Skip to content
Source
Sign inSign up
TanStack/ai
Open History to see the last commit

model-meta.ts

656 lines17.2 KB

1import type { Modality, ModelReasoning } from '@tanstack/ai'
2import type { ModelReasoningCapability } from '@tanstack/ai/adapter-internals'
3import type { LLMGatewayTextProviderOptions } from './text/text-provider-options'
4​
5// Reasoning shapes: the levels a model has for `chat({ reasoning })`, and
6// the provider value to send for each. Each model points at one of them.
7const EFFORT_LOW_TO_HIGH = {
8 levels: { low: 'low', medium: 'medium', high: 'high' },
9 budget: false,
10} as const
11const EFFORT_LOW_TO_MAX = {
12 levels: {
13 low: 'low',
14 medium: 'medium',
15 high: 'high',
16 xhigh: 'xhigh',
17 max: 'max',
18 },
19 budget: false,
20} as const
21const EFFORT_MINIMAL_TO_HIGH = {
22 levels: { minimal: 'minimal', low: 'low', medium: 'medium', high: 'high' },
23 budget: false,
24} as const
25const EFFORT_NONE_LOW_TO_MAX = {
26 levels: {
27 off: 'none',
28 low: 'low',
29 medium: 'medium',
30 high: 'high',
31 xhigh: 'xhigh',
32 max: 'max',
33 },
34 budget: false,
35} as const
36const EFFORT_NONE_LOW_TO_XHIGH = {
37 levels: {
38 off: 'none',
39 low: 'low',
40 medium: 'medium',
41 high: 'high',
42 xhigh: 'xhigh',
43 },
44 budget: false,
45} as const
46const EFFORT_NONE_MINIMAL_TO_MAX = {
47 levels: {
48 off: 'none',
49 minimal: 'minimal',
50 low: 'low',
51 medium: 'medium',
52 high: 'high',
53 xhigh: 'xhigh',
54 max: 'max',
55 },
56 budget: false,
57} as const
58​
59/**
60 * Internal metadata structure describing an LLM Gateway model's capabilities
61 * and pricing.
62 *
63 * LLM Gateway routes hundreds of models from many providers through one
64 * OpenAI-compatible endpoint. This file curates a set of flagship models
65 * with per-model metadata for type safety; any model listed on
66 * https://llmgateway.io/models works at runtime — pass its id with a type
67 * assertion, or prefer a curated model for full type support. Prices are
68 * USD per million tokens and follow the gateway's provider-passthrough
69 * pricing (they may drift; the models page is the source of truth).
70 *
71 * Model ids accept an optional `provider/` prefix (e.g. `openai/gpt-5.5`)
72 * to pin routing to a specific provider — the unprefixed ids below let the
73 * gateway pick the best available provider.
74 */
75interface ModelMeta<TProviderOptions = unknown> {
76 name: string
77 context_window?: number
78 max_completion_tokens?: number
79 pricing: {
80 input?: { normal: number; cached?: number }
81 output?: { normal: number }
82 }
83 supports: {
84 input: Array<'text' | 'image' | 'audio'>
85 output: Array<'text'>
86 endpoints: Array<'chat'>
87 features: Array<
88 | 'streaming'
89 | 'tools'
90 | 'json_object'
91 | 'json_schema'
92 | 'reasoning'
93 | 'vision'
94 >
95 tools?: ReadonlyArray<never>
96 }
97 /**
98 * Type-level description of which provider options this model supports.
99 */
100 providerOptions?: TProviderOptions
101 /** The model's data for `chat({ reasoning })`. None: it does not reason. */
102 reasoning?: ModelReasoning
104​
105const GPT_5_6_TERRA = {
106 name: 'gpt-5.6-terra',
107 context_window: 1_050_000,
108 max_completion_tokens: 128_000,
109 pricing: {
110 input: {
111 normal: 2.5,
112 cached: 0.25,
113 },
114 output: {
115 normal: 15,
116 },
117 },
118 supports: {
119 input: ['text', 'image'],
120 output: ['text'],
121 endpoints: ['chat'],
122 features: [
123 'streaming',
124 'tools',
125 'json_object',
126 'json_schema',
127 'reasoning',
128 'vision',
129 ],
130 tools: [] as const,
131 },
132 reasoning: EFFORT_NONE_LOW_TO_MAX,
133} as const satisfies ModelMeta<LLMGatewayTextProviderOptions>
134​
135const GPT_5_5 = {
136 name: 'gpt-5.5',
137 context_window: 1_050_000,
138 max_completion_tokens: 128_000,
139 pricing: {
140 input: {
141 normal: 5,
142 cached: 0.5,
143 },
144 output: {
145 normal: 30,
146 },
147 },
148 supports: {
149 input: ['text', 'image'],
150 output: ['text'],
151 endpoints: ['chat'],
152 features: [
153 'streaming',
154 'tools',
155 'json_object',
156 'json_schema',
157 'reasoning',
158 'vision',
159 ],
160 tools: [] as const,
161 },
162 reasoning: EFFORT_NONE_LOW_TO_XHIGH,
163} as const satisfies ModelMeta<LLMGatewayTextProviderOptions>
164​
165const GPT_5_4_MINI = {
166 name: 'gpt-5.4-mini',
167 context_window: 400_000,
168 max_completion_tokens: 128_000,
169 pricing: {
170 input: {
171 normal: 0.75,
172 cached: 0.075,
173 },
174 output: {
175 normal: 4.5,
176 },
177 },
178 supports: {
179 input: ['text', 'image'],
180 output: ['text'],
181 endpoints: ['chat'],
182 features: [
183 'streaming',
184 'tools',
185 'json_object',
186 'json_schema',
187 'reasoning',
188 'vision',
189 ],
190 tools: [] as const,
191 },
192 reasoning: EFFORT_NONE_LOW_TO_XHIGH,
193} as const satisfies ModelMeta<LLMGatewayTextProviderOptions>
194​
195const CLAUDE_OPUS_5 = {
196 name: 'claude-opus-5',
197 context_window: 1_000_000,
198 max_completion_tokens: 128_000,
199 pricing: {
200 input: {
201 normal: 5,
202 cached: 0.5,
203 },
204 output: {
205 normal: 25,
206 },
207 },
208 supports: {
209 input: ['text', 'image'],
210 output: ['text'],
211 endpoints: ['chat'],
212 features: ['streaming', 'tools', 'reasoning', 'vision'],
213 tools: [] as const,
214 },
215 reasoning: EFFORT_LOW_TO_MAX,
216} as const satisfies ModelMeta<LLMGatewayTextProviderOptions>
217​
218const CLAUDE_SONNET_5 = {
219 name: 'claude-sonnet-5',
220 context_window: 1_000_000,
221 max_completion_tokens: 128_000,
222 pricing: {
223 input: {
224 normal: 2,
225 cached: 0.2,
226 },
227 output: {
228 normal: 10,
229 },
230 },
231 supports: {
232 input: ['text', 'image'],
233 output: ['text'],
234 endpoints: ['chat'],
235 features: ['streaming', 'tools', 'reasoning', 'vision'],
236 tools: [] as const,
237 },
238 reasoning: EFFORT_LOW_TO_MAX,
239} as const satisfies ModelMeta<LLMGatewayTextProviderOptions>
240​
241const CLAUDE_HAIKU_4_5 = {
242 name: 'claude-haiku-4-5',
243 context_window: 200_000,
244 max_completion_tokens: 64_000,
245 pricing: {
246 input: {
247 normal: 1,
248 cached: 0.1,
249 },
250 output: {
251 normal: 5,
252 },
253 },
254 supports: {
255 input: ['text', 'image'],
256 output: ['text'],
257 endpoints: ['chat'],
258 features: [
259 'streaming',
260 'tools',
261 'json_object',
262 'json_schema',
263 'reasoning',
264 'vision',
265 ],
266 tools: [] as const,
267 },
268 reasoning: EFFORT_LOW_TO_MAX,
269} as const satisfies ModelMeta<LLMGatewayTextProviderOptions>
270​
271const GEMINI_PRO_LATEST = {
272 name: 'gemini-pro-latest',
273 context_window: 1_048_576,
274 max_completion_tokens: 65_536,
275 pricing: {
276 input: {
277 normal: 2,
278 cached: 0.2,
279 },
280 output: {
281 normal: 12,
282 },
283 },
284 supports: {
285 input: ['text', 'image'],
286 output: ['text'],
287 endpoints: ['chat'],
288 features: [
289 'streaming',
290 'tools',
291 'json_object',
292 'json_schema',
293 'reasoning',
294 'vision',
295 ],
296 tools: [] as const,
297 },
298 reasoning: EFFORT_LOW_TO_HIGH,
299} as const satisfies ModelMeta<LLMGatewayTextProviderOptions>
300​
301const GEMINI_3_6_FLASH = {
302 name: 'gemini-3.6-flash',
303 context_window: 1_048_576,
304 max_completion_tokens: 65_536,
305 pricing: {
306 input: {
307 normal: 1.5,
308 cached: 0.15,
309 },
310 output: {
311 normal: 7.5,
312 },
313 },
314 supports: {
315 input: ['text', 'image'],
316 output: ['text'],
317 endpoints: ['chat'],
318 features: [
319 'streaming',
320 'tools',
321 'json_object',
322 'json_schema',
323 'reasoning',
324 'vision',
325 ],
326 tools: [] as const,
327 },
328 reasoning: EFFORT_MINIMAL_TO_HIGH,
329} as const satisfies ModelMeta<LLMGatewayTextProviderOptions>
330​
331const KIMI_K3 = {
332 name: 'kimi-k3',
333 context_window: 1_048_576,
334 max_completion_tokens: 1_048_576,
335 pricing: {
336 input: {
337 normal: 3,
338 cached: 0.3,
339 },
340 output: {
341 normal: 15,
342 },
343 },
344 supports: {
345 input: ['text', 'image'],
346 output: ['text'],
347 endpoints: ['chat'],
348 features: [
349 'streaming',
350 'tools',
351 'json_object',
352 'json_schema',
353 'reasoning',
354 'vision',
355 ],
356 tools: [] as const,
357 },
358 reasoning: EFFORT_NONE_MINIMAL_TO_MAX,
359} as const satisfies ModelMeta<LLMGatewayTextProviderOptions>
360​
361const GLM_5_2 = {
362 name: 'glm-5.2',
363 context_window: 1_000_000,
364 max_completion_tokens: 128_000,
365 pricing: {
366 input: {
367 normal: 1.4,
368 cached: 0.26,
369 },
370 output: {
371 normal: 4.4,
372 },
373 },
374 supports: {
375 input: ['text'],
376 output: ['text'],
377 endpoints: ['chat'],
378 features: ['streaming', 'tools', 'json_object', 'json_schema', 'reasoning'],
379 tools: [] as const,
380 },
381 reasoning: EFFORT_NONE_MINIMAL_TO_MAX,
382} as const satisfies ModelMeta<LLMGatewayTextProviderOptions>
383​
384const DEEPSEEK_V4_PRO = {
385 name: 'deepseek-v4-pro',
386 context_window: 1_050_000,
387 max_completion_tokens: 393_216,
388 pricing: {
389 input: {
390 normal: 0.435,
391 },
392 output: {
393 normal: 0.87,
394 },
395 },
396 supports: {
397 input: ['text'],
398 output: ['text'],
399 endpoints: ['chat'],
400 features: ['streaming', 'tools', 'json_object', 'json_schema', 'reasoning'],
401 tools: [] as const,
402 },
403 reasoning: EFFORT_NONE_MINIMAL_TO_MAX,
404} as const satisfies ModelMeta<LLMGatewayTextProviderOptions>
405​
406const QWEN_3_7_MAX = {
407 name: 'qwen3.7-max',
408 context_window: 1_000_000,
409 max_completion_tokens: 65_536,
410 pricing: {
411 input: {
412 normal: 2.5,
413 cached: 0.5,
414 },
415 output: {
416 normal: 7.5,
417 },
418 },
419 supports: {
420 input: ['text'],
421 output: ['text'],
422 endpoints: ['chat'],
423 features: ['streaming', 'tools', 'json_object', 'json_schema', 'reasoning'],
424 tools: [] as const,
425 },
426 reasoning: EFFORT_NONE_MINIMAL_TO_MAX,
427} as const satisfies ModelMeta<LLMGatewayTextProviderOptions>
428​
429const MINIMAX_M2_5 = {
430 name: 'minimax-m2.5',
431 context_window: 204_800,
432 max_completion_tokens: 131_100,
433 pricing: {
434 input: {
435 normal: 0.3,
436 cached: 0.03,
437 },
438 output: {
439 normal: 1.2,
440 },
441 },
442 supports: {
443 input: ['text'],
444 output: ['text'],
445 endpoints: ['chat'],
446 features: ['streaming', 'tools', 'reasoning'],
447 tools: [] as const,
448 },
449 reasoning: EFFORT_LOW_TO_MAX,
450} as const satisfies ModelMeta<LLMGatewayTextProviderOptions>
451​
452const GROK_4_5 = {
453 name: 'grok-4-5',
454 context_window: 500_000,
455 pricing: {
456 input: {
457 normal: 2,
458 cached: 0.5,
459 },
460 output: {
461 normal: 6,
462 },
463 },
464 supports: {
465 input: ['text', 'image'],
466 output: ['text'],
467 endpoints: ['chat'],
468 features: [
469 'streaming',
470 'tools',
471 'json_object',
472 'json_schema',
473 'reasoning',
474 'vision',
475 ],
476 tools: [] as const,
477 },
478 reasoning: EFFORT_LOW_TO_HIGH,
479} as const satisfies ModelMeta<LLMGatewayTextProviderOptions>
480​
481/**
482 * Curated LLM Gateway chat model identifiers.
483 *
484 * Any model on https://llmgateway.io/models works at runtime; these curated
485 * entries carry per-model type metadata (input modalities, provider
486 * options).
487 */
488export const LLMGATEWAY_CHAT_MODELS = [
489 GPT_5_6_TERRA.name,
490 GPT_5_5.name,
491 GPT_5_4_MINI.name,
492 CLAUDE_OPUS_5.name,
493 CLAUDE_SONNET_5.name,
494 CLAUDE_HAIKU_4_5.name,
495 GEMINI_PRO_LATEST.name,
496 GEMINI_3_6_FLASH.name,
497 KIMI_K3.name,
498 GLM_5_2.name,
499 DEEPSEEK_V4_PRO.name,
500 QWEN_3_7_MAX.name,
501 MINIMAX_M2_5.name,
502 GROK_4_5.name,
503] as const
504​
505/**
506 * Union type of all curated LLM Gateway chat model names.
507 */
508export type LLMGatewayChatModels = (typeof LLMGATEWAY_CHAT_MODELS)[number]
509​
510/**
511 * Model id accepted by the LLM Gateway adapters: a curated model name (with
512 * autocomplete and per-model type metadata) or any other model id from
513 * https://llmgateway.io/models, optionally prefixed with `provider/` to pin
514 * routing to a specific provider. Uncurated ids fall back to text-only
515 * input and the generic provider options.
516 */
517export type LLMGatewayModelId = LLMGatewayChatModels | (string & {})
518​
519/**
520 * Type-only map from LLM Gateway chat model name to its supported input
521 * modalities.
522 */
523export type LLMGatewayModelInputModalitiesByName = {
524 [GPT_5_6_TERRA.name]: typeof GPT_5_6_TERRA.supports.input
525 [GPT_5_5.name]: typeof GPT_5_5.supports.input
526 [GPT_5_4_MINI.name]: typeof GPT_5_4_MINI.supports.input
527 [CLAUDE_OPUS_5.name]: typeof CLAUDE_OPUS_5.supports.input
528 [CLAUDE_SONNET_5.name]: typeof CLAUDE_SONNET_5.supports.input
529 [CLAUDE_HAIKU_4_5.name]: typeof CLAUDE_HAIKU_4_5.supports.input
530 [GEMINI_PRO_LATEST.name]: typeof GEMINI_PRO_LATEST.supports.input
531 [GEMINI_3_6_FLASH.name]: typeof GEMINI_3_6_FLASH.supports.input
532 [KIMI_K3.name]: typeof KIMI_K3.supports.input
533 [GLM_5_2.name]: typeof GLM_5_2.supports.input
534 [DEEPSEEK_V4_PRO.name]: typeof DEEPSEEK_V4_PRO.supports.input
535 [QWEN_3_7_MAX.name]: typeof QWEN_3_7_MAX.supports.input
536 [MINIMAX_M2_5.name]: typeof MINIMAX_M2_5.supports.input
537 [GROK_4_5.name]: typeof GROK_4_5.supports.input
539​
540/**
541 * Runtime map from chat model name to its supported input modalities, for the
542 * text adapter's `inputModalities`. `satisfies` keeps it equal to
543 * {@link LLMGatewayModelInputModalitiesByName}. An unknown name gives `undefined`.
544 */
545export const LLMGATEWAY_MODEL_INPUT_MODALITIES: Readonly<
546 Record<string, ReadonlyArray<Modality>>
547> = {
548 [GPT_5_6_TERRA.name]: GPT_5_6_TERRA.supports.input,
549 [GPT_5_5.name]: GPT_5_5.supports.input,
550 [GPT_5_4_MINI.name]: GPT_5_4_MINI.supports.input,
551 [CLAUDE_OPUS_5.name]: CLAUDE_OPUS_5.supports.input,
552 [CLAUDE_SONNET_5.name]: CLAUDE_SONNET_5.supports.input,
553 [CLAUDE_HAIKU_4_5.name]: CLAUDE_HAIKU_4_5.supports.input,
554 [GEMINI_PRO_LATEST.name]: GEMINI_PRO_LATEST.supports.input,
555 [GEMINI_3_6_FLASH.name]: GEMINI_3_6_FLASH.supports.input,
556 [KIMI_K3.name]: KIMI_K3.supports.input,
557 [GLM_5_2.name]: GLM_5_2.supports.input,
558 [DEEPSEEK_V4_PRO.name]: DEEPSEEK_V4_PRO.supports.input,
559 [QWEN_3_7_MAX.name]: QWEN_3_7_MAX.supports.input,
560 [MINIMAX_M2_5.name]: MINIMAX_M2_5.supports.input,
561 [GROK_4_5.name]: GROK_4_5.supports.input,
562} satisfies LLMGatewayModelInputModalitiesByName
563​
564/**
565 * Type-only map from LLM Gateway chat model name to its provider options
566 * type.
567 */
568export type LLMGatewayChatModelProviderOptionsByName = {
569 [K in (typeof LLMGATEWAY_CHAT_MODELS)[number]]: LLMGatewayTextProviderOptions
571​
572/**
573 * Type-only map from LLM Gateway chat model name to its supported provider
574 * tools. LLM Gateway exposes no provider-specific tool factories, so every
575 * model gets an empty tuple. This ensures that passing an Anthropic/OpenAI
576 * ProviderTool to an LLM Gateway adapter produces a compile-time type error.
577 */
578export type LLMGatewayChatModelToolCapabilitiesByName = {
579 [GPT_5_6_TERRA.name]: typeof GPT_5_6_TERRA.supports.tools
580 [GPT_5_5.name]: typeof GPT_5_5.supports.tools
581 [GPT_5_4_MINI.name]: typeof GPT_5_4_MINI.supports.tools
582 [CLAUDE_OPUS_5.name]: typeof CLAUDE_OPUS_5.supports.tools
583 [CLAUDE_SONNET_5.name]: typeof CLAUDE_SONNET_5.supports.tools
584 [CLAUDE_HAIKU_4_5.name]: typeof CLAUDE_HAIKU_4_5.supports.tools
585 [GEMINI_PRO_LATEST.name]: typeof GEMINI_PRO_LATEST.supports.tools
586 [GEMINI_3_6_FLASH.name]: typeof GEMINI_3_6_FLASH.supports.tools
587 [KIMI_K3.name]: typeof KIMI_K3.supports.tools
588 [GLM_5_2.name]: typeof GLM_5_2.supports.tools
589 [DEEPSEEK_V4_PRO.name]: typeof DEEPSEEK_V4_PRO.supports.tools
590 [QWEN_3_7_MAX.name]: typeof QWEN_3_7_MAX.supports.tools
591 [MINIMAX_M2_5.name]: typeof MINIMAX_M2_5.supports.tools
592 [GROK_4_5.name]: typeof GROK_4_5.supports.tools
594​
595/**
596 * Resolves the provider options type for a specific LLM Gateway model.
597 * Falls back to the generic options for uncurated model ids.
598 */
599export type ResolveProviderOptions<TModel extends string> =
600 TModel extends keyof LLMGatewayChatModelProviderOptionsByName
601 ? LLMGatewayChatModelProviderOptionsByName[TModel]
602 : LLMGatewayTextProviderOptions
603​
604/**
605 * Resolve input modalities for a specific model.
606 * If the model has explicit modalities in the map, use those; otherwise use
607 * text only.
608 */
609export type ResolveInputModalities<TModel extends string> =
610 TModel extends keyof LLMGatewayModelInputModalitiesByName
611 ? LLMGatewayModelInputModalitiesByName[TModel]
612 : readonly ['text']
613​
614// Reasoning
615//
616// Each model's `reasoning` field holds its data for `chat({ reasoning })`: the
617// levels it has, with the provider value for each, and whether it takes a
618// thinking token budget. The data comes from models.dev. The generator that
619// writes it comes with the model catalog later. Until then, the sync scripts
620// keep these fields as they are.
621​
622const LLMGATEWAY_REASONING = {
623 [GPT_5_6_TERRA.name]: GPT_5_6_TERRA.reasoning,
624 [GPT_5_5.name]: GPT_5_5.reasoning,
625 [GPT_5_4_MINI.name]: GPT_5_4_MINI.reasoning,
626 [CLAUDE_OPUS_5.name]: CLAUDE_OPUS_5.reasoning,
627 [CLAUDE_SONNET_5.name]: CLAUDE_SONNET_5.reasoning,
628 [CLAUDE_HAIKU_4_5.name]: CLAUDE_HAIKU_4_5.reasoning,
629 [GEMINI_PRO_LATEST.name]: GEMINI_PRO_LATEST.reasoning,
630 [GEMINI_3_6_FLASH.name]: GEMINI_3_6_FLASH.reasoning,
631 [KIMI_K3.name]: KIMI_K3.reasoning,
632 [GLM_5_2.name]: GLM_5_2.reasoning,
633 [DEEPSEEK_V4_PRO.name]: DEEPSEEK_V4_PRO.reasoning,
634 [QWEN_3_7_MAX.name]: QWEN_3_7_MAX.reasoning,
635 [MINIMAX_M2_5.name]: MINIMAX_M2_5.reasoning,
636 [GROK_4_5.name]: GROK_4_5.reasoning,
638​
639/**
640 * Each chat model's reasoning levels, and whether it takes a token budget,
641 * for `chat({ reasoning })`. Derived from the `reasoning` field. A model
642 * that is not here does not reason.
643 */
644export type LLMGatewayModelReasoningByName = {
645 [K in keyof typeof LLMGATEWAY_REASONING]: ModelReasoningCapability<
646 (typeof LLMGATEWAY_REASONING)[K]
647 >
649​
650/**
651 * Runtime map from chat model name to its reasoning data, for the text adapter.
652 * An unknown name gives `undefined`: the adapter sends no reasoning field.
653 */
654export const LLMGATEWAY_MODEL_REASONING: Readonly<
655 Record<string, ModelReasoning>
656> = LLMGATEWAY_REASONING