@ai-sdk/mistral 4.0.79 → 4.0.81
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.
- package/CHANGELOG.md +38 -0
- package/dist/index.d.ts +158 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1080 -8
- package/dist/index.js.map +1 -1
- package/docs/20-mistral.mdx +258 -8
- package/package.json +10 -3
- package/src/index.ts +5 -0
- package/src/mistral-chat-language-model-options.ts +5 -1
- package/src/mistral-model-catalog.ts +22 -1
- package/src/mistral-prepare-tools.ts +5 -7
- package/src/mistral-provider.ts +19 -0
- package/src/mistral-transcription-model-options.ts +30 -1
- package/src/mistral-transcription-model.ts +33 -0
- package/src/mistral-transcription-stream.ts +339 -0
- package/src/realtime/mistral-realtime-factory.ts +121 -0
- package/src/realtime/mistral-realtime-model-options.ts +199 -0
- package/src/realtime/mistral-realtime-model.ts +46 -0
- package/src/realtime/mistral-realtime-transport.ts +735 -0
package/docs/20-mistral.mdx
CHANGED
|
@@ -5,10 +5,14 @@ description: Learn how to use Mistral AI with AI Gateway and the direct provider
|
|
|
5
5
|
|
|
6
6
|
# Mistral AI Provider
|
|
7
7
|
|
|
8
|
-
The [Mistral AI](https://mistral.ai/) provider
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
The [Mistral AI](https://mistral.ai/) provider supports language models,
|
|
9
|
+
embeddings, speech, transcription, and realtime voice agents.
|
|
10
|
+
You can use Mistral AI language models through [AI Gateway](/providers/ai-sdk-providers/ai-gateway) (recommended) or connect directly with `@ai-sdk/mistral`.
|
|
11
|
+
|
|
12
|
+
<Note>
|
|
13
|
+
Realtime voice agents require the direct `@ai-sdk/mistral` provider and are
|
|
14
|
+
not available through AI Gateway.
|
|
15
|
+
</Note>
|
|
12
16
|
|
|
13
17
|
```ts provider="mistral" model="mistral/mistral-medium-3.5"
|
|
14
18
|
import { generateText } from 'ai';
|
|
@@ -105,6 +109,11 @@ You can use the following optional settings to customize the Mistral provider in
|
|
|
105
109
|
You can use it as a middleware to intercept requests,
|
|
106
110
|
or to provide a custom fetch implementation for e.g. testing.
|
|
107
111
|
|
|
112
|
+
- **webSocket** _WebSocketConstructor_
|
|
113
|
+
|
|
114
|
+
Custom WebSocket implementation for realtime transcription. Use a header-capable
|
|
115
|
+
implementation such as `ws` to send the required Authorization header.
|
|
116
|
+
|
|
108
117
|
## Language Models
|
|
109
118
|
|
|
110
119
|
You can create models that call the [Mistral chat API](https://docs.mistral.ai/api/#operation/createChatCompletion) using a provider instance.
|
|
@@ -115,6 +124,15 @@ Some Mistral chat models support tool calls.
|
|
|
115
124
|
const model = mistral('mistral-large-latest');
|
|
116
125
|
```
|
|
117
126
|
|
|
127
|
+
For Chat Completions models, set
|
|
128
|
+
`toolChoice: { type: 'tool', toolName: 'weather' }` to request a specific function
|
|
129
|
+
from your `tools` definitions. The provider sends Mistral's native function choice
|
|
130
|
+
and keeps all function definitions in the request. This works with both
|
|
131
|
+
`generateText` and `streamText`. Use a model that supports tool calling.
|
|
132
|
+
|
|
133
|
+
See [tool choice](/docs/ai-sdk-core/tools-and-tool-calling#tool-choice) for the
|
|
134
|
+
shared API. The `mistral.conversation()` API handles tool selection separately.
|
|
135
|
+
|
|
118
136
|
Mistral chat models also support additional model settings that are not part of the [standard call settings](/docs/ai-sdk-core/settings).
|
|
119
137
|
You can pass them as an options argument and utilize `MistralLanguageModelChatOptions` for typing:
|
|
120
138
|
|
|
@@ -290,6 +308,7 @@ console.log('ANSWER:', result.text);
|
|
|
290
308
|
```
|
|
291
309
|
|
|
292
310
|
Most Mistral reasoning models support `'high'` and `'none'` as effort levels.
|
|
311
|
+
On the Chat API, `mistral-large-4` and `mistral-large-4-0` support `'low'`, `'medium'`, and `'high'` and cannot disable reasoning. For these models, `reasoning: 'none'` maps to `'low'` with a compatibility warning; `reasoning: 'medium'` is preserved. You can also set `providerOptions.mistral.reasoningEffort: 'medium'` directly.
|
|
293
312
|
GLM-5.3 models (`zai-glm-5-3`, `zai-glm-5-3-flash`, `zai-glm-5`, `zai-glm-latest`) support `'low'`, `'high'`, and `'max'` and cannot disable reasoning.
|
|
294
313
|
|
|
295
314
|
### Example
|
|
@@ -574,7 +593,7 @@ The following optional provider options are available:
|
|
|
574
593
|
- **diarize** _boolean_
|
|
575
594
|
|
|
576
595
|
Whether to identify speakers in the transcription. Voxtral 3 requires
|
|
577
|
-
`timestampGranularities: ['segment']` when this option is `true`.
|
|
596
|
+
`timestampGranularities: ['segment']` for offline transcription when this option is `true`.
|
|
578
597
|
|
|
579
598
|
- **contextBias** _string[]_
|
|
580
599
|
|
|
@@ -590,14 +609,119 @@ available under `result.providerMetadata.mistral.usage`. Segment scores and
|
|
|
590
609
|
speaker IDs from diarization are available under
|
|
591
610
|
`result.providerMetadata.mistral.segments`.
|
|
592
611
|
|
|
612
|
+
### Realtime Transcription
|
|
613
|
+
|
|
614
|
+
Use [`experimental_streamTranscribe`](/docs/reference/ai-sdk-core/stream-transcribe)
|
|
615
|
+
with `voxtral-mini-transcribe-realtime-3` or `voxtral-mini-transcribe-realtime-3-0`.
|
|
616
|
+
The realtime model uses a WebSocket connection instead of the file upload endpoint.
|
|
617
|
+
|
|
618
|
+
```ts
|
|
619
|
+
import {
|
|
620
|
+
createMistral,
|
|
621
|
+
type MistralProviderSettings,
|
|
622
|
+
type MistralTranscriptionModelOptions,
|
|
623
|
+
} from '@ai-sdk/mistral';
|
|
624
|
+
import { experimental_streamTranscribe as streamTranscribe } from 'ai';
|
|
625
|
+
import { WebSocket } from 'ws';
|
|
626
|
+
|
|
627
|
+
const mistral = createMistral({
|
|
628
|
+
webSocket: WebSocket as unknown as MistralProviderSettings['webSocket'],
|
|
629
|
+
});
|
|
630
|
+
|
|
631
|
+
const result = streamTranscribe({
|
|
632
|
+
model: mistral.transcription('voxtral-mini-transcribe-realtime-3'),
|
|
633
|
+
audio, // ReadableStream<Uint8Array | string> from your audio source
|
|
634
|
+
inputAudioFormat: { type: 'audio/pcm', rate: 24000 },
|
|
635
|
+
providerOptions: {
|
|
636
|
+
mistral: {
|
|
637
|
+
language: 'en',
|
|
638
|
+
contextBias: ['Vercel', 'AI SDK'],
|
|
639
|
+
targetStreamingDelayMs: 480,
|
|
640
|
+
} satisfies MistralTranscriptionModelOptions,
|
|
641
|
+
},
|
|
642
|
+
});
|
|
643
|
+
|
|
644
|
+
for await (const part of result.fullStream) {
|
|
645
|
+
if (part.type === 'transcript-delta') process.stdout.write(part.delta);
|
|
646
|
+
if (part.type === 'error') throw part.error;
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
console.log(await result.text);
|
|
650
|
+
```
|
|
651
|
+
|
|
652
|
+
Audio chunks must contain raw mono, signed 16-bit little-endian PCM samples,
|
|
653
|
+
either as bytes or base64 strings. Do not send WAV headers or compressed audio.
|
|
654
|
+
Set `inputAudioFormat.rate` to the source sample rate; it defaults to 16000 Hz.
|
|
655
|
+
The provider splits large chunks, waits for session configuration before sending
|
|
656
|
+
audio, and waits for the final transcript after the input stream closes. Use
|
|
657
|
+
`abortSignal` to cancel a session.
|
|
658
|
+
|
|
593
659
|
<Note>
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
660
|
+
Mistral requires an Authorization header on the WebSocket connection. Native
|
|
661
|
+
WebSocket implementations cannot send this header. On the server, pass a
|
|
662
|
+
header-capable implementation such as `ws` to `createMistral({webSocket})`.
|
|
663
|
+
Custom `fetch` does not intercept WebSocket connections. Keep the API key on
|
|
664
|
+
your server when relaying microphone audio from a browser.
|
|
597
665
|
</Note>
|
|
598
666
|
|
|
667
|
+
Realtime transcription accepts `language`, `contextBias`, and `diarize`, plus:
|
|
668
|
+
|
|
669
|
+
- **targetStreamingDelayMs** _number_
|
|
670
|
+
|
|
671
|
+
An integer from 80 to 1200, or 2400. Lower values reduce transcription delay;
|
|
672
|
+
higher values give the model more context. Omit it to use Mistral's default.
|
|
673
|
+
|
|
674
|
+
- **speakerReferences** _Record<string, string>_
|
|
675
|
+
|
|
676
|
+
Named, base64-encoded WAV, MP3, FLAC, or Opus reference clips. Requires
|
|
677
|
+
`diarize: true`. Mistral supports up to eight clips of 3–15 seconds each.
|
|
678
|
+
The names become speaker IDs. This provider option is supported in realtime
|
|
679
|
+
calls only.
|
|
680
|
+
|
|
681
|
+
All reference clips are sent together in one `session.update` message; the SDK
|
|
682
|
+
does not split them into chunks. When using AI Gateway, the entire serialized
|
|
683
|
+
start frame, including all provider options and base64-encoded references, must
|
|
684
|
+
fit within 256 KiB (262,144 bytes). Base64 increases file sizes by about one
|
|
685
|
+
third, leaving less than 192 KiB for the combined original reference files
|
|
686
|
+
after accounting for JSON and other options. Exceeding the frame limit can
|
|
687
|
+
close the connection. Use short, compressed reference clips and account for
|
|
688
|
+
the complete frame size; the clip count and duration limits alone do not
|
|
689
|
+
guarantee that the references fit.
|
|
690
|
+
|
|
691
|
+
- **turnDetection** _object_
|
|
692
|
+
|
|
693
|
+
An empty object enables default turn detection. Optional fields are
|
|
694
|
+
`startThreshold`, `eagerEndThreshold`, and `endThreshold` (numbers from 0 to 1),
|
|
695
|
+
plus `minSilenceMs` and `endTimeoutMs` (nonnegative integer milliseconds).
|
|
696
|
+
Mistral validates threshold ordering and rejects combining turn detection
|
|
697
|
+
with diarization.
|
|
698
|
+
|
|
699
|
+
`temperature`, `returnLanguage`, and `timestampGranularities` are not sent in
|
|
700
|
+
realtime calls and produce unsupported-option warnings. Realtime-only options
|
|
701
|
+
produce warnings when passed to `transcribe`.
|
|
702
|
+
|
|
703
|
+
With `diarize: true`, incoming segments become `transcript-final` parts with
|
|
704
|
+
`part.providerMetadata.mistral.speakerId`. Realtime timestamps may be absent:
|
|
705
|
+
only timed segments appear in `result.segments`, while all returned segments,
|
|
706
|
+
including speaker IDs, appear in `result.providerMetadata.mistral.segments`.
|
|
707
|
+
Usage is available in `result.providerMetadata.mistral.usage` when returned.
|
|
708
|
+
|
|
709
|
+
Set `includeRawChunks: true` to receive Mistral's `turn.start`, `turn.eager_end`,
|
|
710
|
+
`turn.resume`, and `turn.end` events in `raw` parts. These are not normalized
|
|
711
|
+
transcription events. **A `turn.end` event can precede trailing text deltas**;
|
|
712
|
+
continue reading until the stream completes for the final transcript.
|
|
713
|
+
|
|
714
|
+
See Mistral's [realtime protocol](https://docs.mistral.ai/studio/audio/speech-to-text/transcribe-in-realtime),
|
|
715
|
+
[diarization](https://docs.mistral.ai/studio/audio/speech-to-text/diarize-speakers),
|
|
716
|
+
and [turn detection](https://docs.mistral.ai/studio/audio/speech-to-text/turn-detection)
|
|
717
|
+
documentation for the server-side constraints and event semantics.
|
|
718
|
+
|
|
599
719
|
### Model Capabilities
|
|
600
720
|
|
|
721
|
+
The following table covers offline models. The realtime models listed above
|
|
722
|
+
support streaming transcription, diarization, context bias, and turn detection;
|
|
723
|
+
realtime timestamps can be absent.
|
|
724
|
+
|
|
601
725
|
{/* model-capabilities:mistral-transcription:start */}
|
|
602
726
|
|
|
603
727
|
| Model | Timestamps | Diarization | Context Bias |
|
|
@@ -713,6 +837,132 @@ is redacted from request metadata and API call errors returned by the provider.
|
|
|
713
837
|
|
|
714
838
|
{/* model-capabilities:mistral-speech:end */}
|
|
715
839
|
|
|
840
|
+
## Realtime Voice Agents
|
|
841
|
+
|
|
842
|
+
Realtime voice agents require the direct `@ai-sdk/mistral` provider. AI Gateway
|
|
843
|
+
does not currently support Mistral voice agents.
|
|
844
|
+
|
|
845
|
+
`mistral.experimental_realtime()` connects to Mistral's
|
|
846
|
+
[managed voice agents](https://docs.mistral.ai/studio/audio/voice-agents/overview):
|
|
847
|
+
Mistral handles transcription, response generation, speech, and interruptions.
|
|
848
|
+
The provider handles the LiveKit connection internally. Your application uses the
|
|
849
|
+
existing realtime hook to send microphone audio and play the response.
|
|
850
|
+
|
|
851
|
+
<Note type="warning">Realtime voice agents are experimental.</Note>
|
|
852
|
+
|
|
853
|
+
Install the provider, React hook, and optional `livekit-client` peer dependency
|
|
854
|
+
required for browser voice connections:
|
|
855
|
+
|
|
856
|
+
<InstallPackages packages="ai @ai-sdk/mistral @ai-sdk/react livekit-client" />
|
|
857
|
+
|
|
858
|
+
Server-side consumers that only create and close sessions or use other Mistral
|
|
859
|
+
models do not need `livekit-client`.
|
|
860
|
+
|
|
861
|
+
Keep `MISTRAL_API_KEY` on your server. Create a route that starts and closes
|
|
862
|
+
sessions with server-owned configuration:
|
|
863
|
+
|
|
864
|
+
```ts filename="app/api/mistral-realtime/route.ts"
|
|
865
|
+
import { mistral } from '@ai-sdk/mistral';
|
|
866
|
+
|
|
867
|
+
export async function POST() {
|
|
868
|
+
const session = await mistral.experimental_realtime.createSession({
|
|
869
|
+
model: 'mistral-small-latest',
|
|
870
|
+
sessionConfig: {
|
|
871
|
+
instructions: 'You are a helpful voice assistant. Respond briefly.',
|
|
872
|
+
voice: 'voice_447',
|
|
873
|
+
providerOptions: {
|
|
874
|
+
mistral: {
|
|
875
|
+
stt: { model: 'voxtral-mini-transcribe-realtime-3' },
|
|
876
|
+
tts: { model: 'voxtral-mini-tts-3' },
|
|
877
|
+
},
|
|
878
|
+
},
|
|
879
|
+
},
|
|
880
|
+
});
|
|
881
|
+
return Response.json(session, {
|
|
882
|
+
headers: { 'Cache-Control': 'no-store' },
|
|
883
|
+
});
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
export async function DELETE(request: Request) {
|
|
887
|
+
const sessionId = new URL(request.url).searchParams.get('sessionId');
|
|
888
|
+
if (sessionId == null || sessionId.trim() === '') {
|
|
889
|
+
return Response.json({ error: 'sessionId is required' }, { status: 400 });
|
|
890
|
+
}
|
|
891
|
+
await mistral.experimental_realtime.closeSession({ sessionId });
|
|
892
|
+
return new Response(null, { status: 204 });
|
|
893
|
+
}
|
|
894
|
+
```
|
|
895
|
+
|
|
896
|
+
Authenticate both routes and verify session ownership before closing a session
|
|
897
|
+
in production. The browser receives session credentials, never the API key.
|
|
898
|
+
|
|
899
|
+
Use `api.provider` with the same route in the browser:
|
|
900
|
+
|
|
901
|
+
```tsx filename="app/mistral-realtime/page.tsx"
|
|
902
|
+
'use client';
|
|
903
|
+
|
|
904
|
+
import { mistral } from '@ai-sdk/mistral';
|
|
905
|
+
import { experimental_useRealtime as useRealtime } from '@ai-sdk/react';
|
|
906
|
+
import { useState } from 'react';
|
|
907
|
+
|
|
908
|
+
const model = mistral.experimental_realtime('mistral-small-latest');
|
|
909
|
+
|
|
910
|
+
export default function VoiceChat() {
|
|
911
|
+
const [error, setError] = useState('');
|
|
912
|
+
const realtime = useRealtime({
|
|
913
|
+
model,
|
|
914
|
+
api: { provider: '/api/mistral-realtime' },
|
|
915
|
+
onError: error => setError(error.message),
|
|
916
|
+
});
|
|
917
|
+
|
|
918
|
+
return (
|
|
919
|
+
<>
|
|
920
|
+
<button onClick={() => realtime.connect()}>Start conversation</button>
|
|
921
|
+
<button onClick={() => realtime.close()}>Stop</button>
|
|
922
|
+
<button onClick={() => realtime.resumePlayback()}>Enable audio</button>
|
|
923
|
+
<p>{realtime.status}</p>
|
|
924
|
+
{error && <p role="alert">{error}</p>}
|
|
925
|
+
{realtime.messages.map(message => (
|
|
926
|
+
<p key={message.id}>
|
|
927
|
+
<strong>{message.role}: </strong>
|
|
928
|
+
{message.parts.map((part, index) =>
|
|
929
|
+
part.type === 'text' ? <span key={index}>{part.text}</span> : null,
|
|
930
|
+
)}
|
|
931
|
+
</p>
|
|
932
|
+
))}
|
|
933
|
+
</>
|
|
934
|
+
);
|
|
935
|
+
}
|
|
936
|
+
```
|
|
937
|
+
|
|
938
|
+
`connect()` requests microphone permission and starts playback. Use HTTPS or
|
|
939
|
+
localhost. If the browser blocks playback, call `resumePlayback()` from a user
|
|
940
|
+
gesture. Await `close()` to stop the microphone, leave the room, and close the
|
|
941
|
+
server-side session. Transcripts appear in `messages`; `isCapturing`, `isPlaying`,
|
|
942
|
+
and `onError` expose media state and failures.
|
|
943
|
+
|
|
944
|
+
Configure the session on the server with `instructions`, `voice`, and
|
|
945
|
+
`providerOptions.mistral`. The latter supports `stt`, `tts`, `turn`,
|
|
946
|
+
`welcomeMessage`, `agentId`, and `agentVersion`, and is typed by
|
|
947
|
+
`Experimental_MistralRealtimeModelOptions`. The factory's model ID selects the
|
|
948
|
+
language model; STT and TTS models are separate settings. `voice` takes precedence
|
|
949
|
+
over `tts.voiceId`.
|
|
950
|
+
|
|
951
|
+
This integration supports microphone conversations, transcripts, capture and
|
|
952
|
+
playback controls, client tools, and session cleanup. Pass tool definitions in
|
|
953
|
+
the server's `sessionConfig.tools` and handle calls with `onToolCall` or
|
|
954
|
+
`addToolOutput`, as described in [Realtime tool calling](/docs/ai-sdk-core/realtime#tool-calling).
|
|
955
|
+
Session updates support instructions, tools, and `providerOptions.mistral.turn`.
|
|
956
|
+
|
|
957
|
+
Text messages and manual audio-buffer or response commands are unsupported.
|
|
958
|
+
Audio formats are negotiated by LiveKit; omit `inputAudioFormat`,
|
|
959
|
+
`outputAudioFormat`, and normalized `turnDetection`. Configure turn behavior
|
|
960
|
+
through `providerOptions.mistral` instead. `getToken()` and the hook's `api.token`,
|
|
961
|
+
`api.websocket`, and `api.session` paths do not connect to these managed sessions.
|
|
962
|
+
|
|
963
|
+
The complete microphone-to-speaker example is at
|
|
964
|
+
[`examples/ai-e2e-next/app/mistral-realtime`](https://github.com/vercel/ai/tree/main/examples/ai-e2e-next/app/mistral-realtime).
|
|
965
|
+
|
|
716
966
|
## Embedding Models
|
|
717
967
|
|
|
718
968
|
You can create models that call the [Mistral embeddings API](https://docs.mistral.ai/api/#operation/createEmbedding)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/mistral",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.81",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -29,21 +29,28 @@
|
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@ai-sdk/provider": "4.0.
|
|
33
|
-
"@ai-sdk/provider-utils": "5.0.
|
|
32
|
+
"@ai-sdk/provider": "4.0.37",
|
|
33
|
+
"@ai-sdk/provider-utils": "5.0.76"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@ai-sdk/test-server": "2.0.4",
|
|
37
37
|
"@types/node": "22.19.19",
|
|
38
38
|
"@vercel/ai-tsconfig": "0.0.0",
|
|
39
39
|
"@vercel/ai-tsdown-config": "0.0.0",
|
|
40
|
+
"livekit-client": "^2.23.0",
|
|
40
41
|
"tsdown": "^0.23.0",
|
|
41
42
|
"typescript": "6.0.3",
|
|
42
43
|
"zod": "3.25.76"
|
|
43
44
|
},
|
|
44
45
|
"peerDependencies": {
|
|
46
|
+
"livekit-client": "^2.23.0",
|
|
45
47
|
"zod": "^3.25.76 || ^4.1.8"
|
|
46
48
|
},
|
|
49
|
+
"peerDependenciesMeta": {
|
|
50
|
+
"livekit-client": {
|
|
51
|
+
"optional": true
|
|
52
|
+
}
|
|
53
|
+
},
|
|
47
54
|
"engines": {
|
|
48
55
|
"node": ">=22"
|
|
49
56
|
},
|
package/src/index.ts
CHANGED
|
@@ -18,4 +18,9 @@ export type {
|
|
|
18
18
|
MistralTranscriptionModelId,
|
|
19
19
|
MistralTranscriptionModelOptions,
|
|
20
20
|
} from './mistral-transcription-model-options';
|
|
21
|
+
export type {
|
|
22
|
+
MistralRealtimeFactory as Experimental_MistralRealtimeFactory,
|
|
23
|
+
MistralRealtimeSession as Experimental_MistralRealtimeSession,
|
|
24
|
+
} from './realtime/mistral-realtime-factory';
|
|
25
|
+
export type { MistralRealtimeModelOptions as Experimental_MistralRealtimeModelOptions } from './realtime/mistral-realtime-model-options';
|
|
21
26
|
export { VERSION } from './version';
|
|
@@ -87,11 +87,15 @@ export const mistralLanguageModelChatOptions = () =>
|
|
|
87
87
|
*
|
|
88
88
|
* - `'high'`: Enable reasoning
|
|
89
89
|
* - `'none'`: Disable reasoning
|
|
90
|
+
* - `'medium'`: Medium reasoning effort for models that support it, e.g.
|
|
91
|
+
* `mistral-large-4`, which accepts `'low'`, `'medium'`, and `'high'`
|
|
90
92
|
* - `'low'`, `'max'`: Lowest and highest reasoning effort for models that
|
|
91
93
|
* support them, e.g. `zai-glm-5-3`, which accepts `'low'`, `'high'`, and
|
|
92
94
|
* `'max'` but not `'none'`
|
|
93
95
|
*/
|
|
94
|
-
reasoningEffort: z
|
|
96
|
+
reasoningEffort: z
|
|
97
|
+
.enum(['high', 'none', 'low', 'medium', 'max'])
|
|
98
|
+
.optional(),
|
|
95
99
|
});
|
|
96
100
|
export const mistralLanguageModelChatOptionsValidator = lazySchema(() =>
|
|
97
101
|
zodSchema(mistralLanguageModelChatOptions()),
|
|
@@ -58,6 +58,15 @@ export const mistralProviderOptions = {
|
|
|
58
58
|
contextBias: {
|
|
59
59
|
description: 'Vocabulary and context to guide transcription.',
|
|
60
60
|
},
|
|
61
|
+
targetStreamingDelayMs: {
|
|
62
|
+
description: 'Target transcription delay in milliseconds. Realtime only.',
|
|
63
|
+
},
|
|
64
|
+
speakerReferences: {
|
|
65
|
+
description: 'Named audio clips for known speakers. Realtime only.',
|
|
66
|
+
},
|
|
67
|
+
turnDetection: {
|
|
68
|
+
description: 'Turn detection settings. Realtime only.',
|
|
69
|
+
},
|
|
61
70
|
} satisfies Record<
|
|
62
71
|
keyof MistralTranscriptionModelOptions,
|
|
63
72
|
ProviderOptionDefinition
|
|
@@ -168,6 +177,13 @@ const modelsWithLowHighMaxReasoningEffort = new Set<MistralChatModelId>([
|
|
|
168
177
|
'zai-glm-latest',
|
|
169
178
|
]);
|
|
170
179
|
|
|
180
|
+
// Mistral Large 4 Chat models accept low, medium, and high reasoning effort
|
|
181
|
+
// and cannot disable reasoning (see #24350).
|
|
182
|
+
const modelsWithLowMediumHighReasoningEffort = new Set<MistralChatModelId>([
|
|
183
|
+
'mistral-large-4',
|
|
184
|
+
'mistral-large-4-0',
|
|
185
|
+
]);
|
|
186
|
+
|
|
171
187
|
// https://api.mistral.ai/v1/models (2026-10-06)
|
|
172
188
|
const reasoningEffortModelIds = new Set<MistralChatModelId>([
|
|
173
189
|
'glm-5-2',
|
|
@@ -206,7 +222,9 @@ function createLanguageModelEntry(
|
|
|
206
222
|
? []
|
|
207
223
|
: modelsWithLowHighMaxReasoningEffort.has(modelId)
|
|
208
224
|
? ['low', 'high', 'max']
|
|
209
|
-
:
|
|
225
|
+
: modelsWithLowMediumHighReasoningEffort.has(modelId)
|
|
226
|
+
? ['low', 'medium', 'high']
|
|
227
|
+
: ['none', 'high'],
|
|
210
228
|
);
|
|
211
229
|
const conversationReasoning = reasoningCapabilities(
|
|
212
230
|
reasoningEffortModelIds.has(modelId) ? ['none', 'high'] : [],
|
|
@@ -273,6 +291,9 @@ function createTranscriptionModelEntry(modelId: string, declared: boolean) {
|
|
|
273
291
|
mistralProviderOptions.transcription,
|
|
274
292
|
support,
|
|
275
293
|
{
|
|
294
|
+
targetStreamingDelayMs: false,
|
|
295
|
+
speakerReferences: false,
|
|
296
|
+
turnDetection: false,
|
|
276
297
|
returnLanguage: {
|
|
277
298
|
condition: 'Only supported when language is not pinned.',
|
|
278
299
|
},
|
|
@@ -76,15 +76,13 @@ export function prepareTools({
|
|
|
76
76
|
return { tools: mistralTools, toolChoice: type, toolWarnings };
|
|
77
77
|
case 'required':
|
|
78
78
|
return { tools: mistralTools, toolChoice: 'any', toolWarnings };
|
|
79
|
-
|
|
80
|
-
// mistral does not support tool mode directly,
|
|
81
|
-
// so we filter the tools and force the tool choice through 'any'
|
|
82
79
|
case 'tool':
|
|
83
80
|
return {
|
|
84
|
-
tools: mistralTools
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
81
|
+
tools: mistralTools,
|
|
82
|
+
toolChoice: {
|
|
83
|
+
type: 'function',
|
|
84
|
+
function: { name: toolChoice.toolName },
|
|
85
|
+
},
|
|
88
86
|
toolWarnings,
|
|
89
87
|
};
|
|
90
88
|
default: {
|
package/src/mistral-provider.ts
CHANGED
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
withoutTrailingSlash,
|
|
14
14
|
withUserAgentSuffix,
|
|
15
15
|
type FetchFunction,
|
|
16
|
+
type WebSocketConstructor,
|
|
16
17
|
} from '@ai-sdk/provider-utils';
|
|
17
18
|
import { MistralChatLanguageModel } from './mistral-chat-language-model';
|
|
18
19
|
import { MistralConversationLanguageModel } from './mistral-conversation-language-model';
|
|
@@ -25,9 +26,15 @@ import { MistralTranscriptionModel } from './mistral-transcription-model';
|
|
|
25
26
|
import type { MistralTranscriptionModelId } from './mistral-transcription-model-options';
|
|
26
27
|
import { VERSION } from './version';
|
|
27
28
|
import { mistralTools } from './tool';
|
|
29
|
+
import {
|
|
30
|
+
createMistralRealtimeFactory,
|
|
31
|
+
type MistralRealtimeFactory,
|
|
32
|
+
} from './realtime/mistral-realtime-factory';
|
|
28
33
|
|
|
29
34
|
export interface MistralProvider extends ProviderV4 {
|
|
30
35
|
tools: typeof mistralTools;
|
|
36
|
+
/** Creates managed voice agents and their server-side sessions. */
|
|
37
|
+
experimental_realtime: MistralRealtimeFactory;
|
|
31
38
|
(modelId: MistralChatModelId): LanguageModelV4;
|
|
32
39
|
|
|
33
40
|
/**
|
|
@@ -112,6 +119,12 @@ export interface MistralProviderSettings {
|
|
|
112
119
|
*/
|
|
113
120
|
fetch?: FetchFunction;
|
|
114
121
|
|
|
122
|
+
/**
|
|
123
|
+
* WebSocket implementation for realtime transcription. Use a header-capable
|
|
124
|
+
* implementation such as `ws` to send Mistral's Authorization header.
|
|
125
|
+
*/
|
|
126
|
+
webSocket?: WebSocketConstructor;
|
|
127
|
+
|
|
115
128
|
generateId?: () => string;
|
|
116
129
|
}
|
|
117
130
|
|
|
@@ -179,6 +192,7 @@ export function createMistral(
|
|
|
179
192
|
baseURL,
|
|
180
193
|
headers: getHeaders,
|
|
181
194
|
fetch: options.fetch,
|
|
195
|
+
webSocket: options.webSocket,
|
|
182
196
|
});
|
|
183
197
|
|
|
184
198
|
const provider = function (modelId: MistralChatModelId) {
|
|
@@ -196,6 +210,11 @@ export function createMistral(
|
|
|
196
210
|
provider.chat = createChatModel;
|
|
197
211
|
provider.conversation = createConversationModel;
|
|
198
212
|
provider.tools = mistralTools;
|
|
213
|
+
provider.experimental_realtime = createMistralRealtimeFactory({
|
|
214
|
+
baseURL,
|
|
215
|
+
headers: getHeaders,
|
|
216
|
+
fetch: options.fetch,
|
|
217
|
+
});
|
|
199
218
|
provider.embedding = createEmbeddingModel;
|
|
200
219
|
provider.embeddingModel = createEmbeddingModel;
|
|
201
220
|
provider.textEmbedding = createEmbeddingModel;
|
|
@@ -14,6 +14,8 @@ export type MistralTranscriptionModelId =
|
|
|
14
14
|
| 'voxtral-small-transcribe-3-0'
|
|
15
15
|
| 'voxtral-small-transcribe-3'
|
|
16
16
|
| 'voxtral-small-transcribe-latest'
|
|
17
|
+
| 'voxtral-mini-transcribe-realtime-3'
|
|
18
|
+
| 'voxtral-mini-transcribe-realtime-3-0'
|
|
17
19
|
| (string & {});
|
|
18
20
|
|
|
19
21
|
// https://docs.mistral.ai/api/endpoint/audio/transcriptions
|
|
@@ -47,7 +49,8 @@ export const mistralTranscriptionModelOptions = lazySchema(() =>
|
|
|
47
49
|
|
|
48
50
|
/**
|
|
49
51
|
* Whether to identify speakers in the transcription.
|
|
50
|
-
* Voxtral 3 requires segment timestamps when diarization is enabled.
|
|
52
|
+
* Offline Voxtral 3 requires segment timestamps when diarization is enabled.
|
|
53
|
+
* Realtime diarization cannot be combined with turn detection.
|
|
51
54
|
*/
|
|
52
55
|
diarize: z.boolean().optional(),
|
|
53
56
|
|
|
@@ -60,6 +63,32 @@ export const mistralTranscriptionModelOptions = lazySchema(() =>
|
|
|
60
63
|
* with the audio.
|
|
61
64
|
*/
|
|
62
65
|
contextBias: z.array(z.string().min(1)).optional(),
|
|
66
|
+
|
|
67
|
+
/** Realtime only. Delay in milliseconds: 80–1200, or 2400. */
|
|
68
|
+
targetStreamingDelayMs: z
|
|
69
|
+
.union([z.number().int().min(80).max(1200), z.literal(2400)])
|
|
70
|
+
.optional(),
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Realtime only. Named base64-encoded audio clips for known speakers.
|
|
74
|
+
* Requires diarize. Mistral accepts up to 8 clips of 3–15 seconds each.
|
|
75
|
+
*/
|
|
76
|
+
speakerReferences: z.record(z.string(), z.string().min(1)).optional(),
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Realtime only. Enable turn detection with an empty object for defaults.
|
|
80
|
+
* Turn events are available through includeRawChunks. Mistral validates
|
|
81
|
+
* threshold ordering and compatibility with diarization.
|
|
82
|
+
*/
|
|
83
|
+
turnDetection: z
|
|
84
|
+
.object({
|
|
85
|
+
startThreshold: z.number().min(0).max(1).optional(),
|
|
86
|
+
eagerEndThreshold: z.number().min(0).max(1).optional(),
|
|
87
|
+
endThreshold: z.number().min(0).max(1).optional(),
|
|
88
|
+
minSilenceMs: z.number().int().nonnegative().optional(),
|
|
89
|
+
endTimeoutMs: z.number().int().nonnegative().optional(),
|
|
90
|
+
})
|
|
91
|
+
.optional(),
|
|
63
92
|
}),
|
|
64
93
|
),
|
|
65
94
|
);
|
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
WORKFLOW_DESERIALIZE,
|
|
20
20
|
WORKFLOW_SERIALIZE,
|
|
21
21
|
type FetchFunction,
|
|
22
|
+
type WebSocketConstructor,
|
|
22
23
|
} from '@ai-sdk/provider-utils';
|
|
23
24
|
import { z } from 'zod/v4';
|
|
24
25
|
import { mistralFailedResponseHandler } from './mistral-error';
|
|
@@ -27,12 +28,14 @@ import {
|
|
|
27
28
|
mistralTranscriptionModelOptions,
|
|
28
29
|
type MistralTranscriptionModelId,
|
|
29
30
|
} from './mistral-transcription-model-options';
|
|
31
|
+
import { streamMistralTranscription } from './mistral-transcription-stream';
|
|
30
32
|
|
|
31
33
|
type MistralTranscriptionModelConfig = {
|
|
32
34
|
provider: string;
|
|
33
35
|
baseURL: string;
|
|
34
36
|
headers?: Resolvable<Record<string, string | undefined>>;
|
|
35
37
|
fetch?: FetchFunction;
|
|
38
|
+
webSocket?: WebSocketConstructor;
|
|
36
39
|
_internal?: {
|
|
37
40
|
currentDate?: () => Date;
|
|
38
41
|
};
|
|
@@ -76,6 +79,20 @@ export class MistralTranscriptionModel implements TranscriptionModelV4 {
|
|
|
76
79
|
schema: mistralTranscriptionModelOptions,
|
|
77
80
|
});
|
|
78
81
|
|
|
82
|
+
for (const option of [
|
|
83
|
+
'targetStreamingDelayMs',
|
|
84
|
+
'speakerReferences',
|
|
85
|
+
'turnDetection',
|
|
86
|
+
] as const) {
|
|
87
|
+
if (mistralOptions?.[option] != null) {
|
|
88
|
+
warnings.push({
|
|
89
|
+
type: 'unsupported',
|
|
90
|
+
feature: `providerOptions.mistral.${option}`,
|
|
91
|
+
details: 'This option is only supported for realtime transcription.',
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
79
96
|
if (
|
|
80
97
|
!getMistralTranscriptionModelEntry(this.modelId).capabilities
|
|
81
98
|
.transcription.languageWithTimestamps &&
|
|
@@ -130,6 +147,22 @@ export class MistralTranscriptionModel implements TranscriptionModelV4 {
|
|
|
130
147
|
return { formData, warnings };
|
|
131
148
|
}
|
|
132
149
|
|
|
150
|
+
async doStream(
|
|
151
|
+
options: Parameters<NonNullable<TranscriptionModelV4['doStream']>>[0],
|
|
152
|
+
) {
|
|
153
|
+
return streamMistralTranscription({
|
|
154
|
+
...options,
|
|
155
|
+
modelId: this.modelId,
|
|
156
|
+
baseURL: this.config.baseURL,
|
|
157
|
+
headers: combineHeaders(
|
|
158
|
+
await resolve(this.config.headers),
|
|
159
|
+
options.headers,
|
|
160
|
+
),
|
|
161
|
+
webSocket: this.config.webSocket,
|
|
162
|
+
currentDate: this.config._internal?.currentDate?.() ?? new Date(),
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
|
|
133
166
|
async doGenerate(
|
|
134
167
|
options: Parameters<TranscriptionModelV4['doGenerate']>[0],
|
|
135
168
|
): Promise<Awaited<ReturnType<TranscriptionModelV4['doGenerate']>>> {
|