@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/CHANGELOG.md +800 -206
- package/README.md +92 -2
- package/dist/index.d.mts +50 -9
- package/dist/index.d.ts +50 -9
- package/dist/index.js +276 -98
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +257 -79
- package/dist/index.mjs.map +1 -1
- package/docs/09-groq.mdx +478 -0
- package/package.json +17 -6
- package/src/convert-groq-usage.ts +64 -0
- package/src/convert-to-groq-chat-messages.ts +147 -0
- package/src/get-response-metadata.ts +15 -0
- package/src/groq-api-types.ts +100 -0
- package/src/groq-browser-search-models.ts +26 -0
- package/src/groq-chat-language-model.ts +658 -0
- package/src/groq-chat-options.ts +78 -0
- package/src/groq-config.ts +9 -0
- package/src/groq-error.ts +16 -0
- package/src/groq-prepare-tools.ts +128 -0
- package/src/groq-provider.ts +143 -0
- package/src/groq-tools.ts +5 -0
- package/src/groq-transcription-model.ts +184 -0
- package/src/groq-transcription-options.ts +4 -0
- package/src/index.ts +5 -0
- package/src/map-groq-finish-reason.ts +19 -0
- package/src/tool/browser-search.ts +28 -0
- package/src/transcript-test.mp3 +0 -0
- package/src/version.ts +6 -0
package/docs/09-groq.mdx
ADDED
|
@@ -0,0 +1,478 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Groq
|
|
3
|
+
description: Learn how to use Groq.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Groq Provider
|
|
7
|
+
|
|
8
|
+
The [Groq](https://groq.com/) provider contains language model support for the Groq API.
|
|
9
|
+
|
|
10
|
+
## Setup
|
|
11
|
+
|
|
12
|
+
The Groq provider is available via the `@ai-sdk/groq` module.
|
|
13
|
+
You can install it with
|
|
14
|
+
|
|
15
|
+
<Tabs items={['pnpm', 'npm', 'yarn', 'bun']}>
|
|
16
|
+
<Tab>
|
|
17
|
+
<Snippet text="pnpm add @ai-sdk/groq" dark />
|
|
18
|
+
</Tab>
|
|
19
|
+
<Tab>
|
|
20
|
+
<Snippet text="npm install @ai-sdk/groq" dark />
|
|
21
|
+
</Tab>
|
|
22
|
+
<Tab>
|
|
23
|
+
<Snippet text="yarn add @ai-sdk/groq" dark />
|
|
24
|
+
</Tab>
|
|
25
|
+
|
|
26
|
+
<Tab>
|
|
27
|
+
<Snippet text="bun add @ai-sdk/groq" dark />
|
|
28
|
+
</Tab>
|
|
29
|
+
</Tabs>
|
|
30
|
+
|
|
31
|
+
## Provider Instance
|
|
32
|
+
|
|
33
|
+
You can import the default provider instance `groq` from `@ai-sdk/groq`:
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
import { groq } from '@ai-sdk/groq';
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
If you need a customized setup, you can import `createGroq` from `@ai-sdk/groq`
|
|
40
|
+
and create a provider instance with your settings:
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
import { createGroq } from '@ai-sdk/groq';
|
|
44
|
+
|
|
45
|
+
const groq = createGroq({
|
|
46
|
+
// custom settings
|
|
47
|
+
});
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
You can use the following optional settings to customize the Groq provider instance:
|
|
51
|
+
|
|
52
|
+
- **baseURL** _string_
|
|
53
|
+
|
|
54
|
+
Use a different URL prefix for API calls, e.g. to use proxy servers.
|
|
55
|
+
The default prefix is `https://api.groq.com/openai/v1`.
|
|
56
|
+
|
|
57
|
+
- **apiKey** _string_
|
|
58
|
+
|
|
59
|
+
API key that is being sent using the `Authorization` header.
|
|
60
|
+
It defaults to the `GROQ_API_KEY` environment variable.
|
|
61
|
+
|
|
62
|
+
- **headers** _Record<string,string>_
|
|
63
|
+
|
|
64
|
+
Custom headers to include in the requests.
|
|
65
|
+
|
|
66
|
+
- **fetch** _(input: RequestInfo, init?: RequestInit) => Promise<Response>_
|
|
67
|
+
|
|
68
|
+
Custom [fetch](https://developer.mozilla.org/en-US/docs/Web/API/fetch) implementation.
|
|
69
|
+
Defaults to the global `fetch` function.
|
|
70
|
+
You can use it as a middleware to intercept requests,
|
|
71
|
+
or to provide a custom fetch implementation for e.g. testing.
|
|
72
|
+
|
|
73
|
+
## Language Models
|
|
74
|
+
|
|
75
|
+
You can create [Groq models](https://console.groq.com/docs/models) using a provider instance.
|
|
76
|
+
The first argument is the model id, e.g. `gemma2-9b-it`.
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
const model = groq('gemma2-9b-it');
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Reasoning Models
|
|
83
|
+
|
|
84
|
+
Groq offers several reasoning models such as `qwen-qwq-32b` and `deepseek-r1-distill-llama-70b`.
|
|
85
|
+
You can configure how the reasoning is exposed in the generated text by using the `reasoningFormat` option.
|
|
86
|
+
It supports the options `parsed`, `hidden`, and `raw`.
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
import { groq } from '@ai-sdk/groq';
|
|
90
|
+
import { generateText } from 'ai';
|
|
91
|
+
|
|
92
|
+
const result = await generateText({
|
|
93
|
+
model: groq('qwen/qwen3-32b'),
|
|
94
|
+
providerOptions: {
|
|
95
|
+
groq: {
|
|
96
|
+
reasoningFormat: 'parsed',
|
|
97
|
+
reasoningEffort: 'default',
|
|
98
|
+
parallelToolCalls: true, // Enable parallel function calling (default: true)
|
|
99
|
+
user: 'user-123', // Unique identifier for end-user (optional)
|
|
100
|
+
serviceTier: 'flex', // Use flex tier for higher throughput (optional)
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
prompt: 'How many "r"s are in the word "strawberry"?',
|
|
104
|
+
});
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
The following optional provider options are available for Groq language models:
|
|
108
|
+
|
|
109
|
+
- **reasoningFormat** _'parsed' | 'raw' | 'hidden'_
|
|
110
|
+
|
|
111
|
+
Controls how reasoning is exposed in the generated text. Only supported by reasoning models like `qwen-qwq-32b` and `deepseek-r1-distill-*` models.
|
|
112
|
+
|
|
113
|
+
For a complete list of reasoning models and their capabilities, see [Groq's reasoning models documentation](https://console.groq.com/docs/reasoning).
|
|
114
|
+
|
|
115
|
+
- **reasoningEffort** _'low' | 'meduim' | 'high' | 'none' | 'default'_
|
|
116
|
+
|
|
117
|
+
Controls the level of effort the model will put into reasoning.
|
|
118
|
+
|
|
119
|
+
- `qwen/qwen3-32b`
|
|
120
|
+
- Supported values:
|
|
121
|
+
- `none`: Disable reasoning. The model will not use any reasoning tokens.
|
|
122
|
+
- `default`: Enable reasoning.
|
|
123
|
+
- `gpt-oss20b/gpt-oss120b`
|
|
124
|
+
- Supported values:
|
|
125
|
+
- `low`: Use a low level of reasoning effort.
|
|
126
|
+
- `medium`: Use a medium level of reasoning effort.
|
|
127
|
+
- `high`: Use a high level of reasoning effort.
|
|
128
|
+
|
|
129
|
+
Defaults to `default` for `qwen/qwen3-32b.`
|
|
130
|
+
|
|
131
|
+
- **structuredOutputs** _boolean_
|
|
132
|
+
|
|
133
|
+
Whether to use structured outputs.
|
|
134
|
+
|
|
135
|
+
Defaults to `true`.
|
|
136
|
+
|
|
137
|
+
When enabled, object generation will use the `json_schema` format instead of `json_object` format, providing more reliable structured outputs.
|
|
138
|
+
|
|
139
|
+
- **strictJsonSchema** _boolean_
|
|
140
|
+
|
|
141
|
+
Whether to use strict JSON schema validation. When `true`, the model uses constrained decoding to guarantee schema compliance.
|
|
142
|
+
|
|
143
|
+
Defaults to `true`.
|
|
144
|
+
|
|
145
|
+
Only used when `structuredOutputs` is enabled and a schema is provided. See [Groq's Structured Outputs documentation](https://console.groq.com/docs/structured-outputs) for details on strict mode limitations.
|
|
146
|
+
|
|
147
|
+
- **parallelToolCalls** _boolean_
|
|
148
|
+
|
|
149
|
+
Whether to enable parallel function calling during tool use. Defaults to `true`.
|
|
150
|
+
|
|
151
|
+
- **user** _string_
|
|
152
|
+
|
|
153
|
+
A unique identifier representing your end-user, which can help with monitoring and abuse detection.
|
|
154
|
+
|
|
155
|
+
- **serviceTier** _'on_demand' | 'flex' | 'auto'_
|
|
156
|
+
|
|
157
|
+
Service tier for the request. Defaults to `'on_demand'`.
|
|
158
|
+
|
|
159
|
+
- `'on_demand'`: Default tier with consistent performance and fairness
|
|
160
|
+
- `'flex'`: Higher throughput tier (10x rate limits) optimized for workloads that can handle occasional request failures
|
|
161
|
+
- `'auto'`: Uses on_demand rate limits first, then falls back to flex tier if exceeded
|
|
162
|
+
|
|
163
|
+
For more details about service tiers and their benefits, see [Groq's Flex Processing documentation](https://console.groq.com/docs/flex-processing).
|
|
164
|
+
|
|
165
|
+
<Note>Only Groq reasoning models support the `reasoningFormat` option.</Note>
|
|
166
|
+
|
|
167
|
+
#### Structured Outputs
|
|
168
|
+
|
|
169
|
+
Structured outputs are enabled by default for Groq models.
|
|
170
|
+
You can disable them by setting the `structuredOutputs` option to `false`.
|
|
171
|
+
|
|
172
|
+
```ts
|
|
173
|
+
import { groq } from '@ai-sdk/groq';
|
|
174
|
+
import { generateObject } from 'ai';
|
|
175
|
+
import { z } from 'zod';
|
|
176
|
+
|
|
177
|
+
const result = await generateObject({
|
|
178
|
+
model: groq('moonshotai/kimi-k2-instruct-0905'),
|
|
179
|
+
schema: z.object({
|
|
180
|
+
recipe: z.object({
|
|
181
|
+
name: z.string(),
|
|
182
|
+
ingredients: z.array(z.string()),
|
|
183
|
+
instructions: z.array(z.string()),
|
|
184
|
+
}),
|
|
185
|
+
}),
|
|
186
|
+
prompt: 'Generate a simple pasta recipe.',
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
console.log(JSON.stringify(result.object, null, 2));
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
You can disable structured outputs for models that don't support them:
|
|
193
|
+
|
|
194
|
+
```ts highlight="9"
|
|
195
|
+
import { groq } from '@ai-sdk/groq';
|
|
196
|
+
import { generateObject } from 'ai';
|
|
197
|
+
import { z } from 'zod';
|
|
198
|
+
|
|
199
|
+
const result = await generateObject({
|
|
200
|
+
model: groq('gemma2-9b-it'),
|
|
201
|
+
providerOptions: {
|
|
202
|
+
groq: {
|
|
203
|
+
structuredOutputs: false,
|
|
204
|
+
},
|
|
205
|
+
},
|
|
206
|
+
schema: z.object({
|
|
207
|
+
recipe: z.object({
|
|
208
|
+
name: z.string(),
|
|
209
|
+
ingredients: z.array(z.string()),
|
|
210
|
+
instructions: z.array(z.string()),
|
|
211
|
+
}),
|
|
212
|
+
}),
|
|
213
|
+
prompt: 'Generate a simple pasta recipe in JSON format.',
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
console.log(JSON.stringify(result.object, null, 2));
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
<Note type="warning">
|
|
220
|
+
Structured outputs are only supported by newer Groq models like
|
|
221
|
+
`moonshotai/kimi-k2-instruct-0905`. For unsupported models, you can disable
|
|
222
|
+
structured outputs by setting `structuredOutputs: false`. When disabled, Groq
|
|
223
|
+
uses the `json_object` format which requires the word "JSON" to be included in
|
|
224
|
+
your messages.
|
|
225
|
+
</Note>
|
|
226
|
+
|
|
227
|
+
### Example
|
|
228
|
+
|
|
229
|
+
You can use Groq language models to generate text with the `generateText` function:
|
|
230
|
+
|
|
231
|
+
```ts
|
|
232
|
+
import { groq } from '@ai-sdk/groq';
|
|
233
|
+
import { generateText } from 'ai';
|
|
234
|
+
|
|
235
|
+
const { text } = await generateText({
|
|
236
|
+
model: groq('gemma2-9b-it'),
|
|
237
|
+
prompt: 'Write a vegetarian lasagna recipe for 4 people.',
|
|
238
|
+
});
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
### Image Input
|
|
242
|
+
|
|
243
|
+
Groq's multi-modal models like `meta-llama/llama-4-scout-17b-16e-instruct` support image inputs. You can include images in your messages using either URLs or base64-encoded data:
|
|
244
|
+
|
|
245
|
+
```ts
|
|
246
|
+
import { groq } from '@ai-sdk/groq';
|
|
247
|
+
import { generateText } from 'ai';
|
|
248
|
+
|
|
249
|
+
const { text } = await generateText({
|
|
250
|
+
model: groq('meta-llama/llama-4-scout-17b-16e-instruct'),
|
|
251
|
+
messages: [
|
|
252
|
+
{
|
|
253
|
+
role: 'user',
|
|
254
|
+
content: [
|
|
255
|
+
{ type: 'text', text: 'What do you see in this image?' },
|
|
256
|
+
{
|
|
257
|
+
type: 'image',
|
|
258
|
+
image: 'https://example.com/image.jpg',
|
|
259
|
+
},
|
|
260
|
+
],
|
|
261
|
+
},
|
|
262
|
+
],
|
|
263
|
+
});
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
You can also use base64-encoded images:
|
|
267
|
+
|
|
268
|
+
```ts
|
|
269
|
+
import { groq } from '@ai-sdk/groq';
|
|
270
|
+
import { generateText } from 'ai';
|
|
271
|
+
import { readFileSync } from 'fs';
|
|
272
|
+
|
|
273
|
+
const imageData = readFileSync('path/to/image.jpg', 'base64');
|
|
274
|
+
|
|
275
|
+
const { text } = await generateText({
|
|
276
|
+
model: groq('meta-llama/llama-4-scout-17b-16e-instruct'),
|
|
277
|
+
messages: [
|
|
278
|
+
{
|
|
279
|
+
role: 'user',
|
|
280
|
+
content: [
|
|
281
|
+
{ type: 'text', text: 'Describe this image in detail.' },
|
|
282
|
+
{
|
|
283
|
+
type: 'image',
|
|
284
|
+
image: `data:image/jpeg;base64,${imageData}`,
|
|
285
|
+
},
|
|
286
|
+
],
|
|
287
|
+
},
|
|
288
|
+
],
|
|
289
|
+
});
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
## Model Capabilities
|
|
293
|
+
|
|
294
|
+
| Model | Image Input | Object Generation | Tool Usage | Tool Streaming |
|
|
295
|
+
| ----------------------------------------------- | ------------------- | ------------------- | ------------------- | ------------------- |
|
|
296
|
+
| `gemma2-9b-it` | <Cross size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
|
|
297
|
+
| `llama-3.1-8b-instant` | <Cross size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
|
|
298
|
+
| `llama-3.3-70b-versatile` | <Cross size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
|
|
299
|
+
| `meta-llama/llama-guard-4-12b` | <Check size={18} /> | <Check size={18} /> | <Cross size={18} /> | <Cross size={18} /> |
|
|
300
|
+
| `deepseek-r1-distill-llama-70b` | <Cross size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
|
|
301
|
+
| `meta-llama/llama-4-maverick-17b-128e-instruct` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
|
|
302
|
+
| `meta-llama/llama-4-scout-17b-16e-instruct` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
|
|
303
|
+
| `meta-llama/llama-prompt-guard-2-22m` | <Cross size={18} /> | <Check size={18} /> | <Cross size={18} /> | <Cross size={18} /> |
|
|
304
|
+
| `meta-llama/llama-prompt-guard-2-86m` | <Cross size={18} /> | <Check size={18} /> | <Cross size={18} /> | <Cross size={18} /> |
|
|
305
|
+
| `moonshotai/kimi-k2-instruct-0905` | <Cross size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
|
|
306
|
+
| `qwen/qwen3-32b` | <Cross size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
|
|
307
|
+
| `llama-guard-3-8b` | <Cross size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
|
|
308
|
+
| `llama3-70b-8192` | <Cross size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
|
|
309
|
+
| `llama3-8b-8192` | <Cross size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
|
|
310
|
+
| `mixtral-8x7b-32768` | <Cross size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
|
|
311
|
+
| `qwen-qwq-32b` | <Cross size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
|
|
312
|
+
| `qwen-2.5-32b` | <Cross size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
|
|
313
|
+
| `deepseek-r1-distill-qwen-32b` | <Cross size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
|
|
314
|
+
| `openai/gpt-oss-20b` | <Cross size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
|
|
315
|
+
| `openai/gpt-oss-120b` | <Cross size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
|
|
316
|
+
|
|
317
|
+
<Note>
|
|
318
|
+
The tables above list the most commonly used models. Please see the [Groq
|
|
319
|
+
docs](https://console.groq.com/docs/models) for a complete list of available
|
|
320
|
+
models. You can also pass any available provider model ID as a string if
|
|
321
|
+
needed.
|
|
322
|
+
</Note>
|
|
323
|
+
|
|
324
|
+
## Browser Search Tool
|
|
325
|
+
|
|
326
|
+
Groq provides a browser search tool that offers interactive web browsing capabilities. Unlike traditional web search, browser search navigates websites interactively, providing more detailed and comprehensive results.
|
|
327
|
+
|
|
328
|
+
### Supported Models
|
|
329
|
+
|
|
330
|
+
Browser search is only available for these specific models:
|
|
331
|
+
|
|
332
|
+
- `openai/gpt-oss-20b`
|
|
333
|
+
- `openai/gpt-oss-120b`
|
|
334
|
+
|
|
335
|
+
<Note type="warning">
|
|
336
|
+
Browser search will only work with the supported models listed above. Using it
|
|
337
|
+
with other models will generate a warning and the tool will be ignored.
|
|
338
|
+
</Note>
|
|
339
|
+
|
|
340
|
+
### Basic Usage
|
|
341
|
+
|
|
342
|
+
```ts
|
|
343
|
+
import { groq } from '@ai-sdk/groq';
|
|
344
|
+
import { generateText } from 'ai';
|
|
345
|
+
|
|
346
|
+
const result = await generateText({
|
|
347
|
+
model: groq('openai/gpt-oss-120b'), // Must use supported model
|
|
348
|
+
prompt:
|
|
349
|
+
'What are the latest developments in AI? Please search for recent news.',
|
|
350
|
+
tools: {
|
|
351
|
+
browser_search: groq.tools.browserSearch({}),
|
|
352
|
+
},
|
|
353
|
+
toolChoice: 'required', // Ensure the tool is used
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
console.log(result.text);
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
### Streaming Example
|
|
360
|
+
|
|
361
|
+
```ts
|
|
362
|
+
import { groq } from '@ai-sdk/groq';
|
|
363
|
+
import { streamText } from 'ai';
|
|
364
|
+
|
|
365
|
+
const result = streamText({
|
|
366
|
+
model: groq('openai/gpt-oss-120b'),
|
|
367
|
+
prompt: 'Search for the latest tech news and summarize it.',
|
|
368
|
+
tools: {
|
|
369
|
+
browser_search: groq.tools.browserSearch({}),
|
|
370
|
+
},
|
|
371
|
+
toolChoice: 'required',
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
for await (const delta of result.fullStream) {
|
|
375
|
+
if (delta.type === 'text-delta') {
|
|
376
|
+
process.stdout.write(delta.text);
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
### Key Features
|
|
382
|
+
|
|
383
|
+
- **Interactive Browsing**: Navigates websites like a human user
|
|
384
|
+
- **Comprehensive Results**: More detailed than traditional search snippets
|
|
385
|
+
- **Server-side Execution**: Runs on Groq's infrastructure, no setup required
|
|
386
|
+
- **Powered by Exa**: Uses Exa search engine for optimal results
|
|
387
|
+
- **Currently Free**: Available at no additional charge during beta
|
|
388
|
+
|
|
389
|
+
### Best Practices
|
|
390
|
+
|
|
391
|
+
- Use `toolChoice: 'required'` to ensure the browser search is activated
|
|
392
|
+
- Only supported on `openai/gpt-oss-20b` and `openai/gpt-oss-120b` models
|
|
393
|
+
- The tool works automatically - no configuration parameters needed
|
|
394
|
+
- Server-side execution means no additional API keys or setup required
|
|
395
|
+
|
|
396
|
+
### Model Validation
|
|
397
|
+
|
|
398
|
+
The provider automatically validates model compatibility:
|
|
399
|
+
|
|
400
|
+
```ts
|
|
401
|
+
// ✅ Supported - will work
|
|
402
|
+
const result = await generateText({
|
|
403
|
+
model: groq('openai/gpt-oss-120b'),
|
|
404
|
+
tools: { browser_search: groq.tools.browserSearch({}) },
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
// ❌ Unsupported - will show warning and ignore tool
|
|
408
|
+
const result = await generateText({
|
|
409
|
+
model: groq('gemma2-9b-it'),
|
|
410
|
+
tools: { browser_search: groq.tools.browserSearch({}) },
|
|
411
|
+
});
|
|
412
|
+
// Warning: "Browser search is only supported on models: openai/gpt-oss-20b, openai/gpt-oss-120b"
|
|
413
|
+
```
|
|
414
|
+
|
|
415
|
+
<Note>
|
|
416
|
+
For more details about browser search capabilities and limitations, see the
|
|
417
|
+
[Groq Browser Search
|
|
418
|
+
Documentation](https://console.groq.com/docs/browser-search).
|
|
419
|
+
</Note>
|
|
420
|
+
|
|
421
|
+
## Transcription Models
|
|
422
|
+
|
|
423
|
+
You can create models that call the [Groq transcription API](https://console.groq.com/docs/speech-to-text)
|
|
424
|
+
using the `.transcription()` factory method.
|
|
425
|
+
|
|
426
|
+
The first argument is the model id e.g. `whisper-large-v3`.
|
|
427
|
+
|
|
428
|
+
```ts
|
|
429
|
+
const model = groq.transcription('whisper-large-v3');
|
|
430
|
+
```
|
|
431
|
+
|
|
432
|
+
You can also pass additional provider-specific options using the `providerOptions` argument. For example, supplying the input language in ISO-639-1 (e.g. `en`) format will improve accuracy and latency.
|
|
433
|
+
|
|
434
|
+
```ts highlight="6"
|
|
435
|
+
import { experimental_transcribe as transcribe } from 'ai';
|
|
436
|
+
import { groq } from '@ai-sdk/groq';
|
|
437
|
+
import { readFile } from 'fs/promises';
|
|
438
|
+
|
|
439
|
+
const result = await transcribe({
|
|
440
|
+
model: groq.transcription('whisper-large-v3'),
|
|
441
|
+
audio: await readFile('audio.mp3'),
|
|
442
|
+
providerOptions: { groq: { language: 'en' } },
|
|
443
|
+
});
|
|
444
|
+
```
|
|
445
|
+
|
|
446
|
+
The following provider options are available:
|
|
447
|
+
|
|
448
|
+
- **timestampGranularities** _string[]_
|
|
449
|
+
The granularity of the timestamps in the transcription.
|
|
450
|
+
Defaults to `['segment']`.
|
|
451
|
+
Possible values are `['word']`, `['segment']`, and `['word', 'segment']`.
|
|
452
|
+
Note: There is no additional latency for segment timestamps, but generating word timestamps incurs additional latency.
|
|
453
|
+
**Important:** Requires `responseFormat` to be set to `'verbose_json'`.
|
|
454
|
+
|
|
455
|
+
- **responseFormat** _string_
|
|
456
|
+
The format of the response. Set to `'verbose_json'` to receive timestamps for audio segments and enable `timestampGranularities`.
|
|
457
|
+
Set to `'text'` to return only the transcribed text.
|
|
458
|
+
Optional.
|
|
459
|
+
|
|
460
|
+
- **language** _string_
|
|
461
|
+
The language of the input audio. Supplying the input language in ISO-639-1 format (e.g. 'en') will improve accuracy and latency.
|
|
462
|
+
Optional.
|
|
463
|
+
|
|
464
|
+
- **prompt** _string_
|
|
465
|
+
An optional text to guide the model's style or continue a previous audio segment. The prompt should match the audio language.
|
|
466
|
+
Optional.
|
|
467
|
+
|
|
468
|
+
- **temperature** _number_
|
|
469
|
+
The sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.
|
|
470
|
+
Defaults to 0.
|
|
471
|
+
Optional.
|
|
472
|
+
|
|
473
|
+
### Model Capabilities
|
|
474
|
+
|
|
475
|
+
| Model | Transcription | Duration | Segments | Language |
|
|
476
|
+
| ------------------------ | ------------------- | ------------------- | ------------------- | ------------------- |
|
|
477
|
+
| `whisper-large-v3` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
|
|
478
|
+
| `whisper-large-v3-turbo` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/groq",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-4115c213-20260122152721",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -8,8 +8,18 @@
|
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
9
9
|
"files": [
|
|
10
10
|
"dist/**/*",
|
|
11
|
-
"
|
|
11
|
+
"docs/**/*",
|
|
12
|
+
"src",
|
|
13
|
+
"!src/**/*.test.ts",
|
|
14
|
+
"!src/**/*.test-d.ts",
|
|
15
|
+
"!src/**/__snapshots__",
|
|
16
|
+
"!src/**/__fixtures__",
|
|
17
|
+
"CHANGELOG.md",
|
|
18
|
+
"README.md"
|
|
12
19
|
],
|
|
20
|
+
"directories": {
|
|
21
|
+
"doc": "./docs"
|
|
22
|
+
},
|
|
13
23
|
"exports": {
|
|
14
24
|
"./package.json": "./package.json",
|
|
15
25
|
".": {
|
|
@@ -19,18 +29,19 @@
|
|
|
19
29
|
}
|
|
20
30
|
},
|
|
21
31
|
"dependencies": {
|
|
22
|
-
"@ai-sdk/provider": "
|
|
23
|
-
"@ai-sdk/provider-utils": "
|
|
32
|
+
"@ai-sdk/provider": "0.0.0-4115c213-20260122152721",
|
|
33
|
+
"@ai-sdk/provider-utils": "0.0.0-4115c213-20260122152721"
|
|
24
34
|
},
|
|
25
35
|
"devDependencies": {
|
|
26
36
|
"@types/node": "20.17.24",
|
|
27
37
|
"tsup": "^8",
|
|
28
38
|
"typescript": "5.8.3",
|
|
29
39
|
"zod": "3.25.76",
|
|
40
|
+
"@ai-sdk/test-server": "0.0.0-4115c213-20260122152721",
|
|
30
41
|
"@vercel/ai-tsconfig": "0.0.0"
|
|
31
42
|
},
|
|
32
43
|
"peerDependencies": {
|
|
33
|
-
"zod": "^3.25.76 || ^4"
|
|
44
|
+
"zod": "^3.25.76 || ^4.1.8"
|
|
34
45
|
},
|
|
35
46
|
"engines": {
|
|
36
47
|
"node": ">=18"
|
|
@@ -52,7 +63,7 @@
|
|
|
52
63
|
"scripts": {
|
|
53
64
|
"build": "pnpm clean && tsup --tsconfig tsconfig.build.json",
|
|
54
65
|
"build:watch": "pnpm clean && tsup --watch",
|
|
55
|
-
"clean": "
|
|
66
|
+
"clean": "del-cli dist docs *.tsbuildinfo",
|
|
56
67
|
"lint": "eslint \"./**/*.ts*\"",
|
|
57
68
|
"type-check": "tsc --build",
|
|
58
69
|
"prettier-check": "prettier --check \"./**/*.ts*\"",
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { LanguageModelV3Usage } from '@ai-sdk/provider';
|
|
2
|
+
|
|
3
|
+
export function convertGroqUsage(
|
|
4
|
+
usage:
|
|
5
|
+
| {
|
|
6
|
+
prompt_tokens?: number | null | undefined;
|
|
7
|
+
completion_tokens?: number | null | undefined;
|
|
8
|
+
prompt_tokens_details?:
|
|
9
|
+
| {
|
|
10
|
+
cached_tokens?: number | null | undefined;
|
|
11
|
+
}
|
|
12
|
+
| null
|
|
13
|
+
| undefined;
|
|
14
|
+
completion_tokens_details?:
|
|
15
|
+
| {
|
|
16
|
+
reasoning_tokens?: number | null | undefined;
|
|
17
|
+
}
|
|
18
|
+
| null
|
|
19
|
+
| undefined;
|
|
20
|
+
}
|
|
21
|
+
| undefined
|
|
22
|
+
| null,
|
|
23
|
+
): LanguageModelV3Usage {
|
|
24
|
+
if (usage == null) {
|
|
25
|
+
return {
|
|
26
|
+
inputTokens: {
|
|
27
|
+
total: undefined,
|
|
28
|
+
noCache: undefined,
|
|
29
|
+
cacheRead: undefined,
|
|
30
|
+
cacheWrite: undefined,
|
|
31
|
+
},
|
|
32
|
+
outputTokens: {
|
|
33
|
+
total: undefined,
|
|
34
|
+
text: undefined,
|
|
35
|
+
reasoning: undefined,
|
|
36
|
+
},
|
|
37
|
+
raw: undefined,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const promptTokens = usage.prompt_tokens ?? 0;
|
|
42
|
+
const completionTokens = usage.completion_tokens ?? 0;
|
|
43
|
+
const reasoningTokens =
|
|
44
|
+
usage.completion_tokens_details?.reasoning_tokens ?? undefined;
|
|
45
|
+
const textTokens =
|
|
46
|
+
reasoningTokens != null
|
|
47
|
+
? completionTokens - reasoningTokens
|
|
48
|
+
: completionTokens;
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
inputTokens: {
|
|
52
|
+
total: promptTokens,
|
|
53
|
+
noCache: promptTokens,
|
|
54
|
+
cacheRead: undefined,
|
|
55
|
+
cacheWrite: undefined,
|
|
56
|
+
},
|
|
57
|
+
outputTokens: {
|
|
58
|
+
total: completionTokens,
|
|
59
|
+
text: textTokens,
|
|
60
|
+
reasoning: reasoningTokens,
|
|
61
|
+
},
|
|
62
|
+
raw: usage,
|
|
63
|
+
};
|
|
64
|
+
}
|