@ai-sdk/mistral 4.0.0-beta.4 → 4.0.0-beta.55

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.
@@ -2,29 +2,29 @@ import { z } from 'zod/v4';
2
2
 
3
3
  // https://docs.mistral.ai/getting-started/models/models_overview/
4
4
  export type MistralChatModelId =
5
- // premier
6
5
  | 'ministral-3b-latest'
7
6
  | 'ministral-8b-latest'
7
+ | 'ministral-14b-latest'
8
8
  | 'mistral-large-latest'
9
9
  | 'mistral-medium-latest'
10
+ | 'mistral-medium-3'
11
+ | 'mistral-large-2512'
10
12
  | 'mistral-medium-2508'
11
13
  | 'mistral-medium-2505'
12
- | 'mistral-small-latest'
14
+ | 'mistral-small-2506'
13
15
  | 'pixtral-large-latest'
16
+ // reasoning config support models
17
+ | 'mistral-medium-3.5'
18
+ | 'mistral-small-latest'
19
+ | 'mistral-small-2603'
14
20
  // reasoning models
15
- | 'magistral-small-2507'
16
- | 'magistral-medium-2507'
17
- | 'magistral-small-2506'
18
- | 'magistral-medium-2506'
19
- // free
20
- | 'pixtral-12b-2409'
21
- // legacy
22
- | 'open-mistral-7b'
23
- | 'open-mixtral-8x7b'
24
- | 'open-mixtral-8x22b'
21
+ | 'magistral-medium-latest'
22
+ | 'magistral-small-latest'
23
+ | 'magistral-medium-2509'
24
+ | 'magistral-small-2509'
25
25
  | (string & {});
26
26
 
