@ai-sdk/groq 0.0.0-013d7476-20250808163325 → 0.0.0-4115c213-20260122152721

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -20,6 +20,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var src_exports = {};
22
22
  __export(src_exports, {
23
+ VERSION: () => VERSION,
24
+ browserSearch: () => browserSearch,
23
25
  createGroq: () => createGroq,
24
26
  groq: () => groq
25
27
  });
@@ -27,16 +29,57 @@ module.exports = __toCommonJS(src_exports);
27
29
 
28
30
  // src/groq-provider.ts
29
31
  var import_provider4 = require("@ai-sdk/provider");
30
- var import_provider_utils4 = require("@ai-sdk/provider-utils");
32
+ var import_provider_utils6 = require("@ai-sdk/provider-utils");
31
33
 
32
34
  // src/groq-chat-language-model.ts
33
35
  var import_provider3 = require("@ai-sdk/provider");
34
- var import_provider_utils2 = require("@ai-sdk/provider-utils");
36
+ var import_provider_utils3 = require("@ai-sdk/provider-utils");
35
37
  var import_v43 = require("zod/v4");
36
38
 
39
+ // src/convert-groq-usage.ts
40
+ function convertGroqUsage(usage) {
41
+ var _a, _b, _c, _d;
42
+ if (usage == null) {
43
+ return {
44
+ inputTokens: {
45
+ total: void 0,
46
+ noCache: void 0,
47
+ cacheRead: void 0,
48
+ cacheWrite: void 0
49
+ },
50
+ outputTokens: {
51
+ total: void 0,
52
+ text: void 0,
53
+ reasoning: void 0
54
+ },
55
+ raw: void 0
56
+ };
57
+ }
58
+ const promptTokens = (_a = usage.prompt_tokens) != null ? _a : 0;
59
+ const completionTokens = (_b = usage.completion_tokens) != null ? _b : 0;
60
+ const reasoningTokens = (_d = (_c = usage.completion_tokens_details) == null ? void 0 : _c.reasoning_tokens) != null ? _d : void 0;
61
+ const textTokens = reasoningTokens != null ? completionTokens - reasoningTokens : completionTokens;
62
+ return {
63
+ inputTokens: {
64
+ total: promptTokens,
65
+ noCache: promptTokens,
66
+ cacheRead: void 0,
67
+ cacheWrite: void 0
68
+ },
69
+ outputTokens: {
70
+ total: completionTokens,
71
+ text: textTokens,
72
+ reasoning: reasoningTokens
73
+ },
74
+ raw: usage
75
+ };
76
+ }
77
+
37
78
  // src/convert-to-groq-chat-messages.ts
38
79
  var import_provider = require("@ai-sdk/provider");
