Open History to see the last commit
1import type { GroqTextProviderOptions } from './text/text-provider-options'
2import type { GroqTTSProviderOptions } from './audio/tts-provider-options'
3
4/**
5 * Internal metadata structure describing a Groq model's capabilities and pricing.
6 */
7interface ModelMeta<TProviderOptions = unknown> {
8 name: string
9 context_window?: number
10 max_completion_tokens?: number
11 pricing: {
12 input?: { normal: number; cached?: number }
13 output?: { normal: number }
14 }
15 supports: {
16 input: Array<'text' | 'image' | 'audio'>
17 output: Array<'text' | 'audio'>
18 endpoints: Array<'chat' | 'tts' | 'transcription' | 'batch'>
19
20 features: Array<
21 | 'streaming'
22 | 'tools'
23 | 'json_object'
24 | 'browser_search'
25 | 'code_execution'
26 | 'reasoning'
27 | 'content_moderation'
28 | 'json_schema'
29 | 'vision'
30 >
31 tools?: ReadonlyArray<never>
32 }
33 /**
34 * Type-level description of which provider options this model supports.
35 */
36 providerOptions?: TProviderOptions
37}
38
39const LLAMA_3_3_70B_VERSATILE = {
40 name: 'llama-3.3-70b-versatile',
41 context_window: 131_072,
42 max_completion_tokens: 32_768,
43 pricing: {
44 input: {
45 normal: 0.59,
46 },
47 output: {
48 normal: 0.79,
49 },
50 },
51 supports: {
52 input: ['text'],
53 output: ['text'],
54 endpoints: ['chat'],
55 features: ['streaming', 'tools', 'json_object'],
56 tools: [] as const,
57 },
58} as const satisfies ModelMeta<GroqTextProviderOptions>
59
60const LLAMA_4_MAVERICK_17B_128E_INSTRUCT = {
61 name: 'meta-llama/llama-4-maverick-17b-128e-instruct',
62 context_window: 131_072,
63 max_completion_tokens: 8_192,
64 pricing: {
65 input: {
66 normal: 0.2,
67 },
68 output: {
69 normal: 0.6,
70 },
71 },
72 supports: {
73 input: ['text', 'image'],
74 output: ['text'],
75 endpoints: ['chat'],
76 features: ['streaming', 'tools', 'json_object', 'json_schema', 'vision'],
77 tools: [] as const,
78 },
79} as const satisfies ModelMeta<GroqTextProviderOptions>
80
81const LLAMA_4_SCOUT_17B_16E_INSTRUCT = {
82 name: 'meta-llama/llama-4-scout-17b-16e-instruct',
83 context_window: 131_072,
84 max_completion_tokens: 8_192,
85 pricing: {
86 input: {
87 normal: 0.05,
88 },
89 output: {
90 normal: 0.08,
91 },
92 },
93 supports: {
94 input: ['text', 'image'],
95 output: ['text'],
96 endpoints: ['chat'],
97 features: ['streaming', 'tools', 'json_object'],
98 tools: [] as const,
99 },
100} as const satisfies ModelMeta<GroqTextProviderOptions>
101
102const LLAMA_GUARD_4_12B = {
103 name: 'meta-llama/llama-guard-4-12b',
104 context_window: 131_072,
105 max_completion_tokens: 1024,
106 pricing: {
107 input: {
108 normal: 0.2,
109 },
110 output: {
111 normal: 0.2,
112 },
113 },
114 supports: {
115 input: ['text', 'image'],
116 output: ['text'],
117 endpoints: ['chat'],
118 features: ['streaming', 'json_object', 'content_moderation', 'vision'],
119 tools: [] as const,
120 },
121} as const satisfies ModelMeta<GroqTextProviderOptions>
122
123const LLAMA_PROMPT_GUARD_2_86M = {
124 name: 'meta-llama/llama-prompt-guard-2-86m',
125 context_window: 512,
126 max_completion_tokens: 512,
127 pricing: {
128 input: {
129 normal: 0.04,
130 },
131 output: {
132 normal: 0.04,
133 },
134 },
135 supports: {
136 input: ['text'],
137 output: ['text'],
138 endpoints: ['chat'],
139 features: ['streaming', 'content_moderation', 'json_object'],
140 tools: [] as const,
141 },
142} as const satisfies ModelMeta<GroqTextProviderOptions>
143
144const LLAMA_3_1_8B_INSTANT = {
145 name: 'llama-3.1-8b-instant',
146 context_window: 131_072,
147 max_completion_tokens: 131_072,
148 pricing: {
149 input: {
150 normal: 0.05,
151 },
152 output: {
153 normal: 0.08,
154 },
155 },
156 supports: {
157 input: ['text'],
158 output: ['text'],
159 endpoints: ['chat'],
160 features: ['streaming', 'json_object', 'tools'],
161 tools: [] as const,
162 },
163} as const satisfies ModelMeta<GroqTextProviderOptions>
164
165const LLAMA_PROMPT_GUARD_2_22M = {
166 name: 'meta-llama/llama-prompt-guard-2-22m',
167 context_window: 512,
168 max_completion_tokens: 512,
169 pricing: {
170 input: {
171 normal: 0.03,
172 },
173 output: {
174 normal: 0.03,
175 },
176 },
177 supports: {
178 input: ['text'],
179 output: ['text'],
180 endpoints: ['chat'],
181 features: ['streaming', 'content_moderation'],
182 tools: [] as const,
183 },
184} as const satisfies ModelMeta<GroqTextProviderOptions>
185
186const GPT_OSS_120B = {
187 name: 'openai/gpt-oss-120b',
188 context_window: 131_072,
189 max_completion_tokens: 65_536,
190 pricing: {
191 input: {
192 normal: 0.15,
193 cached: 0.075,
194 },
195 output: {
196 normal: 0.6,
197 },
198 },
199 supports: {
200 input: ['text'],
201 output: ['text'],
202 endpoints: ['chat'],
203 features: [
204 'streaming',
205 'json_object',
206 'json_schema',
207 'tools',
208 'browser_search',
209 'code_execution',
210 'reasoning',
211 ],
212 tools: [] as const,
213 },
214} as const satisfies ModelMeta<GroqTextProviderOptions>
215
216const GPT_OSS_SAFEGUARD_20B = {
217 name: 'openai/gpt-oss-safeguard-20b',
218 context_window: 131_072,
219 max_completion_tokens: 65_536,
220 pricing: {
221 input: {
222 normal: 0.075,
223 cached: 0.037,
224 },
225 output: {
226 normal: 0.3,
227 },
228 },
229 supports: {
230 input: ['text'],
231 output: ['text'],
232 endpoints: ['chat'],
233 features: [
234 'streaming',
235 'tools',
236 'browser_search',
237 'code_execution',
238 'json_object',
239 'json_schema',
240 'reasoning',
241 'content_moderation',
242 ],
243 tools: [] as const,
244 },
245} as const satisfies ModelMeta<GroqTextProviderOptions>
246
247const GPT_OSS_20B = {
248 name: 'openai/gpt-oss-20b',
249 context_window: 131_072,
250 max_completion_tokens: 65_536,
251 pricing: {
252 input: {
253 normal: 0.075,
254 cached: 0.037,
255 },
256 output: {
257 normal: 0.3,
258 },
259 },
260 supports: {
261 input: ['text'],
262 output: ['text'],
263 endpoints: ['chat'],
264 features: [
265 'streaming',
266 'browser_search',
267 'code_execution',
268 'json_object',
269 'json_schema',
270 'reasoning',
271 'tools',
272 ],
273 tools: [] as const,
274 },
275} as const satisfies ModelMeta<GroqTextProviderOptions>
276
277const KIMI_K2_INSTRUCT_0905 = {
278 name: 'moonshotai/kimi-k2-instruct-0905',
279 context_window: 262_144,
280 max_completion_tokens: 16_384,
281 pricing: {
282 input: {
283 normal: 1,
284 cached: 0.5,
285 },
286 output: {
287 normal: 3,
288 },
289 },
290 supports: {
291 input: ['text'],
292 output: ['text'],
293 endpoints: ['chat'],
294 features: ['streaming', 'tools', 'json_object', 'json_schema'],
295 tools: [] as const,
296 },
297} as const satisfies ModelMeta<GroqTextProviderOptions>
298
299const QWEN3_32B = {
300 name: 'qwen/qwen3-32b',
301 context_window: 131_072,
302 max_completion_tokens: 40_960,
303 pricing: {
304 input: {
305 normal: 0.29,
306 },
307 output: {
308 normal: 0.59,
309 },
310 },
311 supports: {
312 input: ['text'],
313 output: ['text'],
314 endpoints: ['chat'],
315 features: ['streaming', 'json_object', 'tools', 'reasoning'],
316 tools: [] as const,
317 },
318} as const satisfies ModelMeta<GroqTextProviderOptions>
319
320/**
321 * All supported Groq chat model identifiers.
322 */
323export const GROQ_CHAT_MODELS = [
324 LLAMA_3_1_8B_INSTANT.name,
325 LLAMA_3_3_70B_VERSATILE.name,
326 LLAMA_4_MAVERICK_17B_128E_INSTRUCT.name,
327 LLAMA_4_SCOUT_17B_16E_INSTRUCT.name,
328 LLAMA_GUARD_4_12B.name,
329 LLAMA_PROMPT_GUARD_2_86M.name,
330 LLAMA_PROMPT_GUARD_2_22M.name,
331 GPT_OSS_20B.name,
332 GPT_OSS_120B.name,
333 GPT_OSS_SAFEGUARD_20B.name,
334 KIMI_K2_INSTRUCT_0905.name,
335 QWEN3_32B.name,
336] as const
337
338/**
339 * Union type of all supported Groq chat model names.
340 */
341export type GroqChatModels = (typeof GROQ_CHAT_MODELS)[number]
342
343/**
344 * Type-only map from Groq chat model name to its supported input modalities.
345 */
346export type GroqModelInputModalitiesByName = {
347 [LLAMA_3_1_8B_INSTANT.name]: typeof LLAMA_3_1_8B_INSTANT.supports.input
348 [LLAMA_3_3_70B_VERSATILE.name]: typeof LLAMA_3_3_70B_VERSATILE.supports.input
349 [LLAMA_4_MAVERICK_17B_128E_INSTRUCT.name]: typeof LLAMA_4_MAVERICK_17B_128E_INSTRUCT.supports.input
350 [LLAMA_4_SCOUT_17B_16E_INSTRUCT.name]: typeof LLAMA_4_SCOUT_17B_16E_INSTRUCT.supports.input
351 [LLAMA_GUARD_4_12B.name]: typeof LLAMA_GUARD_4_12B.supports.input
352 [LLAMA_PROMPT_GUARD_2_86M.name]: typeof LLAMA_PROMPT_GUARD_2_86M.supports.input
353 [LLAMA_PROMPT_GUARD_2_22M.name]: typeof LLAMA_PROMPT_GUARD_2_22M.supports.input
354 [GPT_OSS_20B.name]: typeof GPT_OSS_20B.supports.input
355 [GPT_OSS_120B.name]: typeof GPT_OSS_120B.supports.input
356 [GPT_OSS_SAFEGUARD_20B.name]: typeof GPT_OSS_SAFEGUARD_20B.supports.input
357 [KIMI_K2_INSTRUCT_0905.name]: typeof KIMI_K2_INSTRUCT_0905.supports.input
358 [QWEN3_32B.name]: typeof QWEN3_32B.supports.input
359}
360
361/**
362 * Type-only map from Groq chat model name to its provider options type.
363 */
364export type GroqChatModelProviderOptionsByName = {
365 [K in (typeof GROQ_CHAT_MODELS)[number]]: GroqTextProviderOptions
366}
367
368/**
369 * Type-only map from Groq chat model name to its supported provider tools.
370 * Groq exposes no provider-specific tool factories, so every model gets an
371 * empty tuple. This ensures that passing an Anthropic/OpenAI ProviderTool to
372 * a Groq adapter produces a compile-time type error.
373 */
374export type GroqChatModelToolCapabilitiesByName = {
375 [LLAMA_3_1_8B_INSTANT.name]: typeof LLAMA_3_1_8B_INSTANT.supports.tools
376 [LLAMA_3_3_70B_VERSATILE.name]: typeof LLAMA_3_3_70B_VERSATILE.supports.tools
377 [LLAMA_4_MAVERICK_17B_128E_INSTRUCT.name]: typeof LLAMA_4_MAVERICK_17B_128E_INSTRUCT.supports.tools
378 [LLAMA_4_SCOUT_17B_16E_INSTRUCT.name]: typeof LLAMA_4_SCOUT_17B_16E_INSTRUCT.supports.tools
379 [LLAMA_GUARD_4_12B.name]: typeof LLAMA_GUARD_4_12B.supports.tools
380 [LLAMA_PROMPT_GUARD_2_86M.name]: typeof LLAMA_PROMPT_GUARD_2_86M.supports.tools
381 [LLAMA_PROMPT_GUARD_2_22M.name]: typeof LLAMA_PROMPT_GUARD_2_22M.supports.tools
382 [GPT_OSS_20B.name]: typeof GPT_OSS_20B.supports.tools
383 [GPT_OSS_120B.name]: typeof GPT_OSS_120B.supports.tools
384 [GPT_OSS_SAFEGUARD_20B.name]: typeof GPT_OSS_SAFEGUARD_20B.supports.tools
385 [KIMI_K2_INSTRUCT_0905.name]: typeof KIMI_K2_INSTRUCT_0905.supports.tools
386 [QWEN3_32B.name]: typeof QWEN3_32B.supports.tools
387}
388
389/**
390 * Type-only map from Groq TTS model name to its provider options type.
391 */
392export type GroqTTSModelProviderOptionsByName = {
393 [K in GroqTTSModel]: GroqTTSProviderOptions
394}
395
396/**
397 * Resolves the provider options type for a specific Groq model.
398 * Checks TTS models first, then chat models, then falls back to generic options.
399 */
400export type ResolveProviderOptions<TModel extends string> =
401 TModel extends GroqTTSModel
402 ? GroqTTSProviderOptions
403 : TModel extends keyof GroqChatModelProviderOptionsByName
404 ? GroqChatModelProviderOptionsByName[TModel]
405 : GroqTextProviderOptions
406
407/**
408 * Resolve input modalities for a specific model.
409 * If the model has explicit modalities in the map, use those; otherwise use text only.
410 */
411export type ResolveInputModalities<TModel extends string> =
412 TModel extends keyof GroqModelInputModalitiesByName
413 ? GroqModelInputModalitiesByName[TModel]
414 : readonly ['text']
415
416/**
417 * All supported Groq transcription model identifiers.
418 */
419export const GROQ_TRANSCRIPTION_MODELS = [
420 'whisper-large-v3-turbo',
421 'whisper-large-v3',
422] as const
423
424/**
425 * Union type of all supported Groq transcription model names.
426 */
427export type GroqTranscriptionModel = (typeof GROQ_TRANSCRIPTION_MODELS)[number]
428
429// ============================================================================
430// TTS Models
431// ============================================================================
432
433const ORPHEUS_V1_ENGLISH = {
434 name: 'canopylabs/orpheus-v1-english',
435 pricing: {
436 input: {
437 normal: 22,
438 },
439 },
440 supports: {
441 input: ['text'],
442 output: ['audio'],
443 endpoints: ['tts'],
444 features: [],
445 },
446} as const satisfies ModelMeta<GroqTTSProviderOptions>
447
448const ORPHEUS_ARABIC_SAUDI = {
449 name: 'canopylabs/orpheus-arabic-saudi',
450 pricing: {
451 input: {
452 normal: 40,
453 },
454 },
455 supports: {
456 input: ['text'],
457 output: ['audio'],
458 endpoints: ['tts'],
459 features: [],
460 },
461} as const satisfies ModelMeta<GroqTTSProviderOptions>
462
463/**
464 * All supported Groq TTS model identifiers.
465 */
466export const GROQ_TTS_MODELS = [
467 ORPHEUS_V1_ENGLISH.name,
468 ORPHEUS_ARABIC_SAUDI.name,
469] as const
470
471/**
472 * Union type of all supported Groq TTS model names.
473 */
474export type GroqTTSModel = (typeof GROQ_TTS_MODELS)[number]