27
- export const mistralLanguageModelOptions = z.object({
27
+ export const mistralLanguageModelChatOptions = z.object({
28
28
  /**
29
29
  * Whether to inject a safety prompt before all conversations.
30
30
  *
@@ -56,8 +56,16 @@ export const mistralLanguageModelOptions = z.object({
56
56
  * @default true
57
57
  */
58
58
  parallelToolCalls: z.boolean().optional(),
59
+
60
+ /**
61
+ * Controls the reasoning effort for models that support adjustable reasoning.
62
+ *
63
+ * - `'high'`: Enable reasoning
64
+ * - `'none'`: Disable reasoning
65
+ */
66
+ reasoningEffort: z.enum(['high', 'none']).optional(),
59
67
  });
60
68
 
61
- export type MistralLanguageModelOptions = z.infer<
62
- typeof mistralLanguageModelOptions
69
+ export type MistralLanguageModelChatOptions = z.infer<
70
+ typeof mistralLanguageModelChatOptions
63
71
  >;
@@ -1,4 +1,4 @@
1
- import {
1
+ import type {
2
2
  LanguageModelV4,
3
3
  LanguageModelV4CallOptions,
4
4
  LanguageModelV4Content,
@@ -12,29 +12,37 @@ import {
12
12
  combineHeaders,
13
13
  createEventSourceResponseHandler,
14
14
  createJsonResponseHandler,
15
- FetchFunction,
16
15
  generateId,
17
16
  injectJsonInstructionIntoMessages,
17
+ isCustomReasoning,
18
+ mapReasoningToProviderEffort,
18
19
  parseProviderOptions,
19
- ParseResult,
20
20
  postJsonToApi,
21
+ serializeModelOptions,
22
+ WORKFLOW_SERIALIZE,
23
+ WORKFLOW_DESERIALIZE,
24
+ type FetchFunction,
25
+ type ParseResult,
21
26
  } from '@ai-sdk/provider-utils';
22
27
  import { z } from 'zod/v4';
23
- import { convertMistralUsage, MistralUsage } from './convert-mistral-usage';
28
+ import {
29
+ convertMistralUsage,
30
+ type MistralUsage,
31
+ } from './convert-mistral-usage';
24
32
  import { convertToMistralChatMessages } from './convert-to-mistral-chat-messages';
25
33
  import { getResponseMetadata } from './get-response-metadata';
26
34
  import { mapMistralFinishReason } from './map-mistral-finish-reason';
27
35
  import {
28
- MistralChatModelId,
29
- mistralLanguageModelOptions,
30
- } from './mistral-chat-options';
36
+ mistralLanguageModelChatOptions,
37
+ type MistralChatModelId,
38
+ } from './mistral-chat-language-model-options';
31
39
  import { mistralFailedResponseHandler } from './mistral-error';
32
40
  import { prepareTools } from './mistral-prepare-tools';
33
41
 
34
42
  type MistralChatConfig = {
35
43
  provider: string;
36
44
  baseURL: string;
37
- headers: () => Record<string, string | undefined>;
45
+ headers?: () => Record<string, string | undefined>;
38
46
  fetch?: FetchFunction;
39
47
  generateId?: () => string;
40
48
  };
@@ -47,6 +55,20 @@ export class MistralChatLanguageModel implements LanguageModelV4 {
47
55
  private readonly config: MistralChatConfig;
48
56
  private readonly generateId: () => string;
49
57
 
58
+ static [WORKFLOW_SERIALIZE](model: MistralChatLanguageModel) {
59
+ return serializeModelOptions({
60
+ modelId: model.modelId,
61
+ config: model.config,
62
+ });
63
+ }
64
+
65
+ static [WORKFLOW_DESERIALIZE](options: {
66
+ modelId: MistralChatModelId;
67
+ config: MistralChatConfig;
68
+ }) {
69
+ return new MistralChatLanguageModel(options.modelId, options.config);
70
+ }
71
+
50
72
  constructor(modelId: MistralChatModelId, config: MistralChatConfig) {
51
73
  this.modelId = modelId;
52
74
  this.config = config;
@@ -69,6 +91,7 @@ export class MistralChatLanguageModel implements LanguageModelV4 {
69
91
  topK,
70
92
  frequencyPenalty,
71
93
  presencePenalty,
94
+ reasoning,
72
95
  stopSequences,
73
96
  responseFormat,
74
97
  seed,
@@ -82,7 +105,7 @@ export class MistralChatLanguageModel implements LanguageModelV4 {
82
105
  (await parseProviderOptions({
83
106
  provider: 'mistral',
84
107
  providerOptions,
85
- schema: mistralLanguageModelOptions,
108
+ schema: mistralLanguageModelChatOptions,
86
109
  })) ?? {};
87
110
 
88
111
  if (topK != null) {
@@ -97,8 +120,37 @@ export class MistralChatLanguageModel implements LanguageModelV4 {
97
120
  warnings.push({ type: 'unsupported', feature: 'presencePenalty' });
98
121
  }
99
122
 
100
- if (stopSequences != null) {
101
- warnings.push({ type: 'unsupported', feature: 'stopSequences' });
123
+ const supportsReasoningEffort =
124
+ this.modelId === 'mistral-small-latest' ||
125
+ this.modelId === 'mistral-small-2603' ||
126
+ this.modelId === 'mistral-medium-3' ||
127
+ this.modelId === 'mistral-medium-3.5';
128
+
129
+ let resolvedReasoningEffort: string | undefined;
130
+ if (supportsReasoningEffort) {
131
+ resolvedReasoningEffort =
132
+ options.reasoningEffort ??
133
+ (isCustomReasoning(reasoning)
134
+ ? reasoning === 'none'
135
+ ? 'none'
136
+ : mapReasoningToProviderEffort({
137
+ reasoning,
138
+ effortMap: {
139
+ minimal: 'high',
140
+ low: 'high',
141
+ medium: 'high',
142
+ high: 'high',
143
+ xhigh: 'high',
144
+ },
145
+ warnings,
146
+ })
147
+ : undefined);
148
+ } else if (isCustomReasoning(reasoning)) {
149
+ warnings.push({
150
+ type: 'unsupported',
151
+ feature: 'reasoning',
152
+ details: 'This model does not support reasoning configuration.',
153
+ });
102
154
  }
103
155
 
104
156
  const structuredOutputs = options.structuredOutputs ?? true;
@@ -124,7 +176,9 @@ export class MistralChatLanguageModel implements LanguageModelV4 {
124
176
  max_tokens: maxOutputTokens,
125
177
  temperature,
126
178
  top_p: topP,
179
+ stop: stopSequences,
127
180
  random_seed: seed,
181
+ reasoning_effort: resolvedReasoningEffort,
128
182
 
129
183
  // response format:
130
184
  response_format:
@@ -183,7 +237,7 @@ export class MistralChatLanguageModel implements LanguageModelV4 {
183
237
  rawValue: rawResponse,
184
238
  } = await postJsonToApi({
185
239
  url: `${this.config.baseURL}/chat/completions`,
186
- headers: combineHeaders(this.config.headers(), options.headers),
240
+ headers: combineHeaders(this.config.headers?.(), options.headers),
187
241
  body,
188
242
  failedResponseHandler: mistralFailedResponseHandler,
189
243
  successfulResponseHandler: createJsonResponseHandler(
@@ -262,7 +316,7 @@ export class MistralChatLanguageModel implements LanguageModelV4 {
262
316
 
263
317
  const { responseHeaders, value: response } = await postJsonToApi({
264
318
  url: `${this.config.baseURL}/chat/completions`,
265
- headers: combineHeaders(this.config.headers(), options.headers),
319
+ headers: combineHeaders(this.config.headers?.(), options.headers),
266
320
  body,
267
321
  failedResponseHandler: mistralFailedResponseHandler,
268
322
  successfulResponseHandler: createEventSourceResponseHandler(
@@ -522,6 +576,13 @@ const mistralUsageSchema = z.object({
522
576
  prompt_tokens: z.number(),
523
577
  completion_tokens: z.number(),
524
578
  total_tokens: z.number(),
579
+ num_cached_tokens: z.number().nullish(),
580
+ prompt_tokens_details: z
581
+ .object({ cached_tokens: z.number().nullish() })
582
+ .nullish(),
583
+ prompt_token_details: z
584
+ .object({ cached_tokens: z.number().nullish() })
585
+ .nullish(),
525
586
  });
526
587
 
527
588
  // limited version of the schema, focussed on what is needed for the implementation
@@ -1,21 +1,24 @@
1
1
  import {
2
- EmbeddingModelV4,
3
2
  TooManyEmbeddingValuesForCallError,
3
+ type EmbeddingModelV4,
4
4
  } from '@ai-sdk/provider';
5
5
  import {
6
6
  combineHeaders,
7
7
  createJsonResponseHandler,
8
- FetchFunction,
9
8
  postJsonToApi,
9
+ serializeModelOptions,
10
+ WORKFLOW_SERIALIZE,
11
+ WORKFLOW_DESERIALIZE,
12
+ type FetchFunction,
10
13
  } from '@ai-sdk/provider-utils';
11
14
  import { z } from 'zod/v4';
12
- import { MistralEmbeddingModelId } from './mistral-embedding-options';
15
+ import type { MistralEmbeddingModelId } from './mistral-embedding-options';
13
16
  import { mistralFailedResponseHandler } from './mistral-error';
14
17
 
15
18
  type MistralEmbeddingConfig = {
16
19
  provider: string;
17
20
  baseURL: string;
18
- headers: () => Record<string, string | undefined>;
21
+ headers?: () => Record<string, string | undefined>;
19
22
  fetch?: FetchFunction;
20
23
  };
21
24
 
@@ -31,6 +34,20 @@ export class MistralEmbeddingModel implements EmbeddingModelV4 {
31
34
  return this.config.provider;
32
35
  }
33
36
 
37
+ static [WORKFLOW_SERIALIZE](model: MistralEmbeddingModel) {
38
+ return serializeModelOptions({
39
+ modelId: model.modelId,
40
+ config: model.config,
41
+ });
42
+ }
43
+
44
+ static [WORKFLOW_DESERIALIZE](options: {
45
+ modelId: MistralEmbeddingModelId;
46
+ config: MistralEmbeddingConfig;
47
+ }) {
48
+ return new MistralEmbeddingModel(options.modelId, options.config);
49
+ }
50
+
34
51
  constructor(
35
52
  modelId: MistralEmbeddingModelId,
36
53
  config: MistralEmbeddingConfig,
@@ -61,7 +78,7 @@ export class MistralEmbeddingModel implements EmbeddingModelV4 {
61
78
  rawValue,
62
79
  } = await postJsonToApi({
63
80
  url: `${this.config.baseURL}/embeddings`,
64
- headers: combineHeaders(this.config.headers(), headers),
81
+ headers: combineHeaders(this.config.headers?.(), headers),
65
82
  body: {
66
83
  model: this.modelId,
67
84
  input: values,
@@ -1,9 +1,9 @@
1
1
  import {
2
- LanguageModelV4CallOptions,
3
- SharedV4Warning,
4
2
  UnsupportedFunctionalityError,
3
+ type LanguageModelV4CallOptions,
4
+ type SharedV4Warning,
5
5
  } from '@ai-sdk/provider';
6
- import { MistralToolChoice } from './mistral-chat-prompt';
6
+ import type { MistralToolChoice } from './mistral-chat-prompt';
7
7
 
8
8
  export function prepareTools({
9
9
  tools,
@@ -1,19 +1,19 @@
1
1
  import {
2
- EmbeddingModelV4,
3
- LanguageModelV4,
4
2
  NoSuchModelError,
5
- ProviderV4,
3
+ type EmbeddingModelV4,
4
+ type LanguageModelV4,
5
+ type ProviderV4,
6
6
  } from '@ai-sdk/provider';
7
7
  import {
8
- FetchFunction,
9
8
  loadApiKey,
10
9
  withoutTrailingSlash,
11
10
  withUserAgentSuffix,
11
+ type FetchFunction,
12
12
  } from '@ai-sdk/provider-utils';
13
13
  import { MistralChatLanguageModel } from './mistral-chat-language-model';
14
- import { MistralChatModelId } from './mistral-chat-options';
14
+ import type { MistralChatModelId } from './mistral-chat-language-model-options';
15
15
  import { MistralEmbeddingModel } from './mistral-embedding-model';
16
- import { MistralEmbeddingModelId } from './mistral-embedding-options';
16
+ import type { MistralEmbeddingModelId } from './mistral-embedding-options';
17
17
  import { VERSION } from './version';
18
18
 
19
19
  export interface MistralProvider extends ProviderV4 {
package/dist/index.d.mts DELETED
@@ -1,78 +0,0 @@
1
- import { ProviderV4, LanguageModelV4, EmbeddingModelV4 } from '@ai-sdk/provider';
2
- import { FetchFunction } from '@ai-sdk/provider-utils';
3
- import { z } from 'zod/v4';
4
-
5
- type MistralChatModelId = 'ministral-3b-latest' | 'ministral-8b-latest' | 'mistral-large-latest' | 'mistral-medium-latest' | 'mistral-medium-2508' | 'mistral-medium-2505' | 'mistral-small-latest' | 'pixtral-large-latest' | 'magistral-small-2507' | 'magistral-medium-2507' | 'magistral-small-2506' | 'magistral-medium-2506' | 'pixtral-12b-2409' | 'open-mistral-7b' | 'open-mixtral-8x7b' | 'open-mixtral-8x22b' | (string & {});
6
- declare const mistralLanguageModelOptions: z.ZodObject<{
7
- safePrompt: z.ZodOptional<z.ZodBoolean>;
8
- documentImageLimit: z.ZodOptional<z.ZodNumber>;
9
- documentPageLimit: z.ZodOptional<z.ZodNumber>;
10
- structuredOutputs: z.ZodOptional<z.ZodBoolean>;
11
- strictJsonSchema: z.ZodOptional<z.ZodBoolean>;
12
- parallelToolCalls: z.ZodOptional<z.ZodBoolean>;
13
- }, z.core.$strip>;
14
- type MistralLanguageModelOptions = z.infer<typeof mistralLanguageModelOptions>;
15
-
16
- type MistralEmbeddingModelId = 'mistral-embed' | (string & {});
17
-
18
- interface MistralProvider extends ProviderV4 {
19
- (modelId: MistralChatModelId): LanguageModelV4;
20
- /**
21
- * Creates a model for text generation.
22
- */
23
- languageModel(modelId: MistralChatModelId): LanguageModelV4;
24
- /**
25
- * Creates a model for text generation.
26
- */
27
- chat(modelId: MistralChatModelId): LanguageModelV4;
28
- /**
29
- * Creates a model for text embeddings.
30
- */
31
- embedding(modelId: MistralEmbeddingModelId): EmbeddingModelV4;
32
- /**
33
- * Creates a model for text embeddings.
34
- */
35
- embeddingModel: (modelId: MistralEmbeddingModelId) => EmbeddingModelV4;
36
- /**
37
- * @deprecated Use `embedding` instead.
38
- */
39
- textEmbedding(modelId: MistralEmbeddingModelId): EmbeddingModelV4;
40
- /**
41
- * @deprecated Use `embeddingModel` instead.
42
- */
43
- textEmbeddingModel(modelId: MistralEmbeddingModelId): EmbeddingModelV4;
44
- }
45
- interface MistralProviderSettings {
46
- /**
47
- * Use a different URL prefix for API calls, e.g. to use proxy servers.
48
- * The default prefix is `https://api.mistral.ai/v1`.
49
- */
50
- baseURL?: string;
51
- /**
52
- * API key that is being send using the `Authorization` header.
53
- * It defaults to the `MISTRAL_API_KEY` environment variable.
54
- */
55
- apiKey?: string;
56
- /**
57
- * Custom headers to include in the requests.
58
- */
59
- headers?: Record<string, string>;
60
- /**
61
- * Custom fetch implementation. You can use it as a middleware to intercept requests,
62
- * or to provide a custom fetch implementation for e.g. testing.
63
- */
64
- fetch?: FetchFunction;
65
- generateId?: () => string;
66
- }
67
- /**
68
- * Create a Mistral AI provider instance.
69
- */
70
- declare function createMistral(options?: MistralProviderSettings): MistralProvider;
71
- /**
72
- * Default Mistral provider instance.
73
- */
74
- declare const mistral: MistralProvider;
75
-
76
- declare const VERSION: string;
77
-
78
- export { type MistralLanguageModelOptions, type MistralProvider, type MistralProviderSettings, VERSION, createMistral, mistral };