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

model-meta.ts

469 lines14.9 KB

1import type { Modality, ModelReasoning } from '@tanstack/ai'
2import type { ModelReasoningCapability } from '@tanstack/ai/adapter-internals'
3import type { MistralTextProviderOptions } from './text/text-provider-options'
4import type {
5 CodestralEmbedProviderOptions,
6 MistralEmbedProviderOptions,
7} from './embedding/embedding-provider-options'
8​
9// Reasoning shapes: the levels a model has for `chat({ reasoning })`, and
10// the provider value to send for each. Each model points at one of them.
11const EFFORT_NONE_HIGH = {
12 levels: { off: 'none', high: 'high' },
13 budget: false,
14} as const
15const EFFORT_OFF_HIGH = {
16 levels: { off: 'off', high: 'high' },
17 budget: false,
18} as const
19​
20/** Provider options for vision-capable Mistral models (pixtral-*). */
21export type MistralVisionProviderOptions = MistralTextProviderOptions
22​
23/** Provider options for reasoning-capable Mistral models (magistral-*). */
24export type MistralReasoningProviderOptions = MistralTextProviderOptions
25​
26/**
27 * Internal metadata structure describing a Mistral model's capabilities
28 * and approximate pricing (USD per million tokens).
29 */
30interface ModelMeta<TProviderOptions = unknown> {
31 name: string
32 context_window?: number
33 max_completion_tokens?: number
34 pricing: {
35 input?: { normal: number; cached?: number }
36 output?: { normal: number }
37 }
38 supports: {
39 input: Array<'text' | 'image' | 'audio' | 'document'>
40 output: Array<'text'>
41 endpoints: Array<'chat' | 'embeddings'>
42​
43 features: Array<
44 | 'streaming'
45 | 'tools'
46 | 'json_object'
47 | 'json_schema'
48 | 'reasoning'
49 | 'vision'
50 | 'code'
51 >
52 }
53 providerOptions?: TProviderOptions
54 /** The model's data for `chat({ reasoning })`. None: it does not reason. */
55 reasoning?: ModelReasoning
57​
58const MISTRAL_LARGE_LATEST = {
59 name: 'mistral-large-latest',
60 context_window: 131_072,
61 max_completion_tokens: 8_192,
62 pricing: {
63 input: { normal: 0.5 },
64 output: { normal: 1.5 },
65 },
66 supports: {
67 input: ['text'],
68 output: ['text'],
69 endpoints: ['chat'],
70 features: ['streaming', 'tools', 'json_object', 'json_schema'],
71 },
72} as const satisfies ModelMeta<MistralTextProviderOptions>
73​
74const MISTRAL_MEDIUM_LATEST = {
75 name: 'mistral-medium-latest',
76 context_window: 131_072,
77 max_completion_tokens: 8_192,
78 pricing: {
79 input: { normal: 0.4 },
80 output: { normal: 2 },
81 },
82 supports: {
83 input: ['text', 'image', 'document'],
84 output: ['text'],
85 endpoints: ['chat'],
86 features: ['streaming', 'tools', 'json_object', 'json_schema', 'vision'],
87 },
88 reasoning: EFFORT_NONE_HIGH,
89} as const satisfies ModelMeta<MistralTextProviderOptions>
90​
91const MISTRAL_SMALL_LATEST = {
92 name: 'mistral-small-latest',
93 context_window: 131_072,
94 max_completion_tokens: 8_192,
95 pricing: {
96 input: { normal: 0.1 },
97 output: { normal: 0.3 },
98 },
99 supports: {
100 input: ['text', 'image', 'document'],
101 output: ['text'],
102 endpoints: ['chat'],
103 features: ['streaming', 'tools', 'json_object', 'json_schema', 'vision'],
104 },
105 reasoning: EFFORT_NONE_HIGH,
106} as const satisfies ModelMeta<MistralTextProviderOptions>
107​
108const MINISTRAL_8B_LATEST = {
109 name: 'ministral-8b-latest',
110 context_window: 131_072,
111 max_completion_tokens: 8_192,
112 pricing: {
113 input: { normal: 0.1 },
114 output: { normal: 0.1 },
115 },
116 supports: {
117 input: ['text'],
118 output: ['text'],
119 endpoints: ['chat'],
120 features: ['streaming', 'tools', 'json_object', 'json_schema'],
121 },
122} as const satisfies ModelMeta<MistralTextProviderOptions>
123​
124const MINISTRAL_3B_LATEST = {
125 name: 'ministral-3b-latest',
126 context_window: 131_072,
127 max_completion_tokens: 8_192,
128 pricing: {
129 input: { normal: 0.04 },
130 output: { normal: 0.04 },
131 },
132 supports: {
133 input: ['text'],
134 output: ['text'],
135 endpoints: ['chat'],
136 features: ['streaming', 'tools', 'json_object', 'json_schema'],
137 },
138} as const satisfies ModelMeta<MistralTextProviderOptions>
139​
140const CODESTRAL_LATEST = {
141 name: 'codestral-latest',
142 context_window: 256_000,
143 max_completion_tokens: 8_192,
144 pricing: {
145 input: { normal: 0.3 },
146 output: { normal: 0.9 },
147 },
148 supports: {
149 input: ['text'],
150 output: ['text'],
151 endpoints: ['chat'],
152 features: ['streaming', 'tools', 'json_object', 'json_schema', 'code'],
153 },
154} as const satisfies ModelMeta<MistralTextProviderOptions>
155​
156const PIXTRAL_LARGE_LATEST = {
157 name: 'pixtral-large-latest',
158 context_window: 131_072,
159 max_completion_tokens: 8_192,
160 pricing: {
161 input: { normal: 2 },
162 output: { normal: 6 },
163 },
164 supports: {
165 input: ['text', 'image', 'document'],
166 output: ['text'],
167 endpoints: ['chat'],
168 features: ['streaming', 'tools', 'json_object', 'json_schema', 'vision'],
169 },
170} as const satisfies ModelMeta<MistralTextProviderOptions>
171​
172const PIXTRAL_12B_2409 = {
173 name: 'pixtral-12b-2409',
174 context_window: 131_072,
175 max_completion_tokens: 8_192,
176 pricing: {
177 input: { normal: 0.15 },
178 output: { normal: 0.15 },
179 },
180 supports: {
181 input: ['text', 'image', 'document'],
182 output: ['text'],
183 endpoints: ['chat'],
184 features: ['streaming', 'tools', 'json_object', 'vision'],
185 },
186} as const satisfies ModelMeta<MistralTextProviderOptions>
187​
188const MAGISTRAL_MEDIUM_LATEST = {
189 name: 'magistral-medium-latest',
190 context_window: 40_000,
191 max_completion_tokens: 40_000,
192 pricing: {
193 input: { normal: 2 },
194 output: { normal: 5 },
195 },
196 supports: {
197 input: ['text'],
198 output: ['text'],
199 endpoints: ['chat'],
200 features: ['streaming', 'tools', 'reasoning', 'json_object', 'json_schema'],
201 },
202 reasoning: EFFORT_OFF_HIGH,
203} as const satisfies ModelMeta<MistralTextProviderOptions>
204​
205const MAGISTRAL_SMALL_LATEST = {
206 name: 'magistral-small-latest',
207 context_window: 40_000,
208 max_completion_tokens: 40_000,
209 pricing: {
210 input: { normal: 0.5 },
211 output: { normal: 1.5 },
212 },
213 supports: {
214 input: ['text'],
215 output: ['text'],
216 endpoints: ['chat'],
217 features: ['streaming', 'tools', 'reasoning', 'json_object', 'json_schema'],
218 },
219 // Not in models.dev. The same as Magistral Medium: prompt_mode only.
220 reasoning: EFFORT_OFF_HIGH,
221} as const satisfies ModelMeta<MistralTextProviderOptions>
222​
223const OPEN_MISTRAL_NEMO = {
224 name: 'open-mistral-nemo',
225 context_window: 131_072,
226 max_completion_tokens: 8_192,
227 pricing: {
228 input: { normal: 0.15 },
229 output: { normal: 0.15 },
230 },
231 supports: {
232 input: ['text'],
233 output: ['text'],
234 endpoints: ['chat'],
235 features: ['streaming', 'tools', 'json_object'],
236 },
237} as const satisfies ModelMeta<MistralTextProviderOptions>
238​
239// Vertex Model Garden IDs. These are not the Mistral API catalog.
240// Source: https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/partner-models/mistral
241const MISTRAL_MEDIUM_3 = {
242 name: 'mistral-medium-3',
243 context_window: 131_072,
244 max_completion_tokens: 8_192,
245 pricing: {
246 input: { normal: 0.4 },
247 output: { normal: 2 },
248 },
249 supports: {
250 input: ['text', 'image', 'document'],
251 output: ['text'],
252 endpoints: ['chat'],
253 features: ['streaming', 'tools', 'json_object', 'json_schema', 'vision'],
254 },
255} as const satisfies ModelMeta<MistralTextProviderOptions>
256​
257const MISTRAL_SMALL_2503 = {
258 name: 'mistral-small-2503',
259 context_window: 131_072,
260 max_completion_tokens: 8_192,
261 pricing: {
262 input: { normal: 0.1 },
263 output: { normal: 0.3 },
264 },
265 supports: {
266 input: ['text', 'image', 'document'],
267 output: ['text'],
268 endpoints: ['chat'],
269 features: ['streaming', 'tools', 'json_object', 'json_schema', 'vision'],
270 },
271} as const satisfies ModelMeta<MistralTextProviderOptions>
272​
273const CODESTRAL_2 = {
274 name: 'codestral-2',
275 context_window: 131_072,
276 max_completion_tokens: 8_192,
277 pricing: {
278 input: { normal: 0.3 },
279 output: { normal: 0.9 },
280 },
281 supports: {
282 input: ['text'],
283 output: ['text'],
284 endpoints: ['chat'],
285 features: ['streaming', 'tools', 'json_object', 'json_schema', 'code'],
286 },
287} as const satisfies ModelMeta<MistralTextProviderOptions>
288​
289/**
290 * All supported Mistral chat model identifiers.
291 */
292export const MISTRAL_CHAT_MODELS = [
293 MISTRAL_LARGE_LATEST.name,
294 MISTRAL_MEDIUM_LATEST.name,
295 MISTRAL_SMALL_LATEST.name,
296 MINISTRAL_8B_LATEST.name,
297 MINISTRAL_3B_LATEST.name,
298 CODESTRAL_LATEST.name,
299 PIXTRAL_LARGE_LATEST.name,
300 PIXTRAL_12B_2409.name,
301 MAGISTRAL_MEDIUM_LATEST.name,
302 MAGISTRAL_SMALL_LATEST.name,
303 OPEN_MISTRAL_NEMO.name,
304] as const
305​
306/**
307 * Union type of all supported Mistral chat model names.
308 */
309export type MistralChatModels = (typeof MISTRAL_CHAT_MODELS)[number]
310​
311/**
312 * Mistral chat models on Vertex AI / Gemini Enterprise Agent Platform.
313 * This list is the Google partner catalog, not the Mistral API catalog.
314 * OCR (`mistral-ocr-2505`) is not a chat model.
315 */
316export const MISTRAL_VERTEX_CHAT_MODELS = [
317 MISTRAL_MEDIUM_3.name,
318 MISTRAL_SMALL_2503.name,
319 CODESTRAL_2.name,
320] as const
321​
322export type MistralVertexChatModel = (typeof MISTRAL_VERTEX_CHAT_MODELS)[number]
323export type MistralTextAdapterModel = MistralChatModels | MistralVertexChatModel
324​
325/**
326 * Type-only map from Mistral chat model name to its supported input modalities.
327 */
328export type MistralModelInputModalitiesByName = {
329 [MISTRAL_LARGE_LATEST.name]: typeof MISTRAL_LARGE_LATEST.supports.input
330 [MISTRAL_MEDIUM_LATEST.name]: typeof MISTRAL_MEDIUM_LATEST.supports.input
331 [MISTRAL_SMALL_LATEST.name]: typeof MISTRAL_SMALL_LATEST.supports.input
332 [MINISTRAL_8B_LATEST.name]: typeof MINISTRAL_8B_LATEST.supports.input
333 [MINISTRAL_3B_LATEST.name]: typeof MINISTRAL_3B_LATEST.supports.input
334 [CODESTRAL_LATEST.name]: typeof CODESTRAL_LATEST.supports.input
335 [PIXTRAL_LARGE_LATEST.name]: typeof PIXTRAL_LARGE_LATEST.supports.input
336 [PIXTRAL_12B_2409.name]: typeof PIXTRAL_12B_2409.supports.input
337 [MAGISTRAL_MEDIUM_LATEST.name]: typeof MAGISTRAL_MEDIUM_LATEST.supports.input
338 [MAGISTRAL_SMALL_LATEST.name]: typeof MAGISTRAL_SMALL_LATEST.supports.input
339 [OPEN_MISTRAL_NEMO.name]: typeof OPEN_MISTRAL_NEMO.supports.input
340 [MISTRAL_MEDIUM_3.name]: typeof MISTRAL_MEDIUM_3.supports.input
341 [MISTRAL_SMALL_2503.name]: typeof MISTRAL_SMALL_2503.supports.input
342 [CODESTRAL_2.name]: typeof CODESTRAL_2.supports.input
344​
345/**
346 * Runtime map from chat model name to its supported input modalities, for the
347 * text adapter's `inputModalities`. `satisfies` keeps it equal to
348 * {@link MistralModelInputModalitiesByName}. An unknown name gives `undefined`.
349 */
350export const MISTRAL_MODEL_INPUT_MODALITIES: Readonly<
351 Record<string, ReadonlyArray<Modality>>
352> = {
353 [MISTRAL_LARGE_LATEST.name]: MISTRAL_LARGE_LATEST.supports.input,
354 [MISTRAL_MEDIUM_LATEST.name]: MISTRAL_MEDIUM_LATEST.supports.input,
355 [MISTRAL_SMALL_LATEST.name]: MISTRAL_SMALL_LATEST.supports.input,
356 [MINISTRAL_8B_LATEST.name]: MINISTRAL_8B_LATEST.supports.input,
357 [MINISTRAL_3B_LATEST.name]: MINISTRAL_3B_LATEST.supports.input,
358 [CODESTRAL_LATEST.name]: CODESTRAL_LATEST.supports.input,
359 [PIXTRAL_LARGE_LATEST.name]: PIXTRAL_LARGE_LATEST.supports.input,
360 [PIXTRAL_12B_2409.name]: PIXTRAL_12B_2409.supports.input,
361 [MAGISTRAL_MEDIUM_LATEST.name]: MAGISTRAL_MEDIUM_LATEST.supports.input,
362 [MAGISTRAL_SMALL_LATEST.name]: MAGISTRAL_SMALL_LATEST.supports.input,
363 [OPEN_MISTRAL_NEMO.name]: OPEN_MISTRAL_NEMO.supports.input,
364 [MISTRAL_MEDIUM_3.name]: MISTRAL_MEDIUM_3.supports.input,
365 [MISTRAL_SMALL_2503.name]: MISTRAL_SMALL_2503.supports.input,
366 [CODESTRAL_2.name]: CODESTRAL_2.supports.input,
367} satisfies MistralModelInputModalitiesByName
368​
369/**
370 * Type-only map from Mistral chat model name to its provider options type.
371 */
372export type MistralChatModelProviderOptionsByName = {
373 [MISTRAL_LARGE_LATEST.name]: MistralTextProviderOptions
374 [MISTRAL_MEDIUM_LATEST.name]: MistralVisionProviderOptions
375 [MISTRAL_SMALL_LATEST.name]: MistralVisionProviderOptions
376 [MINISTRAL_8B_LATEST.name]: MistralTextProviderOptions
377 [MINISTRAL_3B_LATEST.name]: MistralTextProviderOptions
378 [CODESTRAL_LATEST.name]: MistralTextProviderOptions
379 [PIXTRAL_LARGE_LATEST.name]: MistralVisionProviderOptions
380 [PIXTRAL_12B_2409.name]: MistralVisionProviderOptions
381 [MAGISTRAL_MEDIUM_LATEST.name]: MistralReasoningProviderOptions
382 [MAGISTRAL_SMALL_LATEST.name]: MistralReasoningProviderOptions
383 [OPEN_MISTRAL_NEMO.name]: MistralTextProviderOptions
384 [MISTRAL_MEDIUM_3.name]: MistralVisionProviderOptions
385 [MISTRAL_SMALL_2503.name]: MistralVisionProviderOptions
386 [CODESTRAL_2.name]: MistralTextProviderOptions
388​
389/**
390 * Embedding models (based on endpoints: "embeddings")
391 */
392export const MISTRAL_EMBEDDING_MODELS = [
393 'mistral-embed',
394 'codestral-embed',
395] as const
396​
397/**
398 * Union type of all supported Mistral embedding model names.
399 */
400export type MistralEmbeddingModel = (typeof MISTRAL_EMBEDDING_MODELS)[number]
401​
402/**
403 * Type-only map from embedding model name to its provider options type.
404 *
405 * `mistral-embed` accepts no provider options (fixed 1024-dim output);
406 * `codestral-embed` additionally supports `outputDtype`.
407 */
408export type MistralEmbeddingModelProviderOptionsByName = {
409 'mistral-embed': MistralEmbedProviderOptions
410 'codestral-embed': CodestralEmbedProviderOptions
412​
413/**
414 * Per-model input modalities for embedding models. Mistral embedding models
415 * are text-only, so image inputs fail at compile time.
416 */
417export type MistralEmbeddingModelInputModalitiesByName = {
418 'mistral-embed': readonly ['text']
419 'codestral-embed': readonly ['text']
421​
422/**
423 * Resolves the provider options type for a specific Mistral model.
424 */
425export type ResolveProviderOptions<TModel extends string> =
426 TModel extends keyof MistralChatModelProviderOptionsByName
427 ? MistralChatModelProviderOptionsByName[TModel]
428 : MistralTextProviderOptions
429​
430/**
431 * Resolve input modalities for a specific model.
432 */
433export type ResolveInputModalities<TModel extends string> =
434 TModel extends keyof MistralModelInputModalitiesByName
435 ? MistralModelInputModalitiesByName[TModel]
436 : readonly ['text']
437​
438// Reasoning
439//
440// Each model's `reasoning` field holds its data for `chat({ reasoning })`: the
441// levels it has, with the provider value for each, and whether it takes a
442// thinking token budget. The data comes from models.dev. The generator that
443// writes it comes with the model catalog later. Until then, the sync scripts
444// keep these fields as they are.
445​
446const MISTRAL_REASONING = {
447 [MISTRAL_MEDIUM_LATEST.name]: MISTRAL_MEDIUM_LATEST.reasoning,
448 [MISTRAL_SMALL_LATEST.name]: MISTRAL_SMALL_LATEST.reasoning,
449 [MAGISTRAL_MEDIUM_LATEST.name]: MAGISTRAL_MEDIUM_LATEST.reasoning,
450 [MAGISTRAL_SMALL_LATEST.name]: MAGISTRAL_SMALL_LATEST.reasoning,
452​
453/**
454 * Each chat model's reasoning levels, and whether it takes a token budget,
455 * for `chat({ reasoning })`. Derived from the `reasoning` field. A model
456 * that is not here does not reason.
457 */
458export type MistralModelReasoningByName = {
459 [K in keyof typeof MISTRAL_REASONING]: ModelReasoningCapability<
460 (typeof MISTRAL_REASONING)[K]
461 >
463​
464/**
465 * Runtime map from chat model name to its reasoning data, for the text adapter.
466 * An unknown name gives `undefined`: the adapter sends no reasoning field.
467 */
468export const MISTRAL_MODEL_REASONING: Readonly<Record<string, ModelReasoning>> =
469 MISTRAL_REASONING