@ai-sdk/mistral 4.0.76 → 4.0.78

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.
@@ -0,0 +1,401 @@
1
+ import type {
2
+ ModelCapabilities,
3
+ ModelCapability,
4
+ ModelEntry,
5
+ ProviderOptionDefinition,
6
+ ProviderOptionDefinitions,
7
+ } from '@ai-sdk/provider';
8
+ import type {
9
+ MistralChatModelId,
10
+ MistralLanguageModelChatOptions,
11
+ } from './mistral-chat-language-model-options';
12
+ import type { MistralEmbeddingModelOptions } from './mistral-embedding-model-options';
13
+ import type { MistralSpeechModelOptions } from './mistral-speech-model-options';
14
+ import type { MistralTranscriptionModelOptions } from './mistral-transcription-model-options';
15
+
16
+ export const mistralProviderOptions = {
17
+ language: {
18
+ safePrompt: { description: 'Inject a safety prompt. Chat API only.' },
19
+ documentImageLimit: {
20
+ description: 'Maximum document images. Chat API only.',
21
+ },
22
+ documentPageLimit: {
23
+ description: 'Maximum document pages. Chat API only.',
24
+ },
25
+ structuredOutputs: {
26
+ description: 'Whether to send a JSON response schema.',
27
+ },
28
+ strictJsonSchema: {
29
+ description: 'Whether to use strict JSON schema validation.',
30
+ },
31
+ parallelToolCalls: {
32
+ description: 'Allow parallel function calls. Chat API only.',
33
+ },
34
+ promptCacheKey: { description: 'Cache affinity key. Chat API only.' },
35
+ reasoningEffort: {
36
+ description: 'Reasoning effort for configurable reasoning models.',
37
+ },
38
+ } satisfies Record<
39
+ keyof MistralLanguageModelChatOptions,
40
+ ProviderOptionDefinition
41
+ >,
42
+ embedding: {
43
+ metadata: { description: 'Metadata attached to the embedding request.' },
44
+ outputDimension: { description: 'Output embedding dimensions.' },
45
+ outputDtype: { description: 'Output embedding data type.' },
46
+ } satisfies Record<
47
+ keyof MistralEmbeddingModelOptions,
48
+ ProviderOptionDefinition
49
+ >,
50
+ transcription: {
51
+ language: { description: 'Language of the audio.' },
52
+ returnLanguage: { description: 'Return the detected language.' },
53
+ temperature: { description: 'Sampling temperature.' },
54
+ timestampGranularities: {
55
+ description: 'Timestamp granularities to return.',
56
+ },
57
+ diarize: { description: 'Identify speakers in the transcription.' },
58
+ contextBias: {
59
+ description: 'Vocabulary and context to guide transcription.',
60
+ },
61
+ } satisfies Record<
62
+ keyof MistralTranscriptionModelOptions,
63
+ ProviderOptionDefinition
64
+ >,
65
+ speech: {
66
+ refAudio: {
67
+ description: 'Reference audio for voice cloning, overriding voice.',
68
+ },
69
+ expressiveness: { description: 'Speech expressiveness, from 1 to 5.' },
70
+ phonemeHints: { description: 'Pronunciation hints as IPA phonemes.' },
71
+ } satisfies Record<keyof MistralSpeechModelOptions, ProviderOptionDefinition>,
72
+ } as const satisfies ProviderOptionDefinitions;
73
+
74
+ type ReasoningEffort = NonNullable<
75
+ MistralLanguageModelChatOptions['reasoningEffort']
76
+ >;
77
+ type ReasoningCapabilities = {
78
+ support: boolean;
79
+ efforts: readonly ReasoningEffort[];
80
+ };
81
+
82
+ type LanguageCapabilities = NonNullable<ModelCapabilities['language']> & {
83
+ reasoning: ReasoningCapabilities;
84
+ endpoints: {
85
+ conversation: {
86
+ reasoning: ReasoningCapabilities;
87
+ };
88
+ };
89
+ };
90
+
91
+ export type MistralLanguageModelEntry = {
92
+ capabilities: { language: LanguageCapabilities };
93
+ providerOptions: {
94
+ language: Record<keyof MistralLanguageModelChatOptions, ModelCapability>;
95
+ };
96
+ };
97
+
98
+ type TranscriptionCapabilities = NonNullable<
99
+ ModelCapabilities['transcription']
100
+ > & {
101
+ languageWithTimestamps: boolean;
102
+ timestamps: ModelCapability;
103
+ diarization: ModelCapability;
104
+ contextBias: ModelCapability;
105
+ };
106
+
107
+ type SpeechCapabilities = NonNullable<ModelCapabilities['speech']> & {
108
+ savedVoices: ModelCapability;
109
+ referenceAudio: ModelCapability;
110
+ nonStreaming: boolean;
111
+ outputFormats: readonly string[];
112
+ };
113
+
114
+ type MistralModelEntry = ModelEntry & {
115
+ providerOptions?: {
116
+ [Section in keyof typeof mistralProviderOptions]?: Record<
117
+ keyof (typeof mistralProviderOptions)[Section],
118
+ ModelCapability
119
+ >;
120
+ };
121
+ capabilities: ModelCapabilities & {
122
+ language?: LanguageCapabilities;
123
+ transcription?: TranscriptionCapabilities;
124
+ speech?: SpeechCapabilities;
125
+ };
126
+ };
127
+
128
+ // Preserve the provider page's documented model set and image-input exceptions.
129
+ const documentedLanguageModels: Record<string, boolean> = {
130
+ 'labs-leanstral-1-5': true,
131
+ 'magistral-medium-latest': true,
132
+ 'magistral-small-latest': true,
133
+ 'ministral-14b-latest': true,
134
+ 'ministral-8b-latest': true,
135
+ 'mistral-large-latest': true,
136
+ 'mistral-medium-latest': true,
137
+ 'mistral-small-latest': true,
138
+ 'voxtral-small-latest': false,
139
+ 'zai-glm-5-2': false,
140
+ };
141
+
142
+ // Known non-reasoning models from https://api.mistral.ai/v1/models
143
+ // (2026-10-06). Unknown IDs inherit current reasoning configuration support.
144
+ const modelsWithoutReasoningEffort = new Set<MistralChatModelId>([
145
+ 'codestral-2508',
146
+ 'codestral-latest',
147
+ 'ministral-14b-2512',
148
+ 'ministral-14b-latest',
149
+ 'ministral-3b-2512',
150
+ 'ministral-3b-latest',
151
+ 'ministral-8b-2512',
152
+ 'ministral-8b-latest',
153
+ 'mistral-code-fim-latest',
154
+ 'mistral-code-latest',
155
+ 'mistral-large-latest',
156
+ 'mistral-large-2512',
157
+ 'voxtral-small-2507',
158
+ 'voxtral-small-latest',
159
+ ]);
160
+
161
+ // GLM-5.3 models accept only low, high, and max reasoning effort and cannot
162
+ // disable reasoning. Omitting reasoning_effort uses max.
163
+ // https://docs.mistral.ai/studio/conversations/reasoning (2026-10-26)
164
+ const modelsWithLowHighMaxReasoningEffort = new Set<MistralChatModelId>([
165
+ 'zai-glm-5',
166
+ 'zai-glm-5-3',
167
+ 'zai-glm-5-3-flash',
168
+ 'zai-glm-latest',
169
+ ]);
170
+
171
+ // https://api.mistral.ai/v1/models (2026-10-06)
172
+ const reasoningEffortModelIds = new Set<MistralChatModelId>([
173
+ 'glm-5-2',
174
+ 'labs-leanstral-1-5',
175
+ 'labs-leanstral-1-5-1',
176
+ 'magistral-medium-latest',
177
+ 'magistral-small-latest',
178
+ 'mistral-large-4',
179
+ 'mistral-large-4-0',
180
+ 'mistral-medium',
181
+ 'mistral-medium-2604',
182
+ 'mistral-medium-3',
183
+ 'mistral-medium-3-5',
184
+ 'mistral-medium-3.5',
185
+ 'mistral-medium-latest',
186
+ 'mistral-small-2603',
187
+ 'mistral-small-latest',
188
+ 'mistral-vibe-cli-fast',
189
+ 'mistral-vibe-cli-latest',
190
+ 'mistral-vibe-cli-with-tools',
191
+ 'zai-glm-5-2',
192
+ ]);
193
+
194
+ function reasoningCapabilities(
195
+ efforts: readonly ReasoningEffort[],
196
+ ): ReasoningCapabilities {
197
+ return { support: efforts.length > 0, efforts };
198
+ }
199
+
200
+ function createLanguageModelEntry(
201
+ modelId: string,
202
+ image?: boolean,
203
+ ): MistralLanguageModelEntry {
204
+ const reasoning = reasoningCapabilities(
205
+ modelsWithoutReasoningEffort.has(modelId)
206
+ ? []
207
+ : modelsWithLowHighMaxReasoningEffort.has(modelId)
208
+ ? ['low', 'high', 'max']
209
+ : ['none', 'high'],
210
+ );
211
+ const conversationReasoning = reasoningCapabilities(
212
+ reasoningEffortModelIds.has(modelId) ? ['none', 'high'] : [],
213
+ );
214
+ const chatOnly = { condition: 'Only supported on the Chat API.' };
215
+ return {
216
+ capabilities: {
217
+ language: {
218
+ inputs: { image: image ?? 'unknown', audio: 'unknown' },
219
+ objectGeneration: image != null ? true : 'unknown',
220
+ tools: {
221
+ usage: image != null ? true : 'unknown',
222
+ streaming: image != null ? true : 'unknown',
223
+ },
224
+ reasoning,
225
+ sampling: { temperature: 'unknown', topP: 'unknown', logprobs: false },
226
+ endpoints: { conversation: { reasoning: conversationReasoning } },
227
+ },
228
+ },
229
+ providerOptions: {
230
+ language: declareProviderOptions(
231
+ mistralProviderOptions.language,
232
+ image != null ? true : 'unknown',
233
+ {
234
+ safePrompt: chatOnly,
235
+ documentImageLimit: chatOnly,
236
+ documentPageLimit: chatOnly,
237
+ parallelToolCalls: chatOnly,
238
+ promptCacheKey: chatOnly,
239
+ reasoningEffort:
240
+ reasoning.support && !conversationReasoning.support
241
+ ? chatOnly
242
+ : reasoning.support,
243
+ },
244
+ ),
245
+ },
246
+ };
247
+ }
248
+
249
+ function createTranscriptionModelEntry(modelId: string, declared: boolean) {
250
+ // Only these legacy IDs reject pinned language combined with timestamps.
251
+ // Future and custom IDs keep the existing permissive request behavior.
252
+ const languageWithTimestamps = ![
253
+ 'voxtral-mini-2507',
254
+ 'voxtral-mini-2602',
255
+ 'voxtral-mini-latest',
256
+ ].includes(modelId);
257
+ const support = declared ? true : 'unknown';
258
+ const capabilities: TranscriptionCapabilities = {
259
+ transcription: support,
260
+ streaming: false,
261
+ duration: support,
262
+ segments: support,
263
+ language: support,
264
+ languageWithTimestamps,
265
+ timestamps: support,
266
+ diarization: support,
267
+ contextBias: support,
268
+ };
269
+ return {
270
+ capabilities: { transcription: capabilities },
271
+ providerOptions: {
272
+ transcription: declareProviderOptions(
273
+ mistralProviderOptions.transcription,
274
+ support,
275
+ {
276
+ returnLanguage: {
277
+ condition: 'Only supported when language is not pinned.',
278
+ },
279
+ timestampGranularities: languageWithTimestamps
280
+ ? support
281
+ : {
282
+ condition: 'Only supported when language is not pinned.',
283
+ },
284
+ },
285
+ ),
286
+ },
287
+ };
288
+ }
289
+
290
+ function createSpeechModelEntry(declared: boolean) {
291
+ const support = declared ? true : 'unknown';
292
+ const capabilities: SpeechCapabilities = {
293
+ instructions: false,
294
+ savedVoices: support,
295
+ referenceAudio: support,
296
+ nonStreaming: true,
297
+ outputFormats: ['pcm', 'wav', 'mp3', 'flac', 'opus'],
298
+ };
299
+ return {
300
+ capabilities: { speech: capabilities },
301
+ providerOptions: {
302
+ speech: declareProviderOptions(
303
+ mistralProviderOptions.speech,
304
+ support,
305
+ {},
306
+ ),
307
+ },
308
+ };
309
+ }
310
+
311
+ function createEmbeddingModelEntry(
312
+ defaultDimensions: number,
313
+ customDimensions: boolean,
314
+ ) {
315
+ return {
316
+ capabilities: { embedding: { defaultDimensions, customDimensions } },
317
+ providerOptions: {
318
+ embedding: declareProviderOptions(
319
+ mistralProviderOptions.embedding,
320
+ true,
321
+ {
322
+ outputDimension: customDimensions,
323
+ outputDtype: customDimensions,
324
+ },
325
+ ),
326
+ },
327
+ };
328
+ }
329
+
330
+ export const mistralModelCatalog: Readonly<Record<string, MistralModelEntry>> =
331
+ {
332
+ ...Object.fromEntries(
333
+ Object.entries(documentedLanguageModels).map(([modelId, image]) => [
334
+ modelId,
335
+ createLanguageModelEntry(modelId, image),
336
+ ]),
337
+ ),
338
+ 'voxtral-mini-transcribe-3-0': createTranscriptionModelEntry(
339
+ 'voxtral-mini-transcribe-3-0',
340
+ true,
341
+ ),
342
+ 'voxtral-small-transcribe-3-0': createTranscriptionModelEntry(
343
+ 'voxtral-small-transcribe-3-0',
344
+ true,
345
+ ),
346
+ 'voxtral-mini-latest': createTranscriptionModelEntry(
347
+ 'voxtral-mini-latest',
348
+ true,
349
+ ),
350
+ 'voxtral-mini-tts-3-0': createSpeechModelEntry(true),
351
+ 'voxtral-mini-tts-2603': createSpeechModelEntry(true),
352
+ 'mistral-embed': createEmbeddingModelEntry(1024, false),
353
+ // https://docs.mistral.ai/studio/knowledge-rag/embeddings/code_embeddings
354
+ 'codestral-embed': createEmbeddingModelEntry(1536, true),
355
+ };
356
+
357
+ function findModelEntry(modelId: string) {
358
+ return Object.prototype.hasOwnProperty.call(mistralModelCatalog, modelId)
359
+ ? mistralModelCatalog[modelId]
360
+ : undefined;
361
+ }
362
+
363
+ export function getMistralLanguageModelEntry(
364
+ modelId: string,
365
+ ): MistralLanguageModelEntry {
366
+ const entry = findModelEntry(modelId);
367
+ return entry?.capabilities.language != null &&
368
+ entry.providerOptions?.language != null
369
+ ? {
370
+ capabilities: { language: entry.capabilities.language },
371
+ providerOptions: { language: entry.providerOptions.language },
372
+ }
373
+ : createLanguageModelEntry(modelId);
374
+ }
375
+
376
+ export function getMistralTranscriptionModelEntry(modelId: string) {
377
+ const capabilities = findModelEntry(modelId)?.capabilities.transcription;
378
+ return capabilities != null
379
+ ? { capabilities: { transcription: capabilities } }
380
+ : createTranscriptionModelEntry(modelId, false);
381
+ }
382
+
383
+ export function getMistralSpeechModelEntry(modelId: string) {
384
+ const capabilities = findModelEntry(modelId)?.capabilities.speech;
385
+ return capabilities != null
386
+ ? { capabilities: { speech: capabilities } }
387
+ : createSpeechModelEntry(false);
388
+ }
389
+
390
+ function declareProviderOptions<Option extends string>(
391
+ definitions: Readonly<Record<Option, ProviderOptionDefinition>>,
392
+ support: ModelCapability,
393
+ exceptions: Partial<Record<Option, ModelCapability>>,
394
+ ): Record<Option, ModelCapability> {
395
+ return Object.fromEntries(
396
+ (Object.keys(definitions) as Option[]).map(option => [
397
+ option,
398
+ exceptions[option] ?? support,
399
+ ]),
400
+ ) as Record<Option, ModelCapability>;
401
+ }
@@ -15,6 +15,7 @@ import {
15
15
  } from '@ai-sdk/provider-utils';
