@ai-sdk/groq 0.0.0-013d7476-20250808163325 → 0.0.0-fd764a60-20260114143805

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