@ai-sdk/mistral 4.0.75 → 4.0.77

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
+ }
@@ -7,6 +7,8 @@ import {
7
7
  type TranscriptionModelV4,
8
8
  } from '@ai-sdk/provider';
9
9
  import {
10
+ resolveWith,
11
+ type Resolvable,
10
12
  loadApiKey,
11
13
  withoutTrailingSlash,
12
14
  withUserAgentSuffix,
@@ -97,7 +99,7 @@ export interface MistralProviderSettings {
97
99
  * API key that is being send using the `Authorization` header.
98
100
  * It defaults to the `MISTRAL_API_KEY` environment variable.
99
101
  */
100
- apiKey?: string;
102
+ apiKey?: Resolvable<string>;
101
103
 
102
104
  /**
103
105
  * Custom headers to include in the requests.
@@ -123,16 +125,18 @@ export function createMistral(
123
125
  withoutTrailingSlash(options.baseURL) ?? 'https://api.mistral.ai/v1';
124
126
 
125
127
  const getHeaders = () =>
126
- withUserAgentSuffix(
127
- {
128
- Authorization: `Bearer ${loadApiKey({
129
- apiKey: options.apiKey,
130
- environmentVariableName: 'MISTRAL_API_KEY',
131
- description: 'Mistral',
132
- })}`,
133
- ...options.headers,
134
- },
135
- `ai-sdk-mistral/${VERSION}`,
128
+ resolveWith(options.apiKey, apiKey =>
129
+ withUserAgentSuffix(
130
+ {
131
+ Authorization: `Bearer ${loadApiKey({
132
+ apiKey,
133
+ environmentVariableName: 'MISTRAL_API_KEY',
134
+ description: 'Mistral',
135
+ })}`,
136
+ ...options.headers,
137
+ },
138
+ `ai-sdk-mistral/${VERSION}`,
139
+ ),
136
140
  );
137
141
 
138
142
  const createChatModel = (modelId: MistralChatModelId) =>
@@ -1,5 +1,7 @@
1
1
  import type { SharedV4Warning, SpeechModelV4 } from '@ai-sdk/provider';
2
2
  import {
3
+ resolve,
4
+ type Resolvable,
3
5
  lazySchema,
4
6
  zodSchema,
5
7
  combineHeaders,
@@ -13,6 +15,7 @@ import {
13
15
  } from '@ai-sdk/provider-utils';
14
16
  import { z } from 'zod/v4';
15
17
  import { mistralFailedResponseHandler } from './mistral-error';
18
+ import { getMistralSpeechModelEntry } from './mistral-model-catalog';
16
19
  import {
17
20
  mistralSpeechModelOptions,
18
21
  type MistralSpeechModelId,
@@ -21,7 +24,7 @@ import {
21
24
  interface MistralSpeechModelConfig {
22
25
  provider: string;
23
26
  baseURL: string;
24
- headers?: () => Record<string, string | undefined>;
27
+ headers?: Resolvable<Record<string, string | undefined>>;
25
28
  fetch?: FetchFunction;
26
29
  _internal?: {
27
30
  currentDate?: () => Date;
@@ -72,8 +75,9 @@ export class MistralSpeechModel implements SpeechModelV4 {
72
75
  schema: mistralSpeechModelOptions,
73
76
  });
74
77
 
78
+ const { speech } = getMistralSpeechModelEntry(this.modelId).capabilities;
75
79
  let responseFormat: MistralSpeechOutputFormat = 'mp3';
76
- if (['pcm', 'wav', 'mp3', 'flac', 'opus'].includes(outputFormat)) {
80
+ if (speech.outputFormats.includes(outputFormat)) {
77
81
  responseFormat = outputFormat as MistralSpeechOutputFormat;
78
82
  } else {
79
83
  warnings.push({
@@ -83,7 +87,7 @@ export class MistralSpeechModel implements SpeechModelV4 {
83
87
  });
84
88
  }
85
89
 
86
- if (instructions != null) {
90
+ if (speech.instructions === false && instructions != null) {
87
91
  warnings.push({
88
92
  type: 'unsupported',
89
93
  feature: 'instructions',
@@ -147,7 +151,7 @@ export class MistralSpeechModel implements SpeechModelV4 {
147
151
  url: `${this.config.baseURL}/audio/speech`,
148
152
  headers: combineHeaders(
149
153
  { 'Content-Type': 'application/json' },
150
- this.config.headers?.(),
154
+ await resolve(this.config.headers),
151
155
  options.headers,
152
156
  ),
153
157
  body: {
@@ -5,6 +5,8 @@ import {
5
5
  type TranscriptionModelV4,
6
6
  } from '@ai-sdk/provider';
7
7
  import {
8
+ resolve,
9
+ type Resolvable,
8
10
  lazySchema,
9
11
  zodSchema,
10
12
  combineHeaders,
@@ -20,6 +22,7 @@ import {
20
22
  } from '@ai-sdk/provider-utils';
21
23
  import { z } from 'zod/v4';
22
24
  import { mistralFailedResponseHandler } from './mistral-error';
25
+ import { getMistralTranscriptionModelEntry } from './mistral-model-catalog';
23
26
  import {
24
27
  mistralTranscriptionModelOptions,
25
28
  type MistralTranscriptionModelId,
@@ -28,7 +31,7 @@ import {
28
31
  type MistralTranscriptionModelConfig = {
29
32
  provider: string;
30
33
  baseURL: string;
31
- headers?: () => Record<string, string | undefined>;
34
+ headers?: Resolvable<Record<string, string | undefined>>;
32
35
  fetch?: FetchFunction;
33
36
  _internal?: {
34
37
  currentDate?: () => Date;
@@ -73,14 +76,9 @@ export class MistralTranscriptionModel implements TranscriptionModelV4 {
73
76
  schema: mistralTranscriptionModelOptions,
74
77
  });
75
78
 
76
- // Restrict only known legacy models so future and custom models can combine
77
- // a pinned language with timestamps without an SDK update.
78
79
  if (
79
- [
80
- 'voxtral-mini-2507',
81
- 'voxtral-mini-2602',
82
- 'voxtral-mini-latest',
83
- ].includes(this.modelId) &&
80
+ !getMistralTranscriptionModelEntry(this.modelId).capabilities
81
+ .transcription.languageWithTimestamps &&
84
82
  mistralOptions?.language != null &&
85
83
  mistralOptions.timestampGranularities != null
86
84
  ) {
@@ -144,7 +142,10 @@ export class MistralTranscriptionModel implements TranscriptionModelV4 {
144
142
  rawValue: rawResponse,
145
143
  } = await postFormDataToApi({
146
144
  url: `${this.config.baseURL}/audio/transcriptions`,
147
- headers: combineHeaders(this.config.headers?.(), options.headers),
145
+ headers: combineHeaders(
146
+ await resolve(this.config.headers),
147
+ options.headers,
148
+ ),
148
149
  formData,
149
150
  failedResponseHandler: mistralFailedResponseHandler,
150
151
  successfulResponseHandler: createJsonResponseHandler(