Open History to see the last commit
1import type { MistralTextProviderOptions } from './text/text-provider-options'
2import type {
3 CodestralEmbedProviderOptions,
4 MistralEmbedProviderOptions,
5} from './embedding/embedding-provider-options'
6
7/** Provider options for vision-capable Mistral models (pixtral-*). */
8export type MistralVisionProviderOptions = MistralTextProviderOptions
9
10/** Provider options for reasoning-capable Mistral models (magistral-*). */
11export type MistralReasoningProviderOptions = MistralTextProviderOptions
12
13/**
14 * Internal metadata structure describing a Mistral model's capabilities
15 * and approximate pricing (USD per million tokens).
16 */
17interface ModelMeta<TProviderOptions = unknown> {
18 name: string
19 context_window?: number
20 max_completion_tokens?: number
21 pricing: {
22 input?: { normal: number; cached?: number }
23 output?: { normal: number }
24 }
25 supports: {
26 input: Array<'text' | 'image' | 'audio' | 'document'>
27 output: Array<'text'>
28 endpoints: Array<'chat' | 'embeddings'>
29
30 features: Array<
31 | 'streaming'
32 | 'tools'
33 | 'json_object'
34 | 'json_schema'
35 | 'reasoning'
36 | 'vision'
37 | 'code'
38 >
39 }
40 providerOptions?: TProviderOptions
41}
42
43const MISTRAL_LARGE_LATEST = {
44 name: 'mistral-large-latest',
45 context_window: 131_072,
46 max_completion_tokens: 8_192,
47 pricing: {
48 input: { normal: 0.5 },
49 output: { normal: 1.5 },
50 },
51 supports: {
52 input: ['text'],
53 output: ['text'],
54 endpoints: ['chat'],
55 features: ['streaming', 'tools', 'json_object', 'json_schema'],
56 },
57} as const satisfies ModelMeta<MistralTextProviderOptions>
58
59const MISTRAL_MEDIUM_LATEST = {
60 name: 'mistral-medium-latest',
61 context_window: 131_072,
62 max_completion_tokens: 8_192,
63 pricing: {
64 input: { normal: 0.4 },
65 output: { normal: 2 },
66 },
67 supports: {
68 input: ['text', 'image', 'document'],
69 output: ['text'],
70 endpoints: ['chat'],
71 features: ['streaming', 'tools', 'json_object', 'json_schema', 'vision'],
72 },
73} as const satisfies ModelMeta<MistralTextProviderOptions>
74
75const MISTRAL_SMALL_LATEST = {
76 name: 'mistral-small-latest',
77 context_window: 131_072,
78 max_completion_tokens: 8_192,
79 pricing: {
80 input: { normal: 0.1 },
81 output: { normal: 0.3 },
82 },
83 supports: {
84 input: ['text', 'image', 'document'],
85 output: ['text'],
86 endpoints: ['chat'],
87 features: ['streaming', 'tools', 'json_object', 'json_schema', 'vision'],
88 },
89} as const satisfies ModelMeta<MistralTextProviderOptions>
90
91const MINISTRAL_8B_LATEST = {
92 name: 'ministral-8b-latest',
93 context_window: 131_072,
94 max_completion_tokens: 8_192,
95 pricing: {
96 input: { normal: 0.1 },
97 output: { normal: 0.1 },
98 },
99 supports: {
100 input: ['text'],
101 output: ['text'],
102 endpoints: ['chat'],
103 features: ['streaming', 'tools', 'json_object', 'json_schema'],
104 },
105} as const satisfies ModelMeta<MistralTextProviderOptions>
106
107const MINISTRAL_3B_LATEST = {
108 name: 'ministral-3b-latest',
109 context_window: 131_072,
110 max_completion_tokens: 8_192,
111 pricing: {
112 input: { normal: 0.04 },
113 output: { normal: 0.04 },
114 },
115 supports: {
116 input: ['text'],
117 output: ['text'],
118 endpoints: ['chat'],
119 features: ['streaming', 'tools', 'json_object', 'json_schema'],
120 },
121} as const satisfies ModelMeta<MistralTextProviderOptions>
122
123const CODESTRAL_LATEST = {
124 name: 'codestral-latest',
125 context_window: 256_000,
126 max_completion_tokens: 8_192,
127 pricing: {
128 input: { normal: 0.3 },
129 output: { normal: 0.9 },
130 },
131 supports: {
132 input: ['text'],
133 output: ['text'],
134 endpoints: ['chat'],
135 features: ['streaming', 'tools', 'json_object', 'json_schema', 'code'],
136 },
137} as const satisfies ModelMeta<MistralTextProviderOptions>
138
139const PIXTRAL_LARGE_LATEST = {
140 name: 'pixtral-large-latest',
141 context_window: 131_072,
142 max_completion_tokens: 8_192,
143 pricing: {
144 input: { normal: 2 },
145 output: { normal: 6 },
146 },
147 supports: {
148 input: ['text', 'image', 'document'],
149 output: ['text'],
150 endpoints: ['chat'],
151 features: ['streaming', 'tools', 'json_object', 'json_schema', 'vision'],
152 },
153} as const satisfies ModelMeta<MistralTextProviderOptions>
154
155const PIXTRAL_12B_2409 = {
156 name: 'pixtral-12b-2409',
157 context_window: 131_072,
158 max_completion_tokens: 8_192,
159 pricing: {
160 input: { normal: 0.15 },
161 output: { normal: 0.15 },
162 },
163 supports: {
164 input: ['text', 'image', 'document'],
165 output: ['text'],
166 endpoints: ['chat'],
167 features: ['streaming', 'tools', 'json_object', 'vision'],
168 },
169} as const satisfies ModelMeta<MistralTextProviderOptions>
170
171const MAGISTRAL_MEDIUM_LATEST = {
172 name: 'magistral-medium-latest',
173 context_window: 40_000,
174 max_completion_tokens: 40_000,
175 pricing: {
176 input: { normal: 2 },
177 output: { normal: 5 },
178 },
179 supports: {
180 input: ['text'],
181 output: ['text'],
182 endpoints: ['chat'],
183 features: ['streaming', 'tools', 'reasoning', 'json_object', 'json_schema'],
184 },
185} as const satisfies ModelMeta<MistralTextProviderOptions>
186
187const MAGISTRAL_SMALL_LATEST = {
188 name: 'magistral-small-latest',
189 context_window: 40_000,
190 max_completion_tokens: 40_000,
191 pricing: {
192 input: { normal: 0.5 },
193 output: { normal: 1.5 },
194 },
195 supports: {
196 input: ['text'],
197 output: ['text'],
198 endpoints: ['chat'],
199 features: ['streaming', 'tools', 'reasoning', 'json_object', 'json_schema'],
200 },
201} as const satisfies ModelMeta<MistralTextProviderOptions>
202
203const OPEN_MISTRAL_NEMO = {
204 name: 'open-mistral-nemo',
205 context_window: 131_072,
206 max_completion_tokens: 8_192,
207 pricing: {
208 input: { normal: 0.15 },
209 output: { normal: 0.15 },
210 },
211 supports: {
212 input: ['text'],
213 output: ['text'],
214 endpoints: ['chat'],
215 features: ['streaming', 'tools', 'json_object'],
216 },
217} as const satisfies ModelMeta<MistralTextProviderOptions>
218
219// Vertex Model Garden IDs. These are not the Mistral API catalog.
220// Source: https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/partner-models/mistral
221const MISTRAL_MEDIUM_3 = {
222 name: 'mistral-medium-3',
223 context_window: 131_072,
224 max_completion_tokens: 8_192,
225 pricing: {
226 input: { normal: 0.4 },
227 output: { normal: 2 },
228 },
229 supports: {
230 input: ['text', 'image', 'document'],
231 output: ['text'],
232 endpoints: ['chat'],
233 features: ['streaming', 'tools', 'json_object', 'json_schema', 'vision'],
234 },
235} as const satisfies ModelMeta<MistralTextProviderOptions>
236
237const MISTRAL_SMALL_2503 = {
238 name: 'mistral-small-2503',
239 context_window: 131_072,
240 max_completion_tokens: 8_192,
241 pricing: {
242 input: { normal: 0.1 },
243 output: { normal: 0.3 },
244 },
245 supports: {
246 input: ['text', 'image', 'document'],
247 output: ['text'],
248 endpoints: ['chat'],
249 features: ['streaming', 'tools', 'json_object', 'json_schema', 'vision'],
250 },
251} as const satisfies ModelMeta<MistralTextProviderOptions>
252
253const CODESTRAL_2 = {
254 name: 'codestral-2',
255 context_window: 131_072,
256 max_completion_tokens: 8_192,
257 pricing: {
258 input: { normal: 0.3 },
259 output: { normal: 0.9 },
260 },
261 supports: {
262 input: ['text'],
263 output: ['text'],
264 endpoints: ['chat'],
265 features: ['streaming', 'tools', 'json_object', 'json_schema', 'code'],
266 },
267} as const satisfies ModelMeta<MistralTextProviderOptions>
268
269/**
270 * All supported Mistral chat model identifiers.
271 */
272export const MISTRAL_CHAT_MODELS = [
273 MISTRAL_LARGE_LATEST.name,
274 MISTRAL_MEDIUM_LATEST.name,
275 MISTRAL_SMALL_LATEST.name,
276 MINISTRAL_8B_LATEST.name,
277 MINISTRAL_3B_LATEST.name,
278 CODESTRAL_LATEST.name,
279 PIXTRAL_LARGE_LATEST.name,
280 PIXTRAL_12B_2409.name,
281 MAGISTRAL_MEDIUM_LATEST.name,
282 MAGISTRAL_SMALL_LATEST.name,
283 OPEN_MISTRAL_NEMO.name,
284] as const
285
286/**
287 * Union type of all supported Mistral chat model names.
288 */
289export type MistralChatModels = (typeof MISTRAL_CHAT_MODELS)[number]
290
291/**
292 * Mistral chat models on Vertex AI / Gemini Enterprise Agent Platform.
293 * This list is the Google partner catalog, not the Mistral API catalog.
294 * OCR (`mistral-ocr-2505`) is not a chat model.
295 */
296export const MISTRAL_VERTEX_CHAT_MODELS = [
297 MISTRAL_MEDIUM_3.name,
298 MISTRAL_SMALL_2503.name,
299 CODESTRAL_2.name,
300] as const
301
302export type MistralVertexChatModel = (typeof MISTRAL_VERTEX_CHAT_MODELS)[number]
303export type MistralTextAdapterModel = MistralChatModels | MistralVertexChatModel
304
305/**
306 * Type-only map from Mistral chat model name to its supported input modalities.
307 */
308export type MistralModelInputModalitiesByName = {
309 [MISTRAL_LARGE_LATEST.name]: typeof MISTRAL_LARGE_LATEST.supports.input
310 [MISTRAL_MEDIUM_LATEST.name]: typeof MISTRAL_MEDIUM_LATEST.supports.input
311 [MISTRAL_SMALL_LATEST.name]: typeof MISTRAL_SMALL_LATEST.supports.input
312 [MINISTRAL_8B_LATEST.name]: typeof MINISTRAL_8B_LATEST.supports.input
313 [MINISTRAL_3B_LATEST.name]: typeof MINISTRAL_3B_LATEST.supports.input
314 [CODESTRAL_LATEST.name]: typeof CODESTRAL_LATEST.supports.input
315 [PIXTRAL_LARGE_LATEST.name]: typeof PIXTRAL_LARGE_LATEST.supports.input
316 [PIXTRAL_12B_2409.name]: typeof PIXTRAL_12B_2409.supports.input
317 [MAGISTRAL_MEDIUM_LATEST.name]: typeof MAGISTRAL_MEDIUM_LATEST.supports.input
318 [MAGISTRAL_SMALL_LATEST.name]: typeof MAGISTRAL_SMALL_LATEST.supports.input
319 [OPEN_MISTRAL_NEMO.name]: typeof OPEN_MISTRAL_NEMO.supports.input
320 [MISTRAL_MEDIUM_3.name]: typeof MISTRAL_MEDIUM_3.supports.input
321 [MISTRAL_SMALL_2503.name]: typeof MISTRAL_SMALL_2503.supports.input
322 [CODESTRAL_2.name]: typeof CODESTRAL_2.supports.input
323}
324
325/**
326 * Type-only map from Mistral chat model name to its provider options type.
327 */
328export type MistralChatModelProviderOptionsByName = {
329 [MISTRAL_LARGE_LATEST.name]: MistralTextProviderOptions
330 [MISTRAL_MEDIUM_LATEST.name]: MistralVisionProviderOptions
331 [MISTRAL_SMALL_LATEST.name]: MistralVisionProviderOptions
332 [MINISTRAL_8B_LATEST.name]: MistralTextProviderOptions
333 [MINISTRAL_3B_LATEST.name]: MistralTextProviderOptions
334 [CODESTRAL_LATEST.name]: MistralTextProviderOptions
335 [PIXTRAL_LARGE_LATEST.name]: MistralVisionProviderOptions
336 [PIXTRAL_12B_2409.name]: MistralVisionProviderOptions
337 [MAGISTRAL_MEDIUM_LATEST.name]: MistralReasoningProviderOptions
338 [MAGISTRAL_SMALL_LATEST.name]: MistralReasoningProviderOptions
339 [OPEN_MISTRAL_NEMO.name]: MistralTextProviderOptions
340 [MISTRAL_MEDIUM_3.name]: MistralVisionProviderOptions
341 [MISTRAL_SMALL_2503.name]: MistralVisionProviderOptions
342 [CODESTRAL_2.name]: MistralTextProviderOptions
343}
344
345/**
346 * Embedding models (based on endpoints: "embeddings")
347 */
348export const MISTRAL_EMBEDDING_MODELS = [
349 'mistral-embed',
350 'codestral-embed',
351] as const
352
353/**
354 * Union type of all supported Mistral embedding model names.
355 */
356export type MistralEmbeddingModel = (typeof MISTRAL_EMBEDDING_MODELS)[number]
357
358/**
359 * Type-only map from embedding model name to its provider options type.
360 *
361 * `mistral-embed` accepts no provider options (fixed 1024-dim output);
362 * `codestral-embed` additionally supports `outputDtype`.
363 */
364export type MistralEmbeddingModelProviderOptionsByName = {
365 'mistral-embed': MistralEmbedProviderOptions
366 'codestral-embed': CodestralEmbedProviderOptions
367}
368
369/**
370 * Per-model input modalities for embedding models. Mistral embedding models
371 * are text-only, so image inputs fail at compile time.
372 */
373export type MistralEmbeddingModelInputModalitiesByName = {
374 'mistral-embed': readonly ['text']
375 'codestral-embed': readonly ['text']
376}
377
378/**
379 * Resolves the provider options type for a specific Mistral model.
380 */
381export type ResolveProviderOptions<TModel extends string> =
382 TModel extends keyof MistralChatModelProviderOptionsByName
383 ? MistralChatModelProviderOptionsByName[TModel]
384 : MistralTextProviderOptions
385
386/**
387 * Resolve input modalities for a specific model.
388 */
389export type ResolveInputModalities<TModel extends string> =
390 TModel extends keyof MistralModelInputModalitiesByName
391 ? MistralModelInputModalitiesByName[TModel]
392 : readonly ['text']