80
+ var import_provider_utils = require("@ai-sdk/provider-utils");
39
81
  function convertToGroqChatMessages(prompt) {
82
+ var _a;
40
83
  const messages = [];
41
84
  for (const { role, content } of prompt) {
42
85
  switch (role) {
@@ -66,7 +109,7 @@ function convertToGroqChatMessages(prompt) {
66
109
  return {
67
110
  type: "image_url",
68
111
  image_url: {
69
- url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${part.data}`
112
+ url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${(0, import_provider_utils.convertToBase64)(part.data)}`
70
113
  }
71
114
  };
72
115
  }
@@ -77,9 +120,16 @@ function convertToGroqChatMessages(prompt) {
77
120
  }
78
121
  case "assistant": {
79
122
  let text = "";
123
+ let reasoning = "";
80
124
  const toolCalls = [];
81
125
  for (const part of content) {
82
126
  switch (part.type) {
127
+ // groq supports reasoning for tool-calls in multi-turn conversations
128
+ // https://github.com/vercel/ai/issues/7860
129
+ case "reasoning": {
130
+ reasoning += part.text;
131
+ break;
132
+ }
83
133
  case "text": {
84
134
  text += part.text;
85
135
  break;
@@ -100,12 +150,16 @@ function convertToGroqChatMessages(prompt) {
100
150
  messages.push({
101
151
  role: "assistant",
102
152
  content: text,
103
- tool_calls: toolCalls.length > 0 ? toolCalls : void 0
153
+ ...reasoning.length > 0 ? { reasoning } : null,
154
+ ...toolCalls.length > 0 ? { tool_calls: toolCalls } : null
104
155
  });
105
156
  break;
106
157
  }
107
158
  case "tool": {
108
159
  for (const toolResponse of content) {
160
+ if (toolResponse.type === "tool-approval-response") {
161
+ continue;
162
+ }
109
163
  const output = toolResponse.output;
110
164
  let contentValue;
111
165
  switch (output.type) {
@@ -113,6 +167,9 @@ function convertToGroqChatMessages(prompt) {
113
167
  case "error-text":
114
168
  contentValue = output.value;
115
169
  break;
170
+ case "execution-denied":
171
+ contentValue = (_a = output.reason) != null ? _a : "Tool execution denied.";
172
+ break;
116
173
  case "content":
117
174
  case "json":
118
175
  case "error-json":
@@ -153,7 +210,11 @@ function getResponseMetadata({
153
210
  var import_v4 = require("zod/v4");
154
211
  var groqProviderOptions = import_v4.z.object({
155
212
  reasoningFormat: import_v4.z.enum(["parsed", "raw", "hidden"]).optional(),
156
- reasoningEffort: import_v4.z.string().optional(),
213
+ /**
214
+ * Specifies the reasoning effort level for model inference.
215
+ * @see https://console.groq.com/docs/reasoning#reasoning-effort
216
+ */
217
+ reasoningEffort: import_v4.z.enum(["none", "default", "low", "medium", "high"]).optional(),
157
218
  /**
158
219
  * Whether to enable parallel function calling during tool use. Default to true.
159
220
  */
@@ -168,40 +229,89 @@ var groqProviderOptions = import_v4.z.object({
168
229
  *
169
230
  * @default true
170
231
  */
171
- structuredOutputs: import_v4.z.boolean().optional()
232
+ structuredOutputs: import_v4.z.boolean().optional(),
233
+ /**
234
+ * Whether to use strict JSON schema validation.
235
+ * When true, the model uses constrained decoding to guarantee schema compliance.
236
+ * Only used when structured outputs are enabled and a schema is provided.
237
+ *
238
+ * @default true
239
+ */
240
+ strictJsonSchema: import_v4.z.boolean().optional(),
241
+ /**
242
+ * Service tier for the request.
243
+ * - 'on_demand': Default tier with consistent performance and fairness
244
+ * - 'flex': Higher throughput tier optimized for workloads that can handle occasional request failures
245
+ * - 'auto': Uses on_demand rate limits, then falls back to flex tier if exceeded
246
+ *
247
+ * @default 'on_demand'
248
+ */
249
+ serviceTier: import_v4.z.enum(["on_demand", "flex", "auto"]).optional()
172
250
  });
173
251
 
174
252
  // src/groq-error.ts
175
253
  var import_v42 = require("zod/v4");
176
- var import_provider_utils = require("@ai-sdk/provider-utils");
254
+ var import_provider_utils2 = require("@ai-sdk/provider-utils");
177
255
  var groqErrorDataSchema = import_v42.z.object({
178
256
  error: import_v42.z.object({
179
257
  message: import_v42.z.string(),
180
258
  type: import_v42.z.string()
181
259
  })
182
260
  });
183
- var groqFailedResponseHandler = (0, import_provider_utils.createJsonErrorResponseHandler)({
261
+ var groqFailedResponseHandler = (0, import_provider_utils2.createJsonErrorResponseHandler)({
184
262
  errorSchema: groqErrorDataSchema,
185
263
  errorToMessage: (data) => data.error.message
186
264
  });
187
265
 
188
266
  // src/groq-prepare-tools.ts
189
267
  var import_provider2 = require("@ai-sdk/provider");
268
+
269
+ // src/groq-browser-search-models.ts
270
+ var BROWSER_SEARCH_SUPPORTED_MODELS = [
271
+ "openai/gpt-oss-20b",
272
+ "openai/gpt-oss-120b"
273
+ ];
274
+ function isBrowserSearchSupportedModel(modelId) {
275
+ return BROWSER_SEARCH_SUPPORTED_MODELS.includes(modelId);
276
+ }
277
+ function getSupportedModelsString() {
278
+ return BROWSER_SEARCH_SUPPORTED_MODELS.join(", ");
279
+ }
280
+
281
+ // src/groq-prepare-tools.ts
190
282
  function prepareTools({
191
283
  tools,
192
- toolChoice
284
+ toolChoice,
285
+ modelId
193
286
  }) {
194
287
  tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
195
288
  const toolWarnings = [];
196
289
  if (tools == null) {
197
290
  return { tools: void 0, toolChoice: void 0, toolWarnings };
198
291
  }
199
- const groqTools = [];
292
+ const groqTools2 = [];
200
293
  for (const tool of tools) {
201
- if (tool.type === "provider-defined") {
202
- toolWarnings.push({ type: "unsupported-tool", tool });
294
+ if (tool.type === "provider") {
295
+ if (tool.id === "groq.browser_search") {
296
+ if (!isBrowserSearchSupportedModel(modelId)) {
297
+ toolWarnings.push({
298
+ type: "unsupported",
299
+ feature: `provider-defined tool ${tool.id}`,
300
+ details: `Browser search is only supported on the following models: ${getSupportedModelsString()}. Current model: ${modelId}`
301
+ });
302
+ } else {
303
+ groqTools2.push({
304
+ type: "browser_search"
305
+ });
306
+ }
307
+ } else {
308
+ toolWarnings.push({
309
+ type: "unsupported",
310
+ feature: `provider-defined tool ${tool.id}`
311
+ });
312
+ }
203
313
  } else {
204
- groqTools.push({
314
+ groqTools2.push({
205
315
  type: "function",
206
316
  function: {
207
317
  name: tool.name,
@@ -212,17 +322,17 @@ function prepareTools({
212
322
  }
213
323
  }
214
324
  if (toolChoice == null) {
215
- return { tools: groqTools, toolChoice: void 0, toolWarnings };
325
+ return { tools: groqTools2, toolChoice: void 0, toolWarnings };
216
326
  }
217
327
  const type = toolChoice.type;
218
328
  switch (type) {
219
329
  case "auto":
220
330
  case "none":
221
331
  case "required":
222
- return { tools: groqTools, toolChoice: type, toolWarnings };
332
+ return { tools: groqTools2, toolChoice: type, toolWarnings };
223
333
  case "tool":
224
334
  return {
225
- tools: groqTools,
335
+ tools: groqTools2,
226
336
  toolChoice: {
227
337
  type: "function",
228
338
  function: {
@@ -253,14 +363,14 @@ function mapGroqFinishReason(finishReason) {
253
363
  case "tool_calls":
254
364
  return "tool-calls";
255
365
  default:
256
- return "unknown";
366
+ return "other";
257
367
  }
258
368
  }
259
369
 
260
370
  // src/groq-chat-language-model.ts
261
371
  var GroqChatLanguageModel = class {
262
372
  constructor(modelId, config) {
263
- this.specificationVersion = "v2";
373
+ this.specificationVersion = "v3";
264
374
  this.supportedUrls = {
265
375
  "image/*": [/^https?:\/\/.*$/]
266
376
  };
@@ -286,32 +396,30 @@ var GroqChatLanguageModel = class {
286
396
  toolChoice,
287
397
  providerOptions
288
398
  }) {
289
- var _a, _b;
399
+ var _a, _b, _c;
290
400
  const warnings = [];
291
- const groqOptions = await (0, import_provider_utils2.parseProviderOptions)({
401
+ const groqOptions = await (0, import_provider_utils3.parseProviderOptions)({
292
402
  provider: "groq",
293
403
  providerOptions,
294
404
  schema: groqProviderOptions
295
405
  });
296
406
  const structuredOutputs = (_a = groqOptions == null ? void 0 : groqOptions.structuredOutputs) != null ? _a : true;
407
+ const strictJsonSchema = (_b = groqOptions == null ? void 0 : groqOptions.strictJsonSchema) != null ? _b : true;
297
408
  if (topK != null) {
298
- warnings.push({
299
- type: "unsupported-setting",
300
- setting: "topK"
301
- });
409
+ warnings.push({ type: "unsupported", feature: "topK" });
302
410
  }
303
411
  if ((responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !structuredOutputs) {
304
412
  warnings.push({
305
- type: "unsupported-setting",
306
- setting: "responseFormat",
413
+ type: "unsupported",
414
+ feature: "responseFormat",
307
415
  details: "JSON response format schema is only supported with structuredOutputs"
308
416
  });
309
417
  }
310
418
  const {
311
- tools: groqTools,
419
+ tools: groqTools2,
312
420
  toolChoice: groqToolChoice,
313
421
  toolWarnings
314
- } = prepareTools({ tools, toolChoice });
422
+ } = prepareTools({ tools, toolChoice, modelId: this.modelId });
315
423
  return {
316
424
  args: {
317
425
  // model id:
@@ -332,24 +440,26 @@ var GroqChatLanguageModel = class {
332
440
  type: "json_schema",
333
441
  json_schema: {
334
442
  schema: responseFormat.schema,
335
- name: (_b = responseFormat.name) != null ? _b : "response",
443
+ strict: strictJsonSchema,
444
+ name: (_c = responseFormat.name) != null ? _c : "response",
336
445
  description: responseFormat.description
337
446
  }
338
447
  } : { type: "json_object" } : void 0,
339
448
  // provider options:
340
449
  reasoning_format: groqOptions == null ? void 0 : groqOptions.reasoningFormat,
341
450
  reasoning_effort: groqOptions == null ? void 0 : groqOptions.reasoningEffort,
451
+ service_tier: groqOptions == null ? void 0 : groqOptions.serviceTier,
342
452
  // messages:
343
453
  messages: convertToGroqChatMessages(prompt),
344
454
  // tools:
345
- tools: groqTools,
455
+ tools: groqTools2,
346
456
  tool_choice: groqToolChoice
347
457
  },
348
458
  warnings: [...warnings, ...toolWarnings]
349
459
  };
350
460
  }
351
461
  async doGenerate(options) {
352
- var _a, _b, _c, _d, _e, _f, _g;
462
+ var _a, _b;
353
463
  const { args, warnings } = await this.getArgs({
354
464
  ...options,
355
465
  stream: false
@@ -359,15 +469,15 @@ var GroqChatLanguageModel = class {
359
469
  responseHeaders,
360
470
  value: response,
361
471
  rawValue: rawResponse
362
- } = await (0, import_provider_utils2.postJsonToApi)({
472
+ } = await (0, import_provider_utils3.postJsonToApi)({
363
473
  url: this.config.url({
364
474
  path: "/chat/completions",
365
475
  modelId: this.modelId
366
476
  }),
367
- headers: (0, import_provider_utils2.combineHeaders)(this.config.headers(), options.headers),
477
+ headers: (0, import_provider_utils3.combineHeaders)(this.config.headers(), options.headers),
368
478
  body: args,
369
479
  failedResponseHandler: groqFailedResponseHandler,
370
- successfulResponseHandler: (0, import_provider_utils2.createJsonResponseHandler)(
480
+ successfulResponseHandler: (0, import_provider_utils3.createJsonResponseHandler)(
371
481
  groqChatResponseSchema
372
482
  ),
373
483
  abortSignal: options.abortSignal,
@@ -390,7 +500,7 @@ var GroqChatLanguageModel = class {
390
500
  for (const toolCall of choice.message.tool_calls) {
391
501
  content.push({
392
502
  type: "tool-call",
393
- toolCallId: (_a = toolCall.id) != null ? _a : (0, import_provider_utils2.generateId)(),
503
+ toolCallId: (_a = toolCall.id) != null ? _a : (0, import_provider_utils3.generateId)(),
394
504
  toolName: toolCall.function.name,
395
505
  input: toolCall.function.arguments
396
506
  });
@@ -398,12 +508,11 @@ var GroqChatLanguageModel = class {
398
508
  }
399
509
  return {
400
510
  content,
401
- finishReason: mapGroqFinishReason(choice.finish_reason),
402
- usage: {
403
- inputTokens: (_c = (_b = response.usage) == null ? void 0 : _b.prompt_tokens) != null ? _c : void 0,
404
- outputTokens: (_e = (_d = response.usage) == null ? void 0 : _d.completion_tokens) != null ? _e : void 0,
405
- totalTokens: (_g = (_f = response.usage) == null ? void 0 : _f.total_tokens) != null ? _g : void 0
511
+ finishReason: {
512
+ unified: mapGroqFinishReason(choice.finish_reason),
513
+ raw: (_b = choice.finish_reason) != null ? _b : void 0
406
514
  },
515
+ usage: convertGroqUsage(response.usage),
407
516
  response: {
408
517
  ...getResponseMetadata(response),
409
518
  headers: responseHeaders,
@@ -416,28 +525,27 @@ var GroqChatLanguageModel = class {
416
525
  async doStream(options) {
417
526
  const { args, warnings } = await this.getArgs({ ...options, stream: true });
418
527
  const body = JSON.stringify({ ...args, stream: true });
419
- const { responseHeaders, value: response } = await (0, import_provider_utils2.postJsonToApi)({
528
+ const { responseHeaders, value: response } = await (0, import_provider_utils3.postJsonToApi)({
420
529
  url: this.config.url({
421
530
  path: "/chat/completions",
422
531
  modelId: this.modelId
423
532
  }),
424
- headers: (0, import_provider_utils2.combineHeaders)(this.config.headers(), options.headers),
533
+ headers: (0, import_provider_utils3.combineHeaders)(this.config.headers(), options.headers),
425
534
  body: {
426
535
  ...args,
427
536
  stream: true
428
537
  },
429
538
  failedResponseHandler: groqFailedResponseHandler,
430
- successfulResponseHandler: (0, import_provider_utils2.createEventSourceResponseHandler)(groqChatChunkSchema),
539
+ successfulResponseHandler: (0, import_provider_utils3.createEventSourceResponseHandler)(groqChatChunkSchema),
431
540
  abortSignal: options.abortSignal,
432
541
  fetch: this.config.fetch
433
542
  });
434
543
  const toolCalls = [];
435
- let finishReason = "unknown";
436
- const usage = {
437
- inputTokens: void 0,
438
- outputTokens: void 0,
439
- totalTokens: void 0
544
+ let finishReason = {
545
+ unified: "other",
546
+ raw: void 0
440
547
  };
548
+ let usage = void 0;
441
549
  let isFirstChunk = true;
442
550
  let isActiveText = false;
443
551
  let isActiveReasoning = false;
@@ -449,18 +557,24 @@ var GroqChatLanguageModel = class {
449
557
  controller.enqueue({ type: "stream-start", warnings });
450
558
  },
451
559
  transform(chunk, controller) {
452
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
560
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
453
561
  if (options.includeRawChunks) {
454
562
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
455
563
  }
456
564
  if (!chunk.success) {
457
- finishReason = "error";
565
+ finishReason = {
566
+ unified: "error",
567
+ raw: void 0
568
+ };
458
569
  controller.enqueue({ type: "error", error: chunk.error });
459
570
  return;
460
571
  }
461
572
  const value = chunk.value;
462
573
  if ("error" in value) {
463
- finishReason = "error";
574
+ finishReason = {
575
+ unified: "error",
576
+ raw: void 0
577
+ };
464
578
  controller.enqueue({ type: "error", error: value.error });
465
579
  return;
466
580
  }
@@ -472,13 +586,14 @@ var GroqChatLanguageModel = class {
472
586
  });
473
587
  }
474
588
  if (((_a = value.x_groq) == null ? void 0 : _a.usage) != null) {
475
- usage.inputTokens = (_b = value.x_groq.usage.prompt_tokens) != null ? _b : void 0;
476
- usage.outputTokens = (_c = value.x_groq.usage.completion_tokens) != null ? _c : void 0;
477
- usage.totalTokens = (_d = value.x_groq.usage.total_tokens) != null ? _d : void 0;
589
+ usage = value.x_groq.usage;
478
590
  }
479
591
  const choice = value.choices[0];
480
592
  if ((choice == null ? void 0 : choice.finish_reason) != null) {
481
- finishReason = mapGroqFinishReason(choice.finish_reason);
593
+ finishReason = {
594
+ unified: mapGroqFinishReason(choice.finish_reason),
595
+ raw: choice.finish_reason
596
+ };
482
597
  }
483
598
  if ((choice == null ? void 0 : choice.delta) == null) {
484
599
  return;
@@ -499,6 +614,13 @@ var GroqChatLanguageModel = class {
499
614
  });
500
615
  }
501
616
  if (delta.content != null && delta.content.length > 0) {
617
+ if (isActiveReasoning) {
618
+ controller.enqueue({
619
+ type: "reasoning-end",
620
+ id: "reasoning-0"
621
+ });
622
+ isActiveReasoning = false;
623
+ }
502
624
  if (!isActiveText) {
503
625
  controller.enqueue({ type: "text-start", id: "txt-0" });
504
626
  isActiveText = true;
@@ -510,6 +632,13 @@ var GroqChatLanguageModel = class {
510
632
  });
511
633
  }
512
634
  if (delta.tool_calls != null) {
635
+ if (isActiveReasoning) {
636
+ controller.enqueue({
637
+ type: "reasoning-end",
638
+ id: "reasoning-0"
639
+ });
640
+ isActiveReasoning = false;
641
+ }
513
642
  for (const toolCallDelta of delta.tool_calls) {
514
643
  const index = toolCallDelta.index;
515
644
  if (toolCalls[index] == null) {
@@ -525,7 +654,7 @@ var GroqChatLanguageModel = class {
525
654
  message: `Expected 'id' to be a string.`
526
655
  });
527
656
  }
528
- if (((_e = toolCallDelta.function) == null ? void 0 : _e.name) == null) {
657
+ if (((_b = toolCallDelta.function) == null ? void 0 : _b.name) == null) {
529
658
  throw new import_provider3.InvalidResponseDataError({
530
659
  data: toolCallDelta,
531
660
  message: `Expected 'function.name' to be a string.`
@@ -541,12 +670,12 @@ var GroqChatLanguageModel = class {
541
670
  type: "function",
542
671
  function: {
543
672
  name: toolCallDelta.function.name,
544
- arguments: (_f = toolCallDelta.function.arguments) != null ? _f : ""
673
+ arguments: (_c = toolCallDelta.function.arguments) != null ? _c : ""
545
674
  },
546
675
  hasFinished: false
547
676
  };
548
677
  const toolCall2 = toolCalls[index];
549
- if (((_g = toolCall2.function) == null ? void 0 : _g.name) != null && ((_h = toolCall2.function) == null ? void 0 : _h.arguments) != null) {
678
+ if (((_d = toolCall2.function) == null ? void 0 : _d.name) != null && ((_e = toolCall2.function) == null ? void 0 : _e.arguments) != null) {
550
679
  if (toolCall2.function.arguments.length > 0) {
551
680
  controller.enqueue({
552
681
  type: "tool-input-delta",
@@ -554,14 +683,14 @@ var GroqChatLanguageModel = class {
554
683
  delta: toolCall2.function.arguments
555
684
  });
556
685
  }
557
- if ((0, import_provider_utils2.isParsableJson)(toolCall2.function.arguments)) {
686
+ if ((0, import_provider_utils3.isParsableJson)(toolCall2.function.arguments)) {
558
687
  controller.enqueue({
559
688
  type: "tool-input-end",
560
689
  id: toolCall2.id
561
690
  });
562
691
  controller.enqueue({
563
692
  type: "tool-call",
564
- toolCallId: (_i = toolCall2.id) != null ? _i : (0, import_provider_utils2.generateId)(),
693
+ toolCallId: (_f = toolCall2.id) != null ? _f : (0, import_provider_utils3.generateId)(),
565
694
  toolName: toolCall2.function.name,
566
695
  input: toolCall2.function.arguments
567
696
  });
@@ -574,22 +703,22 @@ var GroqChatLanguageModel = class {
574
703
  if (toolCall.hasFinished) {
575
704
  continue;
576
705
  }
577
- if (((_j = toolCallDelta.function) == null ? void 0 : _j.arguments) != null) {
578
- toolCall.function.arguments += (_l = (_k = toolCallDelta.function) == null ? void 0 : _k.arguments) != null ? _l : "";
706
+ if (((_g = toolCallDelta.function) == null ? void 0 : _g.arguments) != null) {
707
+ toolCall.function.arguments += (_i = (_h = toolCallDelta.function) == null ? void 0 : _h.arguments) != null ? _i : "";
579
708
  }
580
709
  controller.enqueue({
581
710
  type: "tool-input-delta",
582
711
  id: toolCall.id,
583
- delta: (_m = toolCallDelta.function.arguments) != null ? _m : ""
712
+ delta: (_j = toolCallDelta.function.arguments) != null ? _j : ""
584
713
  });
585
- if (((_n = toolCall.function) == null ? void 0 : _n.name) != null && ((_o = toolCall.function) == null ? void 0 : _o.arguments) != null && (0, import_provider_utils2.isParsableJson)(toolCall.function.arguments)) {
714
+ if (((_k = toolCall.function) == null ? void 0 : _k.name) != null && ((_l = toolCall.function) == null ? void 0 : _l.arguments) != null && (0, import_provider_utils3.isParsableJson)(toolCall.function.arguments)) {
586
715
  controller.enqueue({
587
716
  type: "tool-input-end",
588
717
  id: toolCall.id
589
718
  });
590
719
  controller.enqueue({
591
720
  type: "tool-call",
592
- toolCallId: (_p = toolCall.id) != null ? _p : (0, import_provider_utils2.generateId)(),
721
+ toolCallId: (_m = toolCall.id) != null ? _m : (0, import_provider_utils3.generateId)(),
593
722
  toolName: toolCall.function.name,
594
723
  input: toolCall.function.arguments
595
724
  });
@@ -608,7 +737,7 @@ var GroqChatLanguageModel = class {
608
737
  controller.enqueue({
609
738
  type: "finish",
610
739
  finishReason,
611
- usage,
740
+ usage: convertGroqUsage(usage),
612
741
  ...providerMetadata != null ? { providerMetadata } : {}
613
742
  });
614
743
  }
@@ -646,7 +775,13 @@ var groqChatResponseSchema = import_v43.z.object({
646
775
  usage: import_v43.z.object({
647
776
  prompt_tokens: import_v43.z.number().nullish(),
648
777
  completion_tokens: import_v43.z.number().nullish(),
649
- total_tokens: import_v43.z.number().nullish()
778
+ total_tokens: import_v43.z.number().nullish(),
779
+ prompt_tokens_details: import_v43.z.object({
780
+ cached_tokens: import_v43.z.number().nullish()
781
+ }).nullish(),
782
+ completion_tokens_details: import_v43.z.object({
783
+ reasoning_tokens: import_v43.z.number().nullish()
784
+ }).nullish()
650
785
  }).nullish()
651
786
  });
652
787
  var groqChatChunkSchema = import_v43.z.union([
@@ -679,7 +814,13 @@ var groqChatChunkSchema = import_v43.z.union([
679
814
  usage: import_v43.z.object({
680
815
  prompt_tokens: import_v43.z.number().nullish(),
681
816
  completion_tokens: import_v43.z.number().nullish(),
682
- total_tokens: import_v43.z.number().nullish()
817
+ total_tokens: import_v43.z.number().nullish(),
818
+ prompt_tokens_details: import_v43.z.object({
819
+ cached_tokens: import_v43.z.number().nullish()
820
+ }).nullish(),
821
+ completion_tokens_details: import_v43.z.object({
822
+ reasoning_tokens: import_v43.z.number().nullish()
823
+ }).nullish()
683
824
  }).nullish()
684
825
  }).nullish()
685
826
  }),
@@ -687,7 +828,7 @@ var groqChatChunkSchema = import_v43.z.union([
687
828
  ]);
688
829
 
689
830
  // src/groq-transcription-model.ts
690
- var import_provider_utils3 = require("@ai-sdk/provider-utils");
831
+ var import_provider_utils4 = require("@ai-sdk/provider-utils");
691
832
  var import_v44 = require("zod/v4");
692
833
  var groqProviderOptionsSchema = import_v44.z.object({
693
834
  language: import_v44.z.string().nullish(),
@@ -700,7 +841,7 @@ var GroqTranscriptionModel = class {
700
841
  constructor(modelId, config) {
701
842
  this.modelId = modelId;
702
843
  this.config = config;
703
- this.specificationVersion = "v2";
844
+ this.specificationVersion = "v3";
704
845
  }
705
846
  get provider() {
706
847
  return this.config.provider;
@@ -712,15 +853,20 @@ var GroqTranscriptionModel = class {
712
853
  }) {
713
854
  var _a, _b, _c, _d, _e;
714
855
  const warnings = [];
715
- const groqOptions = await (0, import_provider_utils3.parseProviderOptions)({
856
+ const groqOptions = await (0, import_provider_utils4.parseProviderOptions)({
716
857
  provider: "groq",
717
858
  providerOptions,
718
859
  schema: groqProviderOptionsSchema
719
860
  });
720
861
  const formData = new FormData();
721
- const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([(0, import_provider_utils3.convertBase64ToUint8Array)(audio)]);
862
+ const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([(0, import_provider_utils4.convertBase64ToUint8Array)(audio)]);
722
863
  formData.append("model", this.modelId);
723
- formData.append("file", new File([blob], "audio", { type: mediaType }));
864
+ const fileExtension = (0, import_provider_utils4.mediaTypeToExtension)(mediaType);
865
+ formData.append(
866
+ "file",
867
+ new File([blob], "audio", { type: mediaType }),
868
+ `audio.${fileExtension}`
869
+ );
724
870
  if (groqOptions) {
725
871
  const transcriptionModelOptions = {
726
872
  language: (_a = groqOptions.language) != null ? _a : void 0,
@@ -732,7 +878,13 @@ var GroqTranscriptionModel = class {
732
878
  for (const key in transcriptionModelOptions) {
733
879
  const value = transcriptionModelOptions[key];
734
880
  if (value !== void 0) {
735
- formData.append(key, String(value));
881
+ if (Array.isArray(value)) {
882
+ for (const item of value) {
883
+ formData.append(`${key}[]`, String(item));
884
+ }
885
+ } else {
886
+ formData.append(key, String(value));
887
+ }
736
888
  }
737
889
  }
738
890
  }
@@ -742,22 +894,22 @@ var GroqTranscriptionModel = class {
742
894
  };
743
895
  }
744
896
  async doGenerate(options) {
745
- var _a, _b, _c, _d, _e;
897
+ var _a, _b, _c, _d, _e, _f, _g;
746
898
  const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
747
899
  const { formData, warnings } = await this.getArgs(options);
748
900
  const {
749
901
  value: response,
750
902
  responseHeaders,
751
903
  rawValue: rawResponse
752
- } = await (0, import_provider_utils3.postFormDataToApi)({
904
+ } = await (0, import_provider_utils4.postFormDataToApi)({
753
905
  url: this.config.url({
754
906
  path: "/audio/transcriptions",
755
907
  modelId: this.modelId
756
908
  }),
757
- headers: (0, import_provider_utils3.combineHeaders)(this.config.headers(), options.headers),
909
+ headers: (0, import_provider_utils4.combineHeaders)(this.config.headers(), options.headers),
758
910
  formData,
759
911
  failedResponseHandler: groqFailedResponseHandler,
760
- successfulResponseHandler: (0, import_provider_utils3.createJsonResponseHandler)(
912
+ successfulResponseHandler: (0, import_provider_utils4.createJsonResponseHandler)(
761
913
  groqTranscriptionResponseSchema
762
914
  ),
763
915
  abortSignal: options.abortSignal,
@@ -770,8 +922,8 @@ var GroqTranscriptionModel = class {
770
922
  startSecond: segment.start,
771
923
  endSecond: segment.end
772
924
  }))) != null ? _e : [],
773
- language: response.language,
774
- durationInSeconds: response.duration,
925
+ language: (_f = response.language) != null ? _f : void 0,
926
+ durationInSeconds: (_g = response.duration) != null ? _g : void 0,
775
927
  warnings,
776
928
  response: {
777
929
  timestamp: currentDate,
@@ -783,10 +935,14 @@ var GroqTranscriptionModel = class {
783
935
  }
784
936
  };
785
937
  var groqTranscriptionResponseSchema = import_v44.z.object({
786
- task: import_v44.z.string(),
787
- language: import_v44.z.string(),
788
- duration: import_v44.z.number(),
789
938
  text: import_v44.z.string(),
939
+ x_groq: import_v44.z.object({
940
+ id: import_v44.z.string()
941
+ }),
942
+ // additional properties are returned when `response_format: 'verbose_json'` is
943
+ task: import_v44.z.string().nullish(),
944
+ language: import_v44.z.string().nullish(),
945
+ duration: import_v44.z.number().nullish(),
790
946
  segments: import_v44.z.array(
791
947
  import_v44.z.object({
792
948
  id: import_v44.z.number(),
@@ -800,24 +956,40 @@ var groqTranscriptionResponseSchema = import_v44.z.object({
800
956
  compression_ratio: import_v44.z.number(),
801
957
  no_speech_prob: import_v44.z.number()
802
958
  })
803
- ),
804
- x_groq: import_v44.z.object({
805
- id: import_v44.z.string()
806
- })
959
+ ).nullish()
960
+ });
961
+
962
+ // src/tool/browser-search.ts
963
+ var import_provider_utils5 = require("@ai-sdk/provider-utils");
964
+ var import_v45 = require("zod/v4");
965
+ var browserSearch = (0, import_provider_utils5.createProviderToolFactory)({
966
+ id: "groq.browser_search",
967
+ inputSchema: import_v45.z.object({})
807
968
  });
808
969
 
970
+ // src/groq-tools.ts
971
+ var groqTools = {
972
+ browserSearch
973
+ };
974
+
975
+ // src/version.ts
976
+ var VERSION = true ? "0.0.0-4115c213-20260122152721" : "0.0.0-test";
977
+
809
978
  // src/groq-provider.ts
810
979
  function createGroq(options = {}) {
811
980
  var _a;
812
- const baseURL = (_a = (0, import_provider_utils4.withoutTrailingSlash)(options.baseURL)) != null ? _a : "https://api.groq.com/openai/v1";
813
- const getHeaders = () => ({
814
- Authorization: `Bearer ${(0, import_provider_utils4.loadApiKey)({
815
- apiKey: options.apiKey,
816
- environmentVariableName: "GROQ_API_KEY",
817
- description: "Groq"
818
- })}`,
819
- ...options.headers
820
- });
981
+ const baseURL = (_a = (0, import_provider_utils6.withoutTrailingSlash)(options.baseURL)) != null ? _a : "https://api.groq.com/openai/v1";
982
+ const getHeaders = () => (0, import_provider_utils6.withUserAgentSuffix)(
983
+ {
984
+ Authorization: `Bearer ${(0, import_provider_utils6.loadApiKey)({
985
+ apiKey: options.apiKey,
986
+ environmentVariableName: "GROQ_API_KEY",
987
+ description: "Groq"
988
+ })}`,
989
+ ...options.headers
990
+ },
991
+ `ai-sdk/groq/${VERSION}`
992
+ );
821
993
  const createChatModel = (modelId) => new GroqChatLanguageModel(modelId, {
822
994
  provider: "groq.chat",
823
995
  url: ({ path }) => `${baseURL}${path}`,
@@ -843,20 +1015,26 @@ function createGroq(options = {}) {
843
1015
  const provider = function(modelId) {
844
1016
  return createLanguageModel(modelId);
845
1017
  };
1018
+ provider.specificationVersion = "v3";
846
1019
  provider.languageModel = createLanguageModel;
847
1020
  provider.chat = createChatModel;
848
- provider.textEmbeddingModel = (modelId) => {
849
- throw new import_provider4.NoSuchModelError({ modelId, modelType: "textEmbeddingModel" });
1021
+ provider.embeddingModel = (modelId) => {
1022
+ throw new import_provider4.NoSuchModelError({ modelId, modelType: "embeddingModel" });
850
1023
  };
1024
+ provider.textEmbeddingModel = provider.embeddingModel;
851
1025
  provider.imageModel = (modelId) => {
852
1026
  throw new import_provider4.NoSuchModelError({ modelId, modelType: "imageModel" });
853
1027
  };
854
1028
  provider.transcription = createTranscriptionModel;
1029
+ provider.transcriptionModel = createTranscriptionModel;
1030
+ provider.tools = groqTools;
855
1031
  return provider;
856
1032
  }
857
1033
  var groq = createGroq();
858
1034
  // Annotate the CommonJS export names for ESM import in node:
859
1035
  0 && (module.exports = {
1036
+ VERSION,
1037
+ browserSearch,
860
1038
  createGroq,
861
1039
  groq
862
1040
  });