@ai-sdk/azure 4.0.87 → 4.0.89

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/docs/04-azure.mdx CHANGED
@@ -134,8 +134,8 @@ You can use the following optional settings to customize the OpenAI provider ins
134
134
 
135
135
  - **speechBaseURL** _string_
136
136
 
137
- URL prefix for Azure Speech transcription requests (MAI-Transcribe-2), for example
138
- a regional endpoint such as `https://eastus.api.cognitive.microsoft.com`.
137
+ URL prefix for Azure Speech requests (MAI-Transcribe transcription and MAI-Voice
138
+ speech generation), for example a regional endpoint such as `https://eastus.api.cognitive.microsoft.com`.
139
139
  Defaults to `https://{resourceName}.cognitiveservices.azure.com`.
140
140
  Speech requests do not use `baseURL` or `apiVersion`.
141
141
 
@@ -1114,11 +1114,17 @@ The first argument is the model id e.g. `whisper-1`.
1114
1114
  const model = azure.transcription('whisper-1');
1115
1115
  ```
1116
1116
 
1117
- ### MAI-Transcribe-2
1117
+ ### MAI-Transcribe
1118
+
1119
+ MAI-Transcribe models are multilingual speech-to-text models from Microsoft AI, served through Azure.
1120
+ The following model IDs use the Azure Speech API. They are matched case-insensitively
1121
+ and sent to Azure under their Azure model names:
1122
+
1123
+ | Model ID | Azure model | Notes |
1124
+ | -------------------- | -------------------- | ------------------------------------ |
1125
+ | `mai-transcribe-2` | `MAI-Transcribe-2` | Supports every option below. |
1126
+ | `mai-transcribe-1.5` | `MAI-Transcribe-1.5` | Supports `locales` and `phraseList`. |
1118
1127
 
1119
- MAI-Transcribe-2 is a multilingual speech-to-text model from Microsoft AI, served through Azure.
1120
- `azure.transcription('mai-transcribe-2')` uses the Azure Speech API.
1121
- The model ID is matched case-insensitively and sent to Azure as `MAI-Transcribe-2`.
1122
1128
  All other IDs use the OpenAI API by default, including custom deployment names.
1123
1129
 
1124
1130
  ```ts
@@ -1139,7 +1145,7 @@ const result = await transcribe({
1139
1145
  });