16
16
  import { z } from 'zod/v4';
17
17
  import { mistralFailedResponseHandler } from './mistral-error';
18
+ import { getMistralSpeechModelEntry } from './mistral-model-catalog';
18
19
  import {
19
20
  mistralSpeechModelOptions,
20
21
  type MistralSpeechModelId,
@@ -74,8 +75,9 @@ export class MistralSpeechModel implements SpeechModelV4 {
74
75
  schema: mistralSpeechModelOptions,
75
76
  });
76
77
 
78
+ const { speech } = getMistralSpeechModelEntry(this.modelId).capabilities;
77
79
  let responseFormat: MistralSpeechOutputFormat = 'mp3';
78
- if (['pcm', 'wav', 'mp3', 'flac', 'opus'].includes(outputFormat)) {
80
+ if (speech.outputFormats.includes(outputFormat)) {
79
81
  responseFormat = outputFormat as MistralSpeechOutputFormat;
80
82
  } else {
81
83
  warnings.push({
@@ -85,7 +87,7 @@ export class MistralSpeechModel implements SpeechModelV4 {
85
87
  });
86
88
  }
87
89
 
88
- if (instructions != null) {
90
+ if (speech.instructions === false && instructions != null) {
89
91
  warnings.push({
90
92
  type: 'unsupported',
91
93
  feature: 'instructions',
@@ -22,6 +22,7 @@ import {
22
22
  } from '@ai-sdk/provider-utils';
23
23
  import { z } from 'zod/v4';
24
24
  import { mistralFailedResponseHandler } from './mistral-error';
25
+ import { getMistralTranscriptionModelEntry } from './mistral-model-catalog';
25
26
  import {
26
27
  mistralTranscriptionModelOptions,
27
28
  type MistralTranscriptionModelId,
@@ -75,14 +76,9 @@ export class MistralTranscriptionModel implements TranscriptionModelV4 {
75
76
  schema: mistralTranscriptionModelOptions,
76
77
  });
77
78
 
78
- // Restrict only known legacy models so future and custom models can combine
79
- // a pinned language with timestamps without an SDK update.
80
79
  if (
81
- [
82
- 'voxtral-mini-2507',
83
- 'voxtral-mini-2602',
84
- 'voxtral-mini-latest',
85
- ].includes(this.modelId) &&
80
+ !getMistralTranscriptionModelEntry(this.modelId).capabilities
81
+ .transcription.languageWithTimestamps &&
86
82
  mistralOptions?.language != null &&
87
83
  mistralOptions.timestampGranularities != null
88
84
  ) {