1140
1146
  ```
1141
1147
 
1142
- MAI-Transcribe-2 requires a Microsoft Foundry (Speech) resource in a region where it is available:
1148
+ MAI-Transcribe models require a Microsoft Foundry (Speech) resource in a region where they are available:
1143
1149
  `centralindia`, `eastus`, `northeurope`, `southeastasia`, `westus`, or `westus2`
1144
1150
  (see [Speech service regions](https://learn.microsoft.com/en-us/azure/ai-services/speech-service/regions?tabs=llmspeech)).
1145
1151
  Resources in other regions reject the request.
@@ -1167,17 +1173,19 @@ The following options are available through `providerOptions.azure`:
1167
1173
 
1168
1174
  - **api** _'openai' | 'speech'_
1169
1175
  Overrides model-based API selection for this request.
1170
- Set `openai` for an OpenAI deployment named `mai-transcribe-2`, or `speech` to
1176
+ Set `openai` for an OpenAI deployment named after one of the model IDs above, or `speech` to
1171
1177
  send another model ID to Speech. Other Speech model IDs are sent unchanged.
1172
1178
 
1173
1179
  - **timestamps** _'word' | 'segment' | 'none'_
1174
- Timing granularity. The AI SDK defaults to `segment` so that results include
1175
- timed segments (Azure's own default is `none`). `segment` returns one segment
1180
+ Timing granularity. For MAI-Transcribe-2 the AI SDK defaults to `segment` so that results
1181
+ include timed segments (Azure's own default is `none`). `segment` returns one segment
1176
1182
  per sentence or speaker turn, `word` additionally returns word timing in provider
1177
1183
  metadata, and `none` returns a single segment that spans the whole audio.
1184
+ MAI-Transcribe-1.5 only supports `none`, so the AI SDK does not send a default for it.
1178
1185
 
1179
1186
  - **transcribeStyle** _'verbatim' | 'clean'_
1180
1187
  `verbatim` keeps fillers and false starts, `clean` removes them. Defaults to `verbatim`.
1188
+ `clean` requires MAI-Transcribe-2.
1181
1189
 
1182
1190
  - **locales** _string[]_
1183
1191
  Exactly one language code, such as `['en']`. This is a strong hint; omit it for
@@ -1185,15 +1193,18 @@ The following options are available through `providerOptions.azure`:
1185
1193
 
1186
1194
  - **diarization** _object_
1187
1195
  Set `enabled` to `true` to identify speakers. Speaker IDs are returned in
1188
- provider metadata. `maxSpeakers` is not supported by MAI-Transcribe-2.
1196
+ provider metadata. Requires MAI-Transcribe-2. `maxSpeakers` is not supported.
1189
1197
 
1190
1198
  - **phraseList** _object_
1191
1199
  Set `phrases` to a list of names and domain terms to bias recognition toward them.
1192
1200
 
1193
1201
  Explicit `api` takes precedence over the model ID. Existing OpenAI transcription
1194
1202
  options remain under `providerOptions.openai`. Speech-only Azure options produce
1195
- warnings when used with the OpenAI API. Unknown or unsupported `providerOptions.azure`
1196
- keys (for example `diarization.maxSpeakers`) are rejected before the request is sent.
1203
+ warnings when used with the OpenAI API. Unknown `providerOptions.azure` keys
1204
+ (for example `diarization.maxSpeakers`) are rejected before the request is sent.
1205
+ Options that a model does not support, such as `timestamps: 'word'` with
1206
+ MAI-Transcribe-1.5, are sent unchanged, and Azure rejects the request with an
1207
+ error that names the option.
1197
1208
 
1198
1209
  Results include transcript text, timed segments, duration, and an ISO-639-1
1199
1210
  language code when the reported phrase locales identify one language. Mixed-language
@@ -1203,9 +1214,9 @@ timing are preserved in `providerMetadata.azure.phrases`; use the exported
1203
1214
  `AzureTranscriptionProviderMetadata` type to access them. Phrase timing is in
1204
1215
  milliseconds in metadata and seconds in normalized `segments`.
1205
1216
 
1206
- MAI-Transcribe-2 is a file transcription model: it accepts WAV, MP3, or FLAC files
1207
- shorter than 2 hours and smaller than 250 MB, and does not support streaming
1208
- transcription. The model is in public preview. See
1217
+ MAI-Transcribe models are file transcription models: they accept WAV, MP3, or FLAC files
1218
+ shorter than 2 hours and smaller than 250 MB, and do not support streaming
1219
+ transcription. The models are in public preview. See
1209
1220
  [Azure's MAI-Transcribe guide](https://learn.microsoft.com/en-us/azure/ai-services/speech-service/mai-transcribe)
1210
1221
  for supported languages and diarization limits.
1211
1222
 
@@ -1279,12 +1290,14 @@ The following provider options are available:
1279
1290
  | `gpt-4o-mini-transcribe` | <Check /> | <Cross /> | <Cross /> | <Cross /> |
1280
1291
  | `gpt-4o-transcribe` | <Check /> | <Cross /> | <Cross /> | <Cross /> |
1281
1292
  | `mai-transcribe-2` | <Check /> | <Check /> | <Check /> | <Check /> |
1293
+ | `mai-transcribe-1.5` | <Check /> | <Check /> | <Check /> | <Check /> |
1282
1294
 
1283
1295
  ## Speech Models
1284
1296
 
1285
- You can create models that call the Azure OpenAI speech API using the `.speech()` factory method.
1297
+ You can create models that call the Azure OpenAI speech API or Azure Speech text to speech using the `.speech()` factory method.
1286
1298
 
1287
- The first argument is your deployment name for the text-to-speech model (e.g., `tts-1`).
1299
+ The first argument is your deployment name for the text-to-speech model (e.g., `tts-1`),
1300
+ or a [MAI-Voice](#mai-voice) model ID.
1288
1301
 
1289
1302
  ```ts
1290
1303
  const model = azure.speech('your-tts-deployment-name');
@@ -1343,3 +1356,75 @@ Azure OpenAI supports TTS models through deployments. The capabilities depend on
1343
1356
  | `tts-1` | <Cross /> |
1344
1357
  | `tts-1-hd` | <Cross /> |
1345
1358
  | `gpt-4o-mini-tts` | <Check /> |
1359
+
1360
+ ### MAI-Voice
1361
+
1362
+ MAI-Voice models are multilingual text-to-speech models from Microsoft AI, served through Azure.
1363
+ The following model IDs use the Azure Speech API:
1364
+
1365
+ | Model ID | Notes |
1366
+ | ------------------- | --------------------------------------------- |
1367
+ | `mai-voice-2-flash` | Low latency, for voice agents and assistants. |
1368
+ | `mai-voice-2` | Highest fidelity, for long-form narration. |
1369
+
1370
+ All other IDs use the OpenAI API by default, including custom deployment names.
1371
+
1372
+ ```ts
1373
+ import { azure, type AzureSpeechModelOptions } from '@ai-sdk/azure';
1374
+ import { generateSpeech } from 'ai';
1375
+
1376
+ const result = await generateSpeech({
1377
+ model: azure.speech('mai-voice-2-flash'),
1378
+ text: 'Thanks for calling! Your order shipped this morning.',
1379
+ voice: 'en-US-Ethan',
1380
+ providerOptions: {
1381
+ azure: { style: 'excited' } satisfies AzureSpeechModelOptions,
1382
+ },
1383
+ });
1384
+ ```
1385
+
1386
+ MAI-Voice models require a Microsoft Foundry (Speech) resource in a region where they are available
1387
+ (see [Speech service regions](https://learn.microsoft.com/en-us/azure/ai-services/speech-service/regions)).
1388
+ They use the same settings as [MAI-Transcribe](#mai-transcribe): `resourceName` (or `AZURE_RESOURCE_NAME`),
1389
+ `apiKey` (or `AZURE_API_KEY`), `tokenProvider`, and `speechBaseURL`.
1390
+
1391
+ - **voice** is a prebuilt voice ID that includes its locale, such as `en-US-Harper`
1392
+ (the default), `de-DE-Mia`, or `es-MX-Valeria`. The voice locale selects the language.
1393
+ Full Azure voice names such as `es-MX-Valeria:MAI-Voice-2` are also accepted. Available
1394
+ voices vary by model; see
1395
+ [Azure's MAI-Voice guide](https://learn.microsoft.com/en-us/azure/ai-services/speech-service/mai-voices).
1396
+ - **language** picks a default voice when `voice` is not set (see the table below). Other
1397
+ languages and `auto` use `en-US-Harper` with a warning. When `voice` is set, its locale
1398
+ selects the language, and a conflicting `language` produces a warning.
1399
+ - **outputFormat** accepts `mp3` (default, 24 kHz), `wav`, `pcm` (headerless 24 kHz, 16-bit, mono), `opus` (Ogg),
1400
+ or any Azure `X-Microsoft-OutputFormat` value such as `audio-48khz-192kbitrate-mono-mp3`.
1401
+ Other values fall back to `mp3` with a warning. Azure labels raw formats such as `pcm` as `audio/basic`.
1402
+ - **speed** is a rate multiplier, for example `0.5` for half speed or `2` for double speed.
1403
+ - `instructions` is not supported and produces a warning.
1404
+
1405
+ | Language | Default voice | Language | Default voice |
1406
+ | -------- | --------------- | -------- | ------------- |
1407
+ | `de` | `de-DE-Mia` | `nl` | `nl-NL-Fleur` |
1408
+ | `en` | `en-US-Harper` | `pt` | `pt-BR-Luana` |
1409
+ | `es` | `es-MX-Valeria` | `ro` | `ro-RO-Elena` |
1410
+ | `fr` | `fr-FR-Soleil` | `ru` | `ru-RU-Masha` |
1411
+ | `hi` | `hi-IN-Kavya` | `th` | `th-TH-Krit` |
1412
+ | `hu` | `hu-HU-Lilla` | `tr` | `tr-TR-Elif` |
1413
+ | `it` | `it-IT-Rosa` | `zh` | `zh-CN-Mei` |
1414
+ | `ko` | `ko-KR-Haena` | | |
1415
+
1416
+ The following options are available through `providerOptions.azure`:
1417
+
1418
+ - **api** _'openai' | 'speech'_
1419
+ Overrides model-based API selection for this request.
1420
+ Set `openai` for an OpenAI deployment named after one of the model IDs above, or `speech` to
1421
+ send another model ID to Speech.
1422
+
1423
+ - **style** _string_
1424
+ Speaking style, such as `excited` or `whispering`. Supported styles vary by voice and model.
1425
+
1426
+ - **styleDegree** _number_
1427
+ Style intensity from 0.01 to 2. Azure defaults to 1. Requires `style`.
1428
+
1429
+ Text is always spoken as plain text; SSML input is not supported.
1430
+ The models are in public preview. AI Gateway forwards these provider options, including `azure.api`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/azure",
3
- "version": "4.0.87",
3
+ "version": "4.0.89",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "sideEffects": false,
@@ -15,6 +15,7 @@ import {
15
15
  type LanguageModelV4,
16
16
  type ProviderV4,
17
17
  type ImageModelV4,
18
+ type SharedV4Warning,
18
19
  type SpeechModelV4,
19
20
  type TranscriptionModelV4,
20
21
  } from '@ai-sdk/provider';
@@ -32,10 +33,15 @@ import {
32
33
  type FetchFunction,
33
34
  } from '@ai-sdk/provider-utils';
34
35
  import { azureOpenaiTools } from './azure-openai-tools';
36
+ import {
37
+ azureSpeechModelOptions,
38
+ getMAIVoiceModel,
39
+ } from './azure-speech-model-options';
40
+ import { AzureSpeechSpeechModel } from './azure-speech-speech-model';
35
41
  import { AzureSpeechTranscriptionModel } from './azure-speech-transcription-model';
36
42
  import {
37
43
  azureTranscriptionModelOptions,
38
- isMAITranscribe2,
44
+ getMAITranscribeModel,
39
45
  } from './azure-transcription-model-options';
40
46
  import { VERSION } from './version';
41
47
 
@@ -98,8 +104,8 @@ export interface AzureOpenAIProvider extends ProviderV4 {
98
104
  imageModel(deploymentId: string): ImageModelV4;
99
105
 
100
106
  /**
101
- * Creates an Azure transcription model. MAI-Transcribe-2 uses the Speech API
102
- * by default; other IDs use OpenAI. Override with providerOptions.azure.api.
107
+ * Creates an Azure transcription model. MAI-Transcribe models use the Speech
108
+ * API by default; other IDs use OpenAI. Override with providerOptions.azure.api.
103
109
  */
104
110
  transcription(deploymentId: string): TranscriptionModelV4;
105
111
 
@@ -109,10 +115,16 @@ export interface AzureOpenAIProvider extends ProviderV4 {
109
115
  transcriptionModel(deploymentId: string): TranscriptionModelV4;
110
116
 
111
117
  /**
112
- * Creates an Azure OpenAI model for speech generation.
118
+ * Creates an Azure speech generation model. MAI-Voice models use the Speech
119
+ * API by default; other IDs use OpenAI. Override with providerOptions.azure.api.
113
120
  */
114
121
  speech(deploymentId: string): SpeechModelV4;
115
122
 
123
+ /**
124
+ * Creates an Azure speech generation model. Alias of `speech`.
125
+ */
126
+ speechModel(deploymentId: string): SpeechModelV4;
127
+
116
128
  /**
117
129
  * AzureOpenAI-specific tools.
118
130
  */
@@ -175,8 +187,9 @@ export interface AzureOpenAIProviderSettings {
175
187
  useDeploymentBasedUrls?: boolean;
176
188
 
177
189
  /**
178
- * URL prefix for Azure Speech transcription (MAI-Transcribe-2), e.g. a
179
- * regional endpoint like `https://eastus.api.cognitive.microsoft.com`.
190
+ * URL prefix for Azure Speech (MAI-Transcribe transcription and MAI-Voice
191
+ * speech), e.g. a regional endpoint like
192
+ * `https://eastus.api.cognitive.microsoft.com`.
180
193
  * Defaults to `https://{resourceName}.cognitiveservices.azure.com`.
181
194
  * Speech requests do not use `baseURL` or `apiVersion`.
182
195
  */
@@ -378,6 +391,10 @@ export function createAzure(
378
391
  },
379
392
  });
380
393
 
394
+ const speechBaseURL = () =>
395
+ withoutTrailingSlash(options.speechBaseURL) ??
396
+ `https://${getResourceName()}.cognitiveservices.azure.com`;
397
+
381
398
  const createTranscriptionModel = (modelId: string) =>
382
399
  new AzureTranscriptionModel(
383
400
  modelId,
@@ -390,22 +407,28 @@ export function createAzure(
390
407
  }),
391
408
  new AzureSpeechTranscriptionModel(modelId, {
392
409
  url: () =>
393
- `${
394
- withoutTrailingSlash(options.speechBaseURL) ??
395
- `https://${getResourceName()}.cognitiveservices.azure.com`
396
- }/speechtotext/transcriptions:transcribe?api-version=2025-10-15`,
410
+ `${speechBaseURL()}/speechtotext/transcriptions:transcribe?api-version=2025-10-15`,
397
411
  headers: () => getHeaders('speech'),
398
412
  fetch,
399
413
  }),
400
414
  );
401
415
 
402
416
  const createSpeechModel = (modelId: string) =>
403
- new OpenAISpeechModel(modelId, {
404
- provider: 'azure.speech',
405
- url,
406
- headers: getHeaders,
407
- fetch,
408
- });
417
+ new AzureSpeechModel(
418
+ modelId,
419
+ options,
420
+ new OpenAISpeechModel(modelId, {
421
+ provider: 'azure.speech',
422
+ url,
423
+ headers: getHeaders,
424
+ fetch,
425
+ }),
426
+ new AzureSpeechSpeechModel(modelId, {
427
+ url: () => `${speechBaseURL()}/tts/cognitiveservices/v1`,
428
+ headers: () => getHeaders('speech'),
429
+ fetch,
430
+ }),
431
+ );
409
432
 
410
433
  const provider = function (deploymentId: string) {
411
434
  if (new.target) {
@@ -432,6 +455,7 @@ export function createAzure(
432
455
  provider.transcription = createTranscriptionModel;
433
456
  provider.transcriptionModel = createTranscriptionModel;
434
457
  provider.speech = createSpeechModel;
458
+ provider.speechModel = createSpeechModel;
435
459
  provider.tools = azureOpenaiTools;
436
460
  return provider;
437
461
  }
@@ -514,7 +538,67 @@ class AzureTranscriptionModel implements TranscriptionModelV4 {
514
538
  return {
515
539
  ...options,
516
540
  api:
517
- options?.api ?? (isMAITranscribe2(this.modelId) ? 'speech' : 'openai'),
541
+ options?.api ??
542
+ (getMAITranscribeModel(this.modelId) ? 'speech' : 'openai'),
543
+ };
544
+ }
545
+ }
546
+
547
+ // Resolves the API per request: providerOptions also reach this model via Gateway.
548
+ class AzureSpeechModel implements SpeechModelV4 {
549
+ readonly specificationVersion = 'v4';
550
+ readonly provider = 'azure.speech';
551
+
552
+ constructor(
553
+ readonly modelId: string,
554
+ private readonly config: AzureOpenAIProviderSettings,
555
+ private readonly openai: OpenAISpeechModel,
556
+ private readonly speech: AzureSpeechSpeechModel,
557
+ ) {}
558
+
559
+ static [WORKFLOW_SERIALIZE](model: AzureSpeechModel) {
560
+ return serializeModelOptions({
561
+ modelId: model.modelId,
562
+ config: model.config,
563
+ });
564
+ }
565
+
566
+ static [WORKFLOW_DESERIALIZE](options: {
567
+ modelId: string;
568
+ config: AzureOpenAIProviderSettings;
569
+ }) {
570
+ return createAzure(options.config).speech(options.modelId);
571
+ }
572
+
573
+ async doGenerate(options: Parameters<SpeechModelV4['doGenerate']>[0]) {
574
+ const { api, ...speechOptions } =
575
+ (await parseProviderOptions({
576
+ provider: 'azure',
577
+ providerOptions: options.providerOptions,
578
+ schema: azureSpeechModelOptions,
579
+ })) ?? {};
580
+ if (
581
+ (api ?? (getMAIVoiceModel(this.modelId) ? 'speech' : 'openai')) ===
582
+ 'speech'
583
+ ) {
584
+ return this.speech.doGenerate(options, speechOptions);
585
+ }
586
+
587
+ const result = await this.openai.doGenerate(options);
588
+ return {
589
+ ...result,
590
+ warnings: [
591
+ ...result.warnings,
592
+ ...Object.entries(speechOptions)
593
+ .filter(([, value]) => value !== undefined)
594
+ .map(
595
+ ([key]): SharedV4Warning => ({
596
+ type: 'unsupported',
597
+ feature: `providerOptions.azure.${key}`,
598
+ details: 'This option requires the Azure Speech API.',
599
+ }),
600
+ ),
601
+ ],
518
602
  };
519
603
  }
520
604
  }
@@ -0,0 +1,33 @@
1
+ import {
2
+ lazySchema,
3
+ zodSchema,
4
+ type InferSchema,
5
+ } from '@ai-sdk/provider-utils';
6
+ import { z } from 'zod/v4';
7
+ import { azureSpeechSpeechModelOptionsShape } from './azure-speech-speech-model-options';
8
+
9
+ export const azureSpeechModelOptions = lazySchema(() =>
10
+ zodSchema(
11
+ z.strictObject({
12
+ /**
13
+ * API to use. Defaults to Speech for MAI-Voice models, OpenAI otherwise.
14
+ */
15
+ api: z.enum(['openai', 'speech']).optional(),
16
+ ...azureSpeechSpeechModelOptionsShape(),
17
+ }),
18
+ ),
19
+ );
20
+
21
+ export type AzureSpeechModelOptions = InferSchema<
22
+ typeof azureSpeechModelOptions
23
+ >;
24
+
25
+ // Azure voice-name suffixes by lowercase model ID.
26
+ const maiVoiceModels = new Map([
27
+ ['mai-voice-2-flash', 'MAI-Voice-2-Flash'],
28
+ ['mai-voice-2', 'MAI-Voice-2'],
29
+ ]);
30
+
31
+ export function getMAIVoiceModel(modelId: string) {
32
+ return maiVoiceModels.get(modelId.toLowerCase());
33
+ }
@@ -0,0 +1,27 @@
1
+ import {
2
+ lazySchema,
3
+ zodSchema,
4
+ type InferSchema,
5
+ } from '@ai-sdk/provider-utils';
6
+ import { z } from 'zod/v4';
7
+
8
+ export const azureSpeechSpeechModelOptionsShape = () => ({
9
+ /**
10
+ * Speaking style applied with `mstts:express-as`, e.g. `excited` or
11
+ * `whispering`. Supported styles vary by voice.
12
+ */
13
+ style: z.string().min(1).optional(),
14
+
15
+ /**
16
+ * Intensity of `style`, from 0.01 to 2. Azure defaults to 1.
17
+ */
18
+ styleDegree: z.number().min(0.01).max(2).optional(),
19
+ });
20
+
21
+ export const azureSpeechSpeechModelOptions = lazySchema(() =>
22
+ zodSchema(z.strictObject(azureSpeechSpeechModelOptionsShape())),
23
+ );
24
+
25
+ export type AzureSpeechModelSpeechOptions = InferSchema<
26
+ typeof azureSpeechSpeechModelOptions
27
+ >;