@ai-sdk/azure 4.0.82 → 4.0.83

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 CHANGED
@@ -1,5 +1,27 @@
1
1
  # @ai-sdk/azure
2
2
 
3
+ ## 4.0.83
4
+
5
+ ### Patch Changes
6
+
7
+ - 354af1c: Add MAI-Transcribe-2 file transcription through `azure.transcription()` using the Azure Speech API, with diarization, word/segment timestamps, transcript styles, locale forcing, and phrase lists. Select the API with `providerOptions.azure.api` to override model-based routing, add a `speechBaseURL` setting for the Speech endpoint, and add `azure.transcriptionModel()` as an alias of `azure.transcription()`.
8
+ - 525efc5: feat(provider): advertise image model file and mask input support
9
+
10
+ Use confirmed model IDs for capability declarations so unrecognized model names
11
+ remain unknown. Include Together AI FLUX.2 Pro and Flex single-image editing, and
12
+ allow asynchronous capability lookups and middleware overrides to resolve to
13
+ unknown.
14
+
15
+ Advertise QuiverAI Arrow 2 and Arrow 2 Telos file-input support, and mark Together
16
+ AI Gemini image inputs unsupported by the current single-image request mapping.
17
+
18
+ - Updated dependencies [e3605f6]
19
+ - Updated dependencies [525efc5]
20
+ - @ai-sdk/provider-utils@5.0.50
21
+ - @ai-sdk/openai@4.0.79
22
+ - @ai-sdk/deepseek@3.0.55
23
+ - @ai-sdk/provider@4.0.19
24
+
3
25
  ## 4.0.82
4
26
 
5
27
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import { DeepSeekLanguageModelChatOptions } from '@ai-sdk/deepseek';
2
2
  export { OpenAILanguageModelChatOptions as OpenAIChatLanguageModelOptions, OpenAILanguageModelChatOptions, OpenAILanguageModelResponsesOptions, OpenAILanguageModelResponsesOptions as OpenAIResponsesProviderOptions, OpenAIResponsesSystemMessageOptions } from '@ai-sdk/openai';
3
3
  import { ProviderV4, LanguageModelV4, EmbeddingModelV4, ImageModelV4, TranscriptionModelV4, SpeechModelV4 } from '@ai-sdk/provider';
4
- import { FetchFunction } from '@ai-sdk/provider-utils';
4
+ import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
5
+ import { FetchFunction, InferSchema } from '@ai-sdk/provider-utils';
5
6
  import { codeInterpreter, fileSearch, imageGeneration, webSearch, webSearchPreview, ResponsesProviderMetadata, ResponsesReasoningProviderMetadata, ResponsesSourceDocumentProviderMetadata, ResponsesTextProviderMetadata } from '@ai-sdk/openai/internal';
6
7
 
7
8
  declare const azureOpenaiTools: {
@@ -59,9 +60,14 @@ interface AzureOpenAIProvider extends ProviderV4 {
59
60
  */
60
61
  imageModel(deploymentId: string): ImageModelV4;
61
62
  /**
62
- * Creates an Azure OpenAI model for audio transcription.
63
+ * Creates an Azure transcription model. MAI-Transcribe-2 uses the Speech API
64
+ * by default; other IDs use OpenAI. Override with providerOptions.azure.api.
63
65
  */
64
66
  transcription(deploymentId: string): TranscriptionModelV4;
67
+ /**
68
+ * Creates an Azure transcription model. Alias of `transcription`.
69
+ */
70
+ transcriptionModel(deploymentId: string): TranscriptionModelV4;
65
71
  /**
66
72
  * Creates an Azure OpenAI model for speech generation.
67
73
  */
@@ -117,6 +123,13 @@ interface AzureOpenAIProviderSettings {
117
123
  * `{baseURL}/v1{path}?api-version={apiVersion}`.
118
124
  */
119
125
  useDeploymentBasedUrls?: boolean;
126
+ /**
127
+ * URL prefix for Azure Speech transcription (MAI-Transcribe-2), e.g. a
128
+ * regional endpoint like `https://eastus.api.cognitive.microsoft.com`.
129
+ * Defaults to `https://{resourceName}.cognitiveservices.azure.com`.
130
+ * Speech requests do not use `baseURL` or `apiVersion`.
131
+ */
132
+ speechBaseURL?: string;
120
133
  }
121
134
  /**
122
135
  * Create an Azure OpenAI provider instance.
@@ -142,8 +155,40 @@ type AzureResponsesSourceDocumentProviderMetadata = {
142
155
 
143
156
  declare const VERSION: string;
144
157
 
158
+ declare const azureTranscriptionModelOptions: _ai_sdk_provider_utils.LazySchema<{
159
+ timestamps?: "word" | "segment" | "none" | undefined;
160
+ transcribeStyle?: "verbatim" | "clean" | undefined;
161
+ locales?: string[] | undefined;
162
+ diarization?: {
163
+ enabled: boolean;
164
+ } | undefined;
165
+ phraseList?: {
166
+ phrases: string[];
167
+ } | undefined;
168
+ api?: "openai" | "speech" | undefined;
169
+ }>;
170
+ type AzureTranscriptionModelOptions = InferSchema<typeof azureTranscriptionModelOptions>;
171
+
172
+ type AzureTranscriptionProviderMetadata = {
173
+ azure: {
174
+ phrases: Array<{
175
+ text: string;
176
+ offsetMilliseconds?: number | null;
177
+ durationMilliseconds?: number | null;
178
+ locale?: string | null;
179
+ speaker?: number | null;
180
+ confidence?: number | null;
181
+ words?: Array<{
182
+ text: string;
183
+ offsetMilliseconds?: number | null;
184
+ durationMilliseconds?: number | null;
185
+ }> | null;
186
+ }>;
187
+ };
188
+ };
189
+
145
190
  type AzureDeepSeekLanguageModelOptions = Omit<DeepSeekLanguageModelChatOptions, 'thinking'>;
146
191
  /** @deprecated Use `AzureDeepSeekLanguageModelOptions` instead. */
147
192
  type AzureDeepSeekChatOptions = AzureDeepSeekLanguageModelOptions;
148
193
 
149
- export { type AzureDeepSeekChatOptions, type AzureDeepSeekLanguageModelOptions, type AzureOpenAIProvider, type AzureOpenAIProviderSettings, type AzureResponsesProviderMetadata, type AzureResponsesReasoningProviderMetadata, type AzureResponsesSourceDocumentProviderMetadata, type AzureResponsesTextProviderMetadata, VERSION, azure, createAzure };
194
+ export { type AzureDeepSeekChatOptions, type AzureDeepSeekLanguageModelOptions, type AzureOpenAIProvider, type AzureOpenAIProviderSettings, type AzureResponsesProviderMetadata, type AzureResponsesReasoningProviderMetadata, type AzureResponsesSourceDocumentProviderMetadata, type AzureResponsesTextProviderMetadata, type AzureTranscriptionModelOptions, type AzureTranscriptionProviderMetadata, VERSION, azure, createAzure };
package/dist/index.js CHANGED
@@ -10,12 +10,17 @@ import {
10
10
  } from "@ai-sdk/openai/internal";
11
11
  import { DeepSeekChatLanguageModel } from "@ai-sdk/deepseek/internal";
12
12
  import {
13
- InvalidArgumentError
13
+ InvalidArgumentError,
14
+ UnsupportedFunctionalityError
14
15
  } from "@ai-sdk/provider";
15
16
  import {
16
17
  loadApiKey,
17
18
  loadSetting,
18
19
  normalizeHeaders,
20
+ parseProviderOptions,
21
+ serializeModelOptions,
22
+ WORKFLOW_DESERIALIZE,
23
+ WORKFLOW_SERIALIZE,
19
24
  withoutTrailingSlash,
20
25
  withUserAgentSuffix
21
26
  } from "@ai-sdk/provider-utils";
@@ -36,8 +41,185 @@ var azureOpenaiTools = {
36
41
  webSearchPreview
37
42
  };
38
43
 
44
+ // src/azure-speech-transcription-model.ts
45
+ import {
46
+ combineHeaders,
47
+ convertBase64ToUint8Array,
48
+ createJsonErrorResponseHandler,
49
+ createJsonResponseHandler,
50
+ mediaTypeToExtension,
51
+ postFormDataToApi
52
+ } from "@ai-sdk/provider-utils";
53
+ import { z as z3 } from "zod/v4";
54
+
55
+ // src/azure-transcription-model-options.ts
56
+ import {
57
+ lazySchema as lazySchema2,
58
+ zodSchema as zodSchema2
59
+ } from "@ai-sdk/provider-utils";
60
+ import { z as z2 } from "zod/v4";
61
+
62
+ // src/azure-speech-transcription-model-options.ts
63
+ import {
64
+ lazySchema,
65
+ zodSchema
66
+ } from "@ai-sdk/provider-utils";
67
+ import { z } from "zod/v4";
68
+ var azureSpeechTranscriptionModelOptionsShape = () => ({
69
+ /**
70
+ * Timing granularity. Defaults to `segment` so that transcription results
71
+ * include timed segments (Azure's own default is `none`).
72
+ */
73
+ timestamps: z.enum(["word", "segment", "none"]).optional(),
74
+ /**
75
+ * `verbatim` keeps fillers and false starts, `clean` removes them.
76
+ * Azure defaults to `verbatim`.
77
+ */
78
+ transcribeStyle: z.enum(["verbatim", "clean"]).optional(),
79
+ /**
80
+ * Forces a single language, e.g. `['en']`. Omit for automatic language
81
+ * detection and code switching.
82
+ */
83
+ locales: z.array(z.string()).length(1).optional(),
84
+ /**
85
+ * Speaker diarization. Speaker IDs are available in provider metadata.
86
+ */
87
+ diarization: z.strictObject({ enabled: z.boolean() }).optional(),
88
+ /**
89
+ * Keyword biasing for names and domain terminology.
90
+ */
91
+ phraseList: z.strictObject({ phrases: z.array(z.string()) }).optional()
92
+ });
93
+ var azureSpeechTranscriptionModelOptions = lazySchema(
94
+ () => zodSchema(z.strictObject(azureSpeechTranscriptionModelOptionsShape()))
95
+ );
96
+
97
+ // src/azure-transcription-model-options.ts
98
+ var azureTranscriptionModelOptions = lazySchema2(
99
+ () => zodSchema2(
100
+ z2.strictObject({
101
+ /**
102
+ * API to use. Defaults to Speech for MAI-Transcribe-2, OpenAI otherwise.
103
+ */
104
+ api: z2.enum(["openai", "speech"]).optional(),
105
+ ...azureSpeechTranscriptionModelOptionsShape()
106
+ })
107
+ )
108
+ );
109
+ function isMAITranscribe2(modelId) {
110
+ return modelId.toLowerCase() === "mai-transcribe-2";
111
+ }
112
+
113
+ // src/azure-speech-transcription-model.ts
114
+ var AzureSpeechTranscriptionModel = class {
115
+ constructor(modelId, config) {
116
+ this.modelId = modelId;
117
+ this.config = config;
118
+ this.specificationVersion = "v4";
119
+ this.provider = "azure.transcription";
120
+ }
121
+ async doGenerate(options, azureOptions = {}) {
122
+ const timestamp = /* @__PURE__ */ new Date();
123
+ const formData = new FormData();
124
+ formData.append(
125
+ "audio",
126
+ new Blob(
127
+ [
128
+ typeof options.audio === "string" ? convertBase64ToUint8Array(options.audio) : options.audio
129
+ ],
130
+ { type: options.mediaType }
131
+ ),
132
+ `audio.${mediaTypeToExtension(options.mediaType)}`
133
+ );
134
+ formData.append(
135
+ "definition",
136
+ JSON.stringify({
137
+ enhancedMode: {
138
+ enabled: true,
139
+ model: isMAITranscribe2(this.modelId) ? "MAI-Transcribe-2" : this.modelId,
140
+ modelOptions: {
141
+ timestamps: azureOptions.timestamps ?? "segment",
142
+ transcribeStyle: azureOptions.transcribeStyle
143
+ }
144
+ },
145
+ locales: azureOptions.locales,
146
+ diarization: azureOptions.diarization,
147
+ phraseList: azureOptions.phraseList
148
+ })
149
+ );
150
+ const { value, rawValue, responseHeaders } = await postFormDataToApi({
151
+ url: this.config.url(),
152
+ headers: combineHeaders(this.config.headers(), options.headers),
153
+ formData,
154
+ abortSignal: options.abortSignal,
155
+ fetch: this.config.fetch,
156
+ failedResponseHandler: createJsonErrorResponseHandler({
157
+ errorSchema: z3.union([
158
+ z3.object({ error: z3.object({ message: z3.string() }) }),
159
+ z3.object({ message: z3.string() })
160
+ ]),
161
+ errorToMessage: (data) => "error" in data ? data.error.message : data.message
162
+ }),
163
+ successfulResponseHandler: createJsonResponseHandler(responseSchema)
164
+ });
165
+ const phrases = value.phrases ?? [];
166
+ const languages = new Set(
167
+ phrases.flatMap(
168
+ (phrase) => phrase.locale ? [phrase.locale.split("-")[0].toLowerCase()] : []
169
+ )
170
+ );
171
+ const [language] = languages;
172
+ const reportedLanguage = languages.size === 1 && /^[a-z]{2}$/.test(language) ? language : void 0;
173
+ return {
174
+ text: value.combinedPhrases.map((phrase) => phrase.text).join(" "),
175
+ segments: phrases.flatMap(
176
+ (phrase) => phrase.offsetMilliseconds != null && phrase.durationMilliseconds != null ? [
177
+ {
178
+ text: phrase.text,
179
+ startSecond: phrase.offsetMilliseconds / 1e3,
180
+ endSecond: (phrase.offsetMilliseconds + phrase.durationMilliseconds) / 1e3
181
+ }
182
+ ] : []
183
+ ),
184
+ language: reportedLanguage,
185
+ durationInSeconds: value.durationMilliseconds != null ? value.durationMilliseconds / 1e3 : void 0,
186
+ warnings: [],
187
+ providerMetadata: {
188
+ azure: { phrases }
189
+ },
190
+ response: {
191
+ timestamp,
192
+ modelId: this.modelId,
193
+ headers: responseHeaders,
194
+ body: rawValue
195
+ }
196
+ };
197
+ }
198
+ };
199
+ var responseSchema = z3.object({
200
+ combinedPhrases: z3.array(z3.object({ text: z3.string() })),
201
+ durationMilliseconds: z3.number().nullish(),
202
+ phrases: z3.array(
203
+ z3.object({
204
+ text: z3.string(),
205
+ offsetMilliseconds: z3.number().nullish(),
206
+ durationMilliseconds: z3.number().nullish(),
207
+ locale: z3.string().nullish(),
208
+ speaker: z3.number().nullish(),
209
+ confidence: z3.number().nullish(),
210
+ words: z3.array(
211
+ z3.object({
212
+ text: z3.string(),
213
+ offsetMilliseconds: z3.number().nullish(),
214
+ durationMilliseconds: z3.number().nullish()
215
+ })
216
+ ).nullish()
217
+ })
218
+ ).nullish()
219
+ });
220
+
39
221
  // src/version.ts
40
- var VERSION = true ? "4.0.82" : "0.0.0-test";
222
+ var VERSION = true ? "4.0.83" : "0.0.0-test";
41
223
 
42
224
  // src/azure-openai-provider.ts
43
225
  function getAzureOpenAIBaseURLInfo(baseURL) {
@@ -66,12 +248,12 @@ function createAzure(options = {}) {
66
248
  message: "Both apiKey and tokenProvider were provided. Please use only one authentication method."
67
249
  });
68
250
  }
69
- const getHeaders = () => {
251
+ const getHeaders = (api = "openai") => {
70
252
  const authHeaders = tokenProvider ? {} : {
71
- "api-key": loadApiKey({
253
+ [api === "speech" ? "Ocp-Apim-Subscription-Key" : "api-key"]: loadApiKey({
72
254
  apiKey: options.apiKey,
73
255
  environmentVariableName: "AZURE_API_KEY",
74
- description: "Azure OpenAI"
256
+ description: api === "speech" ? "Azure Speech" : "Azure OpenAI"
75
257
  })
76
258
  };
77
259
  return withUserAgentSuffix(
@@ -162,14 +344,29 @@ function createAzure(options = {}) {
162
344
  provider: "azure.image",
163
345
  url,
164
346
  headers: getHeaders,
165
- fetch
166
- });
167
- const createTranscriptionModel = (modelId) => new OpenAITranscriptionModel(modelId, {
168
- provider: "azure.transcription",
169
- url,
170
- headers: getHeaders,
171
- fetch
347
+ fetch,
348
+ // Azure model IDs are user-defined deployment names, so OpenAI model
349
+ // family capabilities cannot be inferred from them.
350
+ imageInputCapabilities: {
351
+ supportsFileInputs: void 0,
352
+ supportsMaskInputs: void 0
353
+ }
172
354
  });
355
+ const createTranscriptionModel = (modelId) => new AzureTranscriptionModel(
356
+ modelId,
357
+ options,
358
+ new OpenAITranscriptionModel(modelId, {
359
+ provider: "azure.transcription",
360
+ url,
361
+ headers: getHeaders,
362
+ fetch
363
+ }),
364
+ new AzureSpeechTranscriptionModel(modelId, {
365
+ url: () => `${withoutTrailingSlash(options.speechBaseURL) ?? `https://${getResourceName()}.cognitiveservices.azure.com`}/speechtotext/transcriptions:transcribe?api-version=2025-10-15`,
366
+ headers: () => getHeaders("speech"),
367
+ fetch
368
+ })
369
+ );
173
370
  const createSpeechModel = (modelId) => new OpenAISpeechModel(modelId, {
174
371
  provider: "azure.speech",
175
372
  url,
@@ -197,11 +394,71 @@ function createAzure(options = {}) {
197
394
  provider.imageModel = createImageModel;
198
395
  provider.responses = createResponsesModel;
199
396
  provider.transcription = createTranscriptionModel;
397
+ provider.transcriptionModel = createTranscriptionModel;
200
398
  provider.speech = createSpeechModel;
201
399
  provider.tools = azureOpenaiTools;
202
400
  return provider;
203
401
  }
204
402
  var azure = createAzure();
403
+ var AzureTranscriptionModel = class {
404
+ constructor(modelId, config, openai, speech) {
405
+ this.modelId = modelId;
406
+ this.config = config;
407
+ this.openai = openai;
408
+ this.speech = speech;
409
+ this.specificationVersion = "v4";
410
+ this.provider = "azure.transcription";
411
+ }
412
+ static [WORKFLOW_SERIALIZE](model) {
413
+ return serializeModelOptions({
414
+ modelId: model.modelId,
415
+ config: model.config
416
+ });
417
+ }
418
+ static [WORKFLOW_DESERIALIZE](options) {
419
+ return createAzure(options.config).transcription(options.modelId);
420
+ }
421
+ async doGenerate(options) {
422
+ const { api, ...speechOptions } = await this.getOptions(
423
+ options.providerOptions
424
+ );
425
+ if (api === "speech") {
426
+ return this.speech.doGenerate(options, speechOptions);
427
+ }
428
+ const result = await this.openai.doGenerate(options);
429
+ return {
430
+ ...result,
431
+ warnings: [
432
+ ...result.warnings,
433
+ ...Object.keys(speechOptions).map((key) => ({
434
+ type: "unsupported",
435
+ feature: `providerOptions.azure.${key}`,
436
+ details: "This option requires the Azure Speech API."
437
+ }))
438
+ ]
439
+ };
440
+ }
441
+ async doStream(options) {
442
+ const { api } = await this.getOptions(options.providerOptions);
443
+ if (api === "speech") {
444
+ throw new UnsupportedFunctionalityError({
445
+ functionality: "streaming transcription with the Azure Speech API"
446
+ });
447
+ }
448
+ return this.openai.doStream(options);
449
+ }
450
+ async getOptions(providerOptions) {
451
+ const options = await parseProviderOptions({
452
+ provider: "azure",
453
+ providerOptions,
454
+ schema: azureTranscriptionModelOptions
455
+ });
456
+ return {
457
+ ...options,
458
+ api: options?.api ?? (isMAITranscribe2(this.modelId) ? "speech" : "openai")
459
+ };
460
+ }
461
+ };
205
462
  export {
206
463
  VERSION,
207
464
  azure,
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/azure-openai-provider.ts","../src/azure-openai-tools.ts","../src/version.ts"],"sourcesContent":["import {\n OpenAIChatLanguageModel,\n OpenAICompletionLanguageModel,\n OpenAIEmbeddingModel,\n OpenAIImageModel,\n OpenAIResponsesLanguageModel,\n OpenAISpeechModel,\n OpenAITranscriptionModel,\n} from '@ai-sdk/openai/internal';\nimport { DeepSeekChatLanguageModel } from '@ai-sdk/deepseek/internal';\nimport {\n InvalidArgumentError,\n type EmbeddingModelV4,\n type LanguageModelV4,\n type ProviderV4,\n type ImageModelV4,\n type SpeechModelV4,\n type TranscriptionModelV4,\n} from '@ai-sdk/provider';\nimport {\n loadApiKey,\n loadSetting,\n normalizeHeaders,\n withoutTrailingSlash,\n withUserAgentSuffix,\n type FetchFunction,\n} from '@ai-sdk/provider-utils';\nimport { azureOpenaiTools } from './azure-openai-tools';\nimport { VERSION } from './version';\n\nexport interface AzureOpenAIProvider extends ProviderV4 {\n (deploymentId: string): LanguageModelV4;\n\n /**\n * Creates an Azure OpenAI responses API model for text generation.\n */\n languageModel(deploymentId: string): LanguageModelV4;\n\n /**\n * Creates an Azure OpenAI chat model for text generation.\n */\n chat(deploymentId: string): LanguageModelV4;\n\n /**\n * Creates an Azure-hosted DeepSeek chat model for text generation.\n */\n deepseek(deploymentId: string): LanguageModelV4;\n\n /**\n * Creates an Azure OpenAI responses API model for text generation.\n */\n responses(deploymentId: string): LanguageModelV4;\n\n /**\n * Creates an Azure OpenAI completion model for text generation.\n */\n completion(deploymentId: string): LanguageModelV4;\n\n /**\n * Creates an Azure OpenAI model for text embeddings.\n */\n embedding(deploymentId: string): EmbeddingModelV4;\n\n /**\n * Creates an Azure OpenAI model for text embeddings.\n */\n embeddingModel(deploymentId: string): EmbeddingModelV4;\n\n /**\n * @deprecated Use `embedding` instead.\n */\n textEmbedding(deploymentId: string): EmbeddingModelV4;\n\n /**\n * @deprecated Use `embeddingModel` instead.\n */\n textEmbeddingModel(deploymentId: string): EmbeddingModelV4;\n\n /**\n * Creates an Azure OpenAI DALL-E model for image generation.\n */\n image(deploymentId: string): ImageModelV4;\n\n /**\n * Creates an Azure OpenAI DALL-E model for image generation.\n */\n imageModel(deploymentId: string): ImageModelV4;\n\n /**\n * Creates an Azure OpenAI model for audio transcription.\n */\n transcription(deploymentId: string): TranscriptionModelV4;\n\n /**\n * Creates an Azure OpenAI model for speech generation.\n */\n speech(deploymentId: string): SpeechModelV4;\n\n /**\n * AzureOpenAI-specific tools.\n */\n tools: typeof azureOpenaiTools;\n}\n\nexport interface AzureOpenAIProviderSettings {\n /**\n * Name of the Azure OpenAI resource. Either this or `baseURL` can be used.\n *\n * The resource name is used in the assembled URL: `https://{resourceName}.openai.azure.com/openai/v1{path}`.\n */\n resourceName?: string;\n\n /**\n * Use a different URL prefix for API calls, e.g. to use proxy servers. Either this or `resourceName` can be used.\n * When a baseURL is provided, the resourceName is ignored.\n *\n * With an unversioned Azure OpenAI baseURL, the resolved URL is `{baseURL}/v1{path}`.\n * Azure OpenAI base URLs that already end in `/openai/v1` are used as-is.\n * With a non-Azure custom gateway baseURL, the resolved URL is `{baseURL}{path}`.\n */\n baseURL?: string;\n\n /**\n * API key for authenticating requests.\n */\n apiKey?: string;\n\n /**\n * A function that returns an access token for Microsoft Entra\n * (formerly known as Azure Active Directory), which will be invoked\n * on every request.\n */\n tokenProvider?: (() => Promise<string>) | undefined;\n\n /**\n * Custom headers to include in the requests.\n */\n headers?: Record<string, string>;\n\n /**\n * Custom fetch implementation. You can use it as a middleware to intercept requests,\n * or to provide a custom fetch implementation for e.g. testing.\n */\n fetch?: FetchFunction;\n\n /**\n * Custom api version to use. Defaults to `v1`.\n * Complete v1 base URLs are used as-is.\n */\n apiVersion?: string;\n\n /**\n * Use deployment-based URLs for specific model types. Set to true to use legacy deployment format:\n * `{baseURL}/deployments/{deploymentId}{path}?api-version={apiVersion}` instead of\n * `{baseURL}/v1{path}?api-version={apiVersion}`.\n */\n useDeploymentBasedUrls?: boolean;\n}\n\nfunction getAzureOpenAIBaseURLInfo(baseURL: string | undefined) {\n if (baseURL == null) {\n return {\n isAzureOpenAI: true,\n isFoundryProject: false,\n isVersioned: false,\n };\n }\n\n const url = new URL(baseURL);\n const hostname = url.hostname;\n const isAzureOpenAI =\n hostname.endsWith('.openai.azure.com') ||\n hostname.endsWith('.services.ai.azure.com') ||\n hostname.endsWith('.cognitiveservices.azure.com');\n const pathname = url.pathname.replace(/\\/+$/, '');\n\n return {\n isAzureOpenAI,\n isFoundryProject:\n hostname.endsWith('.services.ai.azure.com') &&\n pathname.startsWith('/api/projects/'),\n isVersioned: isAzureOpenAI && pathname.toLowerCase().endsWith('/openai/v1'),\n };\n}\n\n/**\n * Create an Azure OpenAI provider instance.\n */\nexport function createAzure(\n options: AzureOpenAIProviderSettings = {},\n): AzureOpenAIProvider {\n const tokenProvider = options.tokenProvider;\n\n if (options.apiKey && tokenProvider) {\n throw new InvalidArgumentError({\n argument: 'apiKey/tokenProvider',\n message:\n 'Both apiKey and tokenProvider were provided. Please use only one authentication method.',\n });\n }\n\n const getHeaders = () => {\n const authHeaders = tokenProvider\n ? {}\n : {\n 'api-key': loadApiKey({\n apiKey: options.apiKey,\n environmentVariableName: 'AZURE_API_KEY',\n description: 'Azure OpenAI',\n }),\n };\n\n return withUserAgentSuffix(\n {\n ...authHeaders,\n ...options.headers,\n },\n `ai-sdk/azure/${VERSION}`,\n );\n };\n\n const fetch: FetchFunction | undefined = tokenProvider\n ? async (input, init) => {\n const headers = normalizeHeaders(init?.headers);\n\n if (headers.authorization == null) {\n headers.authorization = `Bearer ${await tokenProvider()}`;\n }\n\n return (options.fetch ?? globalThis.fetch)(input, {\n ...init,\n headers,\n });\n }\n : options.fetch;\n\n const getResourceName = () =>\n loadSetting({\n settingValue: options.resourceName,\n settingName: 'resourceName',\n environmentVariableName: 'AZURE_RESOURCE_NAME',\n description: 'Azure OpenAI resource name',\n });\n\n const apiVersion = options.apiVersion ?? 'v1';\n const {\n isAzureOpenAI,\n isFoundryProject,\n isVersioned: isAzureOpenAIVersioned,\n } = getAzureOpenAIBaseURLInfo(options.baseURL);\n\n const url = ({ path, modelId }: { path: string; modelId: string }) => {\n const baseUrlPrefix = withoutTrailingSlash(\n options.baseURL ?? `https://${getResourceName()}.openai.azure.com/openai`,\n );\n\n let fullUrl: URL;\n if (options.useDeploymentBasedUrls) {\n // Use deployment-based format for compatibility with certain Azure OpenAI models\n fullUrl = new URL(`${baseUrlPrefix}/deployments/${modelId}${path}`);\n } else if (!isAzureOpenAI || isAzureOpenAIVersioned) {\n // Custom gateways can own Azure routing and versioning themselves.\n // Complete Azure OpenAI v1 URLs also own their versioning.\n fullUrl = new URL(`${baseUrlPrefix}${path}`);\n } else {\n // Use v1 API format - no deployment ID in URL\n fullUrl = new URL(`${baseUrlPrefix}/v1${path}`);\n }\n\n if (\n options.useDeploymentBasedUrls ||\n (isAzureOpenAI && !isAzureOpenAIVersioned && !isFoundryProject)\n ) {\n fullUrl.searchParams.set('api-version', apiVersion);\n }\n\n return fullUrl.toString();\n };\n\n const createChatModel = (deploymentName: string) =>\n new OpenAIChatLanguageModel(deploymentName, {\n provider: 'azure.chat',\n url,\n headers: getHeaders,\n fetch,\n });\n\n const createDeepSeekModel = (deploymentName: string) =>\n new DeepSeekChatLanguageModel(deploymentName, {\n provider: 'azure.deepseek',\n url,\n headers: getHeaders,\n fetch,\n supportsPenaltySampling: true,\n supportsThinking: false,\n // json_object with thinking enabled makes Azure return the JSON in reasoning_content with empty content\n supportsStructuredOutputs: true,\n });\n\n const createCompletionModel = (modelId: string) =>\n new OpenAICompletionLanguageModel(modelId, {\n provider: 'azure.completion',\n url,\n headers: getHeaders,\n fetch,\n });\n\n const createEmbeddingModel = (modelId: string) =>\n new OpenAIEmbeddingModel(modelId, {\n provider: 'azure.embeddings',\n headers: getHeaders,\n url,\n fetch,\n });\n\n const createResponsesModel = (modelId: string) =>\n new OpenAIResponsesLanguageModel(modelId, {\n provider: 'azure.responses',\n url,\n headers: getHeaders,\n fetch,\n explicitMessageItemType: isFoundryProject,\n // Soft-deprecated. TODO: remove in v8\n fileIdPrefixes: ['assistant-'],\n });\n\n const createImageModel = (modelId: string) =>\n new OpenAIImageModel(modelId, {\n provider: 'azure.image',\n url,\n headers: getHeaders,\n fetch,\n });\n\n const createTranscriptionModel = (modelId: string) =>\n new OpenAITranscriptionModel(modelId, {\n provider: 'azure.transcription',\n url,\n headers: getHeaders,\n fetch,\n });\n\n const createSpeechModel = (modelId: string) =>\n new OpenAISpeechModel(modelId, {\n provider: 'azure.speech',\n url,\n headers: getHeaders,\n fetch,\n });\n\n const provider = function (deploymentId: string) {\n if (new.target) {\n throw new Error(\n 'The Azure OpenAI model function cannot be called with the new keyword.',\n );\n }\n\n return createResponsesModel(deploymentId);\n };\n\n provider.specificationVersion = 'v4' as const;\n provider.languageModel = createResponsesModel;\n provider.chat = createChatModel;\n provider.deepseek = createDeepSeekModel;\n provider.completion = createCompletionModel;\n provider.embedding = createEmbeddingModel;\n provider.embeddingModel = createEmbeddingModel;\n provider.textEmbedding = createEmbeddingModel;\n provider.textEmbeddingModel = createEmbeddingModel;\n provider.image = createImageModel;\n provider.imageModel = createImageModel;\n provider.responses = createResponsesModel;\n provider.transcription = createTranscriptionModel;\n provider.speech = createSpeechModel;\n provider.tools = azureOpenaiTools;\n return provider;\n}\n\n/**\n * Default Azure OpenAI provider instance.\n */\nexport const azure = createAzure();\n","import {\n codeInterpreter,\n fileSearch,\n imageGeneration,\n webSearch,\n webSearchPreview,\n} from '@ai-sdk/openai/internal';\n\nexport const azureOpenaiTools: {\n codeInterpreter: typeof codeInterpreter;\n fileSearch: typeof fileSearch;\n imageGeneration: typeof imageGeneration;\n webSearch: typeof webSearch;\n webSearchPreview: typeof webSearchPreview;\n} = {\n codeInterpreter,\n fileSearch,\n imageGeneration,\n webSearch,\n webSearchPreview,\n};\n","// Version string of this package injected at build time.\ndeclare const __PACKAGE_VERSION__: string | undefined;\nexport const VERSION: string =\n typeof __PACKAGE_VERSION__ !== 'undefined'\n ? __PACKAGE_VERSION__\n : '0.0.0-test';\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,iCAAiC;AAC1C;AAAA,EACE;AAAA,OAOK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;;;AC1BP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEA,IAAM,mBAMT;AAAA,EACF;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;;;AClBO,IAAM,UACX,OACI,WACA;;;AF0JN,SAAS,0BAA0B,SAA6B;AAC9D,MAAI,WAAW,MAAM;AACnB,WAAO;AAAA,MACL,eAAe;AAAA,MACf,kBAAkB;AAAA,MAClB,aAAa;AAAA,IACf;AAAA,EACF;AAEA,QAAM,MAAM,IAAI,IAAI,OAAO;AAC3B,QAAM,WAAW,IAAI;AACrB,QAAM,gBACJ,SAAS,SAAS,mBAAmB,KACrC,SAAS,SAAS,wBAAwB,KAC1C,SAAS,SAAS,8BAA8B;AAClD,QAAM,WAAW,IAAI,SAAS,QAAQ,QAAQ,EAAE;AAEhD,SAAO;AAAA,IACL;AAAA,IACA,k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AAgB,CAAC,YAAY;AAAA,EAC/B,CAAC;AAEH,QAAM,mBAAmB,CAAC,YACxB,IAAI,iBAAiB,SAAS;AAAA,IAC5B,UAAU;AAAA,IACV;AAAA,IACA,SAAS;AAAA,IACT;AAAA,EACF,CAAC;AAEH,QAAM,2BAA2B,CAAC,YAChC,IAAI,yBAAyB,SAAS;AAAA,IACpC,UAAU;AAAA,IACV;AAAA,IACA,SAAS;AAAA,IACT;AAAA,EACF,CAAC;AAEH,QAAM,oBAAoB,CAAC,YACzB,IAAI,kBAAkB,SAAS;AAAA,IAC7B,UAAU;AAAA,IACV;AAAA,IACA,SAAS;AAAA,IACT;AAAA,EACF,CAAC;AAEH,QAAM,WAAW,SAAU,cAAsB;AAC/C,QAAI,YAAY;AACd,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAEA,WAAO,qBAAqB,YAAY;AAAA,EAC1C;AAEA,WAAS,uBAAuB;AAChC,WAAS,gBAAgB;AACzB,WAAS,OAAO;AAChB,WAAS,WAAW;AACpB,WAAS,aAAa;AACtB,WAAS,YAAY;AACrB,WAAS,iBAAiB;AAC1B,WAAS,gBAAgB;AACzB,WAAS,qBAAqB;AAC9B,WAAS,QAAQ;AACjB,WAAS,aAAa;AACtB,WAAS,YAAY;AACrB,WAAS,gBAAgB;AACzB,WAAS,SAAS;AAClB,WAAS,QAAQ;AACjB,SAAO;AACT;AAKO,IAAM,QAAQ,YAAY;","names":[]}
1
+ {"version":3,"sources":["../src/azure-openai-provider.ts","../src/azure-openai-tools.ts","../src/azure-speech-transcription-model.ts","../src/azure-transcription-model-options.ts","../src/azure-speech-transcription-model-options.ts","../src/version.ts"],"sourcesContent":["import {\n OpenAIChatLanguageModel,\n OpenAICompletionLanguageModel,\n OpenAIEmbeddingModel,\n OpenAIImageModel,\n OpenAIResponsesLanguageModel,\n OpenAISpeechModel,\n OpenAITranscriptionModel,\n} from '@ai-sdk/openai/internal';\nimport { DeepSeekChatLanguageModel } from '@ai-sdk/deepseek/internal';\nimport {\n InvalidArgumentError,\n UnsupportedFunctionalityError,\n type EmbeddingModelV4,\n type LanguageModelV4,\n type ProviderV4,\n type ImageModelV4,\n type SpeechModelV4,\n type TranscriptionModelV4,\n} from '@ai-sdk/provider';\nimport {\n loadApiKey,\n loadSetting,\n normalizeHeaders,\n parseProviderOptions,\n serializeModelOptions,\n WORKFLOW_DESERIALIZE,\n WORKFLOW_SERIALIZE,\n withoutTrailingSlash,\n withUserAgentSuffix,\n type FetchFunction,\n} from '@ai-sdk/provider-utils';\nimport { azureOpenaiTools } from './azure-openai-tools';\nimport { AzureSpeechTranscriptionModel } from './azure-speech-transcription-model';\nimport {\n azureTranscriptionModelOptions,\n isMAITranscribe2,\n} from './azure-transcription-model-options';\nimport { VERSION } from './version';\n\nexport interface AzureOpenAIProvider extends ProviderV4 {\n (deploymentId: string): LanguageModelV4;\n\n /**\n * Creates an Azure OpenAI responses API model for text generation.\n */\n languageModel(deploymentId: string): LanguageModelV4;\n\n /**\n * Creates an Azure OpenAI chat model for text generation.\n */\n chat(deploymentId: string): LanguageModelV4;\n\n /**\n * Creates an Azure-hosted DeepSeek chat model for text generation.\n */\n deepseek(deploymentId: string): LanguageModelV4;\n\n /**\n * Creates an Azure OpenAI responses API model for text generation.\n */\n responses(deploymentId: string): LanguageModelV4;\n\n /**\n * Creates an Azure OpenAI completion model for text generation.\n */\n completion(deploymentId: string): LanguageModelV4;\n\n /**\n * Creates an Azure OpenAI model for text embeddings.\n */\n embedding(deploymentId: string): EmbeddingModelV4;\n\n /**\n * Creates an Azure OpenAI model for text embeddings.\n */\n embeddingModel(deploymentId: string): EmbeddingModelV4;\n\n /**\n * @deprecated Use `embedding` instead.\n */\n textEmbedding(deploymentId: string): EmbeddingModelV4;\n\n /**\n * @deprecated Use `embeddingModel` instead.\n */\n textEmbeddingModel(deploymentId: string): EmbeddingModelV4;\n\n /**\n * Creates an Azure OpenAI DALL-E model for image generation.\n */\n image(deploymentId: string): ImageModelV4;\n\n /**\n * Creates an Azure OpenAI DALL-E model for image generation.\n */\n imageModel(deploymentId: string): ImageModelV4;\n\n /**\n * Creates an Azure transcription model. MAI-Transcribe-2 uses the Speech API\n * by default; other IDs use OpenAI. Override with providerOptions.azure.api.\n */\n transcription(deploymentId: string): TranscriptionModelV4;\n\n /**\n * Creates an Azure transcription model. Alias of `transcription`.\n */\n transcriptionModel(deploymentId: string): TranscriptionModelV4;\n\n /**\n * Creates an Azure OpenAI model for speech generation.\n */\n speech(deploymentId: string): SpeechModelV4;\n\n /**\n * AzureOpenAI-specific tools.\n */\n tools: typeof azureOpenaiTools;\n}\n\nexport interface AzureOpenAIProviderSettings {\n /**\n * Name of the Azure OpenAI resource. Either this or `baseURL` can be used.\n *\n * The resource name is used in the assembled URL: `https://{resourceName}.openai.azure.com/openai/v1{path}`.\n */\n resourceName?: string;\n\n /**\n * Use a different URL prefix for API calls, e.g. to use proxy servers. Either this or `resourceName` can be used.\n * When a baseURL is provided, the resourceName is ignored.\n *\n * With an unversioned Azure OpenAI baseURL, the resolved URL is `{baseURL}/v1{path}`.\n * Azure OpenAI base URLs that already end in `/openai/v1` are used as-is.\n * With a non-Azure custom gateway baseURL, the resolved URL is `{baseURL}{path}`.\n */\n baseURL?: string;\n\n /**\n * API key for authenticating requests.\n */\n apiKey?: string;\n\n /**\n * A function that returns an access token for Microsoft Entra\n * (formerly known as Azure Active Directory), which will be invoked\n * on every request.\n */\n tokenProvider?: (() => Promise<string>) | undefined;\n\n /**\n * Custom headers to include in the requests.\n */\n headers?: Record<string, string>;\n\n /**\n * Custom fetch implementation. You can use it as a middleware to intercept requests,\n * or to provide a custom fetch implementation for e.g. testing.\n */\n fetch?: FetchFunction;\n\n /**\n * Custom api version to use. Defaults to `v1`.\n * Complete v1 base URLs are used as-is.\n */\n apiVersion?: string;\n\n /**\n * Use deployment-based URLs for specific model types. Set to true to use legacy deployment format:\n * `{baseURL}/deployments/{deploymentId}{path}?api-version={apiVersion}` instead of\n * `{baseURL}/v1{path}?api-version={apiVersion}`.\n */\n useDeploymentBasedUrls?: boolean;\n\n /**\n * URL prefix for Azure Speech transcription (MAI-Transcribe-2), e.g. a\n * regional endpoint like `https://eastus.api.cognitive.microsoft.com`.\n * Defaults to `https://{resourceName}.cognitiveservices.azure.com`.\n * Speech requests do not use `baseURL` or `apiVersion`.\n */\n speechBaseURL?: string;\n}\n\nfunction getAzureOpenAIBaseURLInfo(baseURL: string | undefined) {\n if (baseURL == null) {\n return {\n isAzureOpenAI: true,\n isFoundryProject: false,\n isVersioned: false,\n };\n }\n\n const url = new URL(baseURL);\n const hostname = url.hostname;\n const isAzureOpenAI =\n hostname.endsWith('.openai.azure.com') ||\n hostname.endsWith('.services.ai.azure.com') ||\n hostname.endsWith('.cognitiveservices.azure.com');\n const pathname = url.pathname.replace(/\\/+$/, '');\n\n return {\n isAzureOpenAI,\n isFoundryProject:\n hostname.endsWith('.services.ai.azure.com') &&\n pathname.startsWith('/api/projects/'),\n isVersioned: isAzureOpenAI && pathname.toLowerCase().endsWith('/openai/v1'),\n };\n}\n\n/**\n * Create an Azure OpenAI provider instance.\n */\nexport function createAzure(\n options: AzureOpenAIProviderSettings = {},\n): AzureOpenAIProvider {\n const tokenProvider = options.tokenProvider;\n\n if (options.apiKey && tokenProvider) {\n throw new InvalidArgumentError({\n argument: 'apiKey/tokenProvider',\n message:\n 'Both apiKey and tokenProvider were provided. Please use only one authentication method.',\n });\n }\n\n const getHeaders = (api: 'openai' | 'speech' = 'openai') => {\n const authHeaders = tokenProvider\n ? {}\n : {\n [api === 'speech' ? 'Ocp-Apim-Subscription-Key' : 'api-key']:\n loadApiKey({\n apiKey: options.apiKey,\n environmentVariableName: 'AZURE_API_KEY',\n description: api === 'speech' ? 'Azure Speech' : 'Azure OpenAI',\n }),\n };\n\n return withUserAgentSuffix(\n {\n ...authHeaders,\n ...options.headers,\n },\n `ai-sdk/azure/${VERSION}`,\n );\n };\n\n const fetch: FetchFunction | undefined = tokenProvider\n ? async (input, init) => {\n const headers = normalizeHeaders(init?.headers);\n\n if (headers.authorization == null) {\n headers.authorization = `Bearer ${await tokenProvider()}`;\n }\n\n return (options.fetch ?? globalThis.fetch)(input, {\n ...init,\n headers,\n });\n }\n : options.fetch;\n\n const getResourceName = () =>\n loadSetting({\n settingValue: options.resourceName,\n settingName: 'resourceName',\n environmentVariableName: 'AZURE_RESOURCE_NAME',\n description: 'Azure OpenAI resource name',\n });\n\n const apiVersion = options.apiVersion ?? 'v1';\n const {\n isAzureOpenAI,\n isFoundryProject,\n isVersioned: isAzureOpenAIVersioned,\n } = getAzureOpenAIBaseURLInfo(options.baseURL);\n\n const url = ({ path, modelId }: { path: string; modelId: string }) => {\n const baseUrlPrefix = withoutTrailingSlash(\n options.baseURL ?? `https://${getResourceName()}.openai.azure.com/openai`,\n );\n\n let fullUrl: URL;\n if (options.useDeploymentBasedUrls) {\n // Use deployment-based format for compatibility with certain Azure OpenAI models\n fullUrl = new URL(`${baseUrlPrefix}/deployments/${modelId}${path}`);\n } else if (!isAzureOpenAI || isAzureOpenAIVersioned) {\n // Custom gateways can own Azure routing and versioning themselves.\n // Complete Azure OpenAI v1 URLs also own their versioning.\n fullUrl = new URL(`${baseUrlPrefix}${path}`);\n } else {\n // Use v1 API format - no deployment ID in URL\n fullUrl = new URL(`${baseUrlPrefix}/v1${path}`);\n }\n\n if (\n options.useDeploymentBasedUrls ||\n (isAzureOpenAI && !isAzureOpenAIVersioned && !isFoundryProject)\n ) {\n fullUrl.searchParams.set('api-version', apiVersion);\n }\n\n return fullUrl.toString();\n };\n\n const createChatModel = (deploymentName: string) =>\n new OpenAIChatLanguageModel(deploymentName, {\n provider: 'azure.chat',\n url,\n headers: getHeaders,\n fetch,\n });\n\n const createDeepSeekModel = (deploymentName: string) =>\n new DeepSeekChatLanguageModel(deploymentName, {\n provider: 'azure.deepseek',\n url,\n headers: getHeaders,\n fetch,\n supportsPenaltySampling: true,\n supportsThinking: false,\n // json_object with thinking enabled makes Azure return the JSON in reasoning_content with empty content\n supportsStructuredOutputs: true,\n });\n\n const createCompletionModel = (modelId: string) =>\n new OpenAICompletionLanguageModel(modelId, {\n provider: 'azure.completion',\n url,\n headers: getHeaders,\n fetch,\n });\n\n const createEmbeddingModel = (modelId: string) =>\n new OpenAIEmbeddingModel(modelId, {\n provider: 'azure.embeddings',\n headers: getHeaders,\n url,\n fetch,\n });\n\n const createResponsesModel = (modelId: string) =>\n new OpenAIResponsesLanguageModel(modelId, {\n provider: 'azure.responses',\n url,\n headers: getHeaders,\n fetch,\n explicitMessageItemType: isFoundryProject,\n // Soft-deprecated. TODO: remove in v8\n fileIdPrefixes: ['assistant-'],\n });\n\n const createImageModel = (modelId: string) =>\n new OpenAIImageModel(modelId, {\n provider: 'azure.image',\n url,\n headers: getHeaders,\n fetch,\n // Azure model IDs are user-defined deployment names, so OpenAI model\n // family capabilities cannot be inferred from them.\n imageInputCapabilities: {\n supportsFileInputs: undefined,\n supportsMaskInputs: undefined,\n },\n });\n\n const createTranscriptionModel = (modelId: string) =>\n new AzureTranscriptionModel(\n modelId,\n options,\n new OpenAITranscriptionModel(modelId, {\n provider: 'azure.transcription',\n url,\n headers: getHeaders,\n fetch,\n }),\n new AzureSpeechTranscriptionModel(modelId, {\n url: () =>\n `${\n withoutTrailingSlash(options.speechBaseURL) ??\n `https://${getResourceName()}.cognitiveservices.azure.com`\n }/speechtotext/transcriptions:transcribe?api-version=2025-10-15`,\n headers: () => getHeaders('speech'),\n fetch,\n }),\n );\n\n const createSpeechModel = (modelId: string) =>\n new OpenAISpeechModel(modelId, {\n provider: 'azure.speech',\n url,\n headers: getHeaders,\n fetch,\n });\n\n const provider = function (deploymentId: string) {\n if (new.target) {\n throw new Error(\n 'The Azure OpenAI model function cannot be called with the new keyword.',\n );\n }\n\n return createResponsesModel(deploymentId);\n };\n\n provider.specificationVersion = 'v4' as const;\n provider.languageModel = createResponsesModel;\n provider.chat = createChatModel;\n provider.deepseek = createDeepSeekModel;\n provider.completion = createCompletionModel;\n provider.embedding = createEmbeddingModel;\n provider.embeddingModel = createEmbeddingModel;\n provider.textEmbedding = createEmbeddingModel;\n provider.textEmbeddingModel = createEmbeddingModel;\n provider.image = createImageModel;\n provider.imageModel = createImageModel;\n provider.responses = createResponsesModel;\n provider.transcription = createTranscriptionModel;\n provider.transcriptionModel = createTranscriptionModel;\n provider.speech = createSpeechModel;\n provider.tools = azureOpenaiTools;\n return provider;\n}\n\n/**\n * Default Azure OpenAI provider instance.\n */\nexport const azure = createAzure();\n\n// Resolves the API per request: providerOptions also reach this model via Gateway.\nclass AzureTranscriptionModel implements TranscriptionModelV4 {\n readonly specificationVersion = 'v4';\n readonly provider = 'azure.transcription';\n\n constructor(\n readonly modelId: string,\n private readonly config: AzureOpenAIProviderSettings,\n private readonly openai: OpenAITranscriptionModel,\n private readonly speech: AzureSpeechTranscriptionModel,\n ) {}\n\n static [WORKFLOW_SERIALIZE](model: AzureTranscriptionModel) {\n return serializeModelOptions({\n modelId: model.modelId,\n config: model.config,\n });\n }\n\n static [WORKFLOW_DESERIALIZE](options: {\n modelId: string;\n config: AzureOpenAIProviderSettings;\n }) {\n return createAzure(options.config).transcription(options.modelId);\n }\n\n async doGenerate(options: Parameters<TranscriptionModelV4['doGenerate']>[0]) {\n const { api, ...speechOptions } = await this.getOptions(\n options.providerOptions,\n );\n if (api === 'speech') {\n return this.speech.doGenerate(options, speechOptions);\n }\n\n const result = await this.openai.doGenerate(options);\n return {\n ...result,\n warnings: [\n ...result.warnings,\n ...Object.keys(speechOptions).map(key => ({\n type: 'unsupported' as const,\n feature: `providerOptions.azure.${key}`,\n details: 'This option requires the Azure Speech API.',\n })),\n ],\n };\n }\n\n async doStream(\n options: Parameters<NonNullable<TranscriptionModelV4['doStream']>>[0],\n ) {\n const { api } = await this.getOptions(options.providerOptions);\n if (api === 'speech') {\n throw new UnsupportedFunctionalityError({\n functionality: 'streaming transcription with the Azure Speech API',\n });\n }\n return this.openai.doStream(options);\n }\n\n private async getOptions(\n providerOptions: Parameters<\n TranscriptionModelV4['doGenerate']\n >[0]['providerOptions'],\n ) {\n const options = await parseProviderOptions({\n provider: 'azure',\n providerOptions,\n schema: azureTranscriptionModelOptions,\n });\n return {\n ...options,\n api:\n options?.api ?? (isMAITranscribe2(this.modelId) ? 'speech' : 'openai'),\n };\n }\n}\n","import {\n codeInterpreter,\n fileSearch,\n imageGeneration,\n webSearch,\n webSearchPreview,\n} from '@ai-sdk/openai/internal';\n\nexport const azureOpenaiTools: {\n codeInterpreter: typeof codeInterpreter;\n fileSearch: typeof fileSearch;\n imageGeneration: typeof imageGeneration;\n webSearch: typeof webSearch;\n webSearchPreview: typeof webSearchPreview;\n} = {\n codeInterpreter,\n fileSearch,\n imageGeneration,\n webSearch,\n webSearchPreview,\n};\n","import type { TranscriptionModelV4 } from '@ai-sdk/provider';\nimport {\n combineHeaders,\n convertBase64ToUint8Array,\n createJsonErrorResponseHandler,\n createJsonResponseHandler,\n mediaTypeToExtension,\n postFormDataToApi,\n type FetchFunction,\n} from '@ai-sdk/provider-utils';\nimport { z } from 'zod/v4';\nimport type { AzureTranscriptionProviderMetadata } from './azure-transcription-provider-metadata';\nimport type { AzureTranscriptionModelSpeechOptions } from './azure-speech-transcription-model-options';\nimport { isMAITranscribe2 } from './azure-transcription-model-options';\n\nexport class AzureSpeechTranscriptionModel implements TranscriptionModelV4 {\n readonly specificationVersion = 'v4';\n readonly provider = 'azure.transcription';\n\n constructor(\n readonly modelId: string,\n private readonly config: {\n url: () => string;\n headers: () => Record<string, string | undefined>;\n fetch?: FetchFunction;\n },\n ) {}\n\n async doGenerate(\n options: Parameters<TranscriptionModelV4['doGenerate']>[0],\n azureOptions: AzureTranscriptionModelSpeechOptions = {},\n ): Promise<Awaited<ReturnType<TranscriptionModelV4['doGenerate']>>> {\n const timestamp = new Date();\n const formData = new FormData();\n formData.append(\n 'audio',\n new Blob(\n [\n typeof options.audio === 'string'\n ? convertBase64ToUint8Array(options.audio)\n : options.audio,\n ],\n { type: options.mediaType },\n ),\n `audio.${mediaTypeToExtension(options.mediaType)}`,\n );\n formData.append(\n 'definition',\n JSON.stringify({\n enhancedMode: {\n enabled: true,\n model: isMAITranscribe2(this.modelId)\n ? 'MAI-Transcribe-2'\n : this.modelId,\n modelOptions: {\n timestamps: azureOptions.timestamps ?? 'segment',\n transcribeStyle: azureOptions.transcribeStyle,\n },\n },\n locales: azureOptions.locales,\n diarization: azureOptions.diarization,\n phraseList: azureOptions.phraseList,\n }),\n );\n\n const { value, rawValue, responseHeaders } = await postFormDataToApi({\n url: this.config.url(),\n headers: combineHeaders(this.config.headers(), options.headers),\n formData,\n abortSignal: options.abortSignal,\n fetch: this.config.fetch,\n failedResponseHandler: createJsonErrorResponseHandler({\n errorSchema: z.union([\n z.object({ error: z.object({ message: z.string() }) }),\n z.object({ message: z.string() }),\n ]),\n errorToMessage: data =>\n 'error' in data ? data.error.message : data.message,\n }),\n successfulResponseHandler: createJsonResponseHandler(responseSchema),\n });\n\n const phrases = value.phrases ?? [];\n // Consider every reported locale so mixed results (e.g. en + fil) are not\n // collapsed to one language; only ISO-639-1 codes are reported.\n const languages = new Set(\n phrases.flatMap(phrase =>\n phrase.locale ? [phrase.locale.split('-')[0].toLowerCase()] : [],\n ),\n );\n const [language] = languages;\n const reportedLanguage =\n languages.size === 1 && /^[a-z]{2}$/.test(language)\n ? language\n : undefined;\n\n return {\n text: value.combinedPhrases.map(phrase => phrase.text).join(' '),\n segments: phrases.flatMap(phrase =>\n phrase.offsetMilliseconds != null && phrase.durationMilliseconds != null\n ? [\n {\n text: phrase.text,\n startSecond: phrase.offsetMilliseconds / 1000,\n endSecond:\n (phrase.offsetMilliseconds + phrase.durationMilliseconds) /\n 1000,\n },\n ]\n : [],\n ),\n language: reportedLanguage,\n durationInSeconds:\n value.durationMilliseconds != null\n ? value.durationMilliseconds / 1000\n : undefined,\n warnings: [],\n providerMetadata: {\n azure: { phrases },\n } satisfies AzureTranscriptionProviderMetadata,\n response: {\n timestamp,\n modelId: this.modelId,\n headers: responseHeaders,\n body: rawValue,\n },\n };\n }\n}\n\nconst responseSchema = z.object({\n combinedPhrases: z.array(z.object({ text: z.string() })),\n durationMilliseconds: z.number().nullish(),\n phrases: z\n .array(\n z.object({\n text: z.string(),\n offsetMilliseconds: z.number().nullish(),\n durationMilliseconds: z.number().nullish(),\n locale: z.string().nullish(),\n speaker: z.number().nullish(),\n confidence: z.number().nullish(),\n words: z\n .array(\n z.object({\n text: z.string(),\n offsetMilliseconds: z.number().nullish(),\n durationMilliseconds: z.number().nullish(),\n }),\n )\n .nullish(),\n }),\n )\n .nullish(),\n});\n","import {\n lazySchema,\n zodSchema,\n type InferSchema,\n} from '@ai-sdk/provider-utils';\nimport { z } from 'zod/v4';\nimport { azureSpeechTranscriptionModelOptionsShape } from './azure-speech-transcription-model-options';\n\nexport const azureTranscriptionModelOptions = lazySchema(() =>\n zodSchema(\n z.strictObject({\n /**\n * API to use. Defaults to Speech for MAI-Transcribe-2, OpenAI otherwise.\n */\n api: z.enum(['openai', 'speech']).optional(),\n ...azureSpeechTranscriptionModelOptionsShape(),\n }),\n ),\n);\n\nexport type AzureTranscriptionModelOptions = InferSchema<\n typeof azureTranscriptionModelOptions\n>;\n\nexport function isMAITranscribe2(modelId: string): boolean {\n return modelId.toLowerCase() === 'mai-transcribe-2';\n}\n","import {\n lazySchema,\n zodSchema,\n type InferSchema,\n} from '@ai-sdk/provider-utils';\nimport { z } from 'zod/v4';\n\n// Strict objects reject unknown keys (e.g. `diarization.maxSpeakers`, which\n// MAI-Transcribe-2 does not support) instead of silently dropping them.\nexport const azureSpeechTranscriptionModelOptionsShape = () => ({\n /**\n * Timing granularity. Defaults to `segment` so that transcription results\n * include timed segments (Azure's own default is `none`).\n */\n timestamps: z.enum(['word', 'segment', 'none']).optional(),\n\n /**\n * `verbatim` keeps fillers and false starts, `clean` removes them.\n * Azure defaults to `verbatim`.\n */\n transcribeStyle: z.enum(['verbatim', 'clean']).optional(),\n\n /**\n * Forces a single language, e.g. `['en']`. Omit for automatic language\n * detection and code switching.\n */\n locales: z.array(z.string()).length(1).optional(),\n\n /**\n * Speaker diarization. Speaker IDs are available in provider metadata.\n */\n diarization: z.strictObject({ enabled: z.boolean() }).optional(),\n\n /**\n * Keyword biasing for names and domain terminology.\n */\n phraseList: z.strictObject({ phrases: z.array(z.string()) }).optional(),\n});\n\nexport const azureSpeechTranscriptionModelOptions = lazySchema(() =>\n zodSchema(z.strictObject(azureSpeechTranscriptionModelOptionsShape())),\n);\n\nexport type AzureTranscriptionModelSpeechOptions = InferSchema<\n typeof azureSpeechTranscriptionModelOptions\n>;\n","// Version string of this package injected at build time.\ndeclare const __PACKAGE_VERSION__: string | undefined;\nexport const VERSION: string =\n typeof __PACKAGE_VERSION__ !== 'undefined'\n ? __PACKAGE_VERSION__\n : '0.0.0-test';\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,iCAAiC;AAC1C;AAAA,EACE;AAAA,EACA;AAAA,OAOK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;;;AC/BP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEA,IAAM,mBAMT;AAAA,EACF;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;;;ACnBA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,KAAAA,UAAS;;;ACVlB;AAAA,EACE,cAAAC;AAAA,EACA,aAAAC;AAAA,OAEK;AACP,SAAS,KAAAC,UAAS;;;ACLlB;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AACP,SAAS,SAAS;AAIX,IAAM,4CAA4C,OAAO;AAAA;AAAA;AAAA;AAAA;A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ACpB,aAAO,KAAK,OAAO,WAAW,SAAS,aAAa;AAAA,IACtD;AAEA,UAAM,SAAS,MAAM,KAAK,OAAO,WAAW,OAAO;AACnD,WAAO;AAAA,MACL,GAAG;AAAA,MACH,UAAU;AAAA,QACR,GAAG,OAAO;AAAA,QACV,GAAG,OAAO,KAAK,aAAa,EAAE,IAAI,UAAQ;AAAA,UACxC,MAAM;AAAA,UACN,SAAS,yBAAyB,GAAG;AAAA,UACrC,SAAS;AAAA,QACX,EAAE;AAAA,MACJ;AAAA,IACF;AAAA,EACF;AAAA,EAEA,MAAM,SACJ,SACA;AACA,UAAM,EAAE,IAAI,IAAI,MAAM,KAAK,WAAW,QAAQ,eAAe;AAC7D,QAAI,QAAQ,UAAU;AACpB,YAAM,IAAI,8BAA8B;AAAA,QACtC,eAAe;AAAA,MACjB,CAAC;AAAA,IACH;AACA,WAAO,KAAK,OAAO,SAAS,OAAO;AAAA,EACrC;AAAA,EAEA,MAAc,WACZ,iBAGA;AACA,UAAM,UAAU,MAAM,qBAAqB;AAAA,MACzC,UAAU;AAAA,MACV;AAAA,MACA,QAAQ;AAAA,IACV,CAAC;AACD,WAAO;AAAA,MACL,GAAG;AAAA,MACH,KACE,SAAS,QAAQ,iBAAiB,KAAK,OAAO,IAAI,WAAW;AAAA,IACjE;AAAA,EACF;AACF;","names":["z","lazySchema","zodSchema","z","lazySchema","zodSchema","z","z"]}
package/docs/04-azure.mdx CHANGED
@@ -131,6 +131,13 @@ You can use the following optional settings to customize the OpenAI provider ins
131
131
  This option is useful for compatibility with certain Azure OpenAI models or deployments
132
132
  that require the legacy endpoint format.
133
133
 
134
+ - **speechBaseURL** _string_
135
+
136
+ URL prefix for Azure Speech transcription requests (MAI-Transcribe-2), for example
137
+ a regional endpoint such as `https://eastus.api.cognitive.microsoft.com`.
138
+ Defaults to `https://{resourceName}.cognitiveservices.azure.com`.
139
+ Speech requests do not use `baseURL` or `apiVersion`.
140
+
134
141
  ## Language Models
135
142
 
136
143
  The Azure OpenAI provider instance is a function that you can invoke to create a language model:
@@ -1079,6 +1086,13 @@ Azure OpenAI supports DALL-E 2 and DALL-E 3 models through deployments. The capa
1079
1086
  | DALL-E 3 | 1024x1024, 1792x1024, 1024x1792 |
1080
1087
  | DALL-E 2 | 256x256, 512x512, 1024x1024 |
1081
1088
 
1089
+ Azure deployment names are user-defined and do not identify the backing model.
1090
+ Consequently, `supportsFileInputs` and `supportsMaskInputs` are `undefined`
1091
+ (unknown) for Azure image model instances. If your application knows the
1092
+ capabilities of a deployment, you can advertise them with the
1093
+ `overrideSupportsFileInputs` and `overrideSupportsMaskInputs` options of
1094
+ [`wrapImageModel`](/docs/reference/ai-sdk-core/wrap-image-model).
1095
+
1082
1096
  <Note>
1083
1097
  DALL-E models do not support the `aspectRatio` parameter. Use the `size`
1084
1098
  parameter instead.
@@ -1091,7 +1105,7 @@ Azure OpenAI supports DALL-E 2 and DALL-E 3 models through deployments. The capa
1091
1105
 
1092
1106
  ## Transcription Models
1093
1107
 
1094
- You can create models that call the Azure OpenAI transcription API using the `.transcription()` factory method.
1108
+ You can create models that call the Azure OpenAI or Azure Speech transcription API using the `.transcription()` factory method.
1095
1109
 
1096
1110
  The first argument is the model id e.g. `whisper-1`.
1097
1111
 
@@ -1099,6 +1113,105 @@ The first argument is the model id e.g. `whisper-1`.
1099
1113
  const model = azure.transcription('whisper-1');
1100
1114
  ```
1101
1115
 
1116
+ ### MAI-Transcribe-2
1117
+
1118
+ MAI-Transcribe-2 is a multilingual speech-to-text model from Microsoft AI, served through Azure.
1119
+ `azure.transcription('mai-transcribe-2')` uses the Azure Speech API.
1120
+ The model ID is matched case-insensitively and sent to Azure as `MAI-Transcribe-2`.
1121
+ All other IDs use the OpenAI API by default, including custom deployment names.
1122
+
1123
+ ```ts
1124
+ import { azure, type AzureTranscriptionModelOptions } from '@ai-sdk/azure';
1125
+ import { transcribe } from 'ai';
1126
+ import { readFile } from 'fs/promises';
1127
+
1128
+ const result = await transcribe({
1129
+ model: azure.transcription('mai-transcribe-2'),
1130
+ audio: await readFile('audio.wav'),
1131
+ providerOptions: {
1132
+ azure: {
1133
+ timestamps: 'word',
1134
+ diarization: { enabled: true },
1135
+ transcribeStyle: 'clean',
1136
+ } satisfies AzureTranscriptionModelOptions,
1137
+ },
1138
+ });
1139
+ ```
1140
+
1141
+ MAI-Transcribe-2 requires a Microsoft Foundry (Speech) resource in a region where it is available:
1142
+ `centralindia`, `eastus`, `northeurope`, `southeastasia`, `westus`, or `westus2`
1143
+ (see [Speech service regions](https://learn.microsoft.com/en-us/azure/ai-services/speech-service/regions?tabs=llmspeech)).
1144
+ Resources in other regions reject the request.
1145
+ Set `AZURE_RESOURCE_NAME` and `AZURE_API_KEY` to that resource's name and key,
1146
+ or pass `resourceName` and `apiKey` to `createAzure`. `tokenProvider`, custom headers,
1147
+ and custom fetch are also supported. Keys are sent as `Ocp-Apim-Subscription-Key`.
1148
+
1149
+ Speech requests use `https://{resourceName}.cognitiveservices.azure.com/speechtotext/transcriptions:transcribe`
1150
+ with API version `2025-10-15`. Use `speechBaseURL` to supply a different Speech URL prefix
1151
+ (without `/speechtotext/transcriptions:transcribe`), for example a regional endpoint:
1152
+
1153
+ ```ts
1154
+ import { createAzure } from '@ai-sdk/azure';
1155
+
1156
+ const azure = createAzure({
1157
+ speechBaseURL: 'https://eastus.api.cognitive.microsoft.com',
1158
+ apiKey: process.env.AZURE_SPEECH_API_KEY,
1159
+ });
1160
+ ```
1161
+
1162
+ Speech requests do not use `baseURL`, `apiVersion`, or `useDeploymentBasedUrls`;
1163
+ those settings only apply to Azure OpenAI models.
1164
+
1165
+ The following options are available through `providerOptions.azure`:
1166
+
1167
+ - **api** _'openai' | 'speech'_
1168
+ Overrides model-based API selection for this request.
1169
+ Set `openai` for an OpenAI deployment named `mai-transcribe-2`, or `speech` to
1170
+ send another model ID to Speech. Other Speech model IDs are sent unchanged.
1171
+
1172
+ - **timestamps** _'word' | 'segment' | 'none'_
1173
+ Timing granularity. The AI SDK defaults to `segment` so that results include
1174
+ timed segments (Azure's own default is `none`). `segment` returns one segment
1175
+ per sentence or speaker turn, `word` additionally returns word timing in provider
1176
+ metadata, and `none` returns a single segment that spans the whole audio.
1177
+
1178
+ - **transcribeStyle** _'verbatim' | 'clean'_
1179
+ `verbatim` keeps fillers and false starts, `clean` removes them. Defaults to `verbatim`.
1180
+
1181
+ - **locales** _string[]_
1182
+ Exactly one language code, such as `['en']`. This is a strong hint; omit it for
1183
+ automatic language detection and code switching.
1184
+
1185
+ - **diarization** _object_
1186
+ Set `enabled` to `true` to identify speakers. Speaker IDs are returned in
1187
+ provider metadata. `maxSpeakers` is not supported by MAI-Transcribe-2.
1188
+
1189
+ - **phraseList** _object_
1190
+ Set `phrases` to a list of names and domain terms to bias recognition toward them.
1191
+
1192
+ Explicit `api` takes precedence over the model ID. Existing OpenAI transcription
1193
+ options remain under `providerOptions.openai`. Speech-only Azure options produce
1194
+ warnings when used with the OpenAI API. Unknown or unsupported `providerOptions.azure`
1195
+ keys (for example `diarization.maxSpeakers`) are rejected before the request is sent.
1196
+
1197
+ Results include transcript text, timed segments, duration, and an ISO-639-1
1198
+ language code when the reported phrase locales identify one language. Mixed-language
1199
+ results, and languages without an ISO-639-1 code such as Filipino (`fil`) or
1200
+ Cantonese (`yue`), leave `language` undefined. Speaker IDs, exact locales, and word
1201
+ timing are preserved in `providerMetadata.azure.phrases`; use the exported
1202
+ `AzureTranscriptionProviderMetadata` type to access them. Phrase timing is in
1203
+ milliseconds in metadata and seconds in normalized `segments`.
1204
+
1205
+ MAI-Transcribe-2 is a file transcription model: it accepts WAV, MP3, or FLAC files
1206
+ shorter than 2 hours and smaller than 250 MB, and does not support streaming
1207
+ transcription. The model is in public preview. See
1208
+ [Azure's MAI-Transcribe guide](https://learn.microsoft.com/en-us/azure/ai-services/speech-service/mai-transcribe)
1209
+ for supported languages and diarization limits.
1210
+
1211
+ AI Gateway forwards these provider options, including `azure.api`.
1212
+
1213
+ ### OpenAI transcription
1214
+
1102
1215
  <Note>
1103
1216
  If you encounter a "DeploymentNotFound" error with transcription models,
1104
1217
  try enabling deployment-based URLs:
@@ -1164,6 +1277,7 @@ The following provider options are available:
1164
1277
  | `whisper-1` | <Check /> | <Check /> | <Check /> | <Check /> |
1165
1278
  | `gpt-4o-mini-transcribe` | <Check /> | <Cross /> | <Cross /> | <Cross /> |
1166
1279
  | `gpt-4o-transcribe` | <Check /> | <Cross /> | <Cross /> | <Cross /> |
1280
+ | `mai-transcribe-2` | <Check /> | <Check /> | <Check /> | <Check /> |
1167
1281
 
1168
1282
  ## Speech Models
1169
1283
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/azure",
3
- "version": "4.0.82",
3
+ "version": "4.0.83",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "sideEffects": false,
@@ -29,10 +29,10 @@
29
29
  }
30
30
  },
31
31
  "dependencies": {
32
- "@ai-sdk/deepseek": "3.0.54",
33
- "@ai-sdk/openai": "4.0.78",
34
- "@ai-sdk/provider": "4.0.18",
35
- "@ai-sdk/provider-utils": "5.0.49"
32
+ "@ai-sdk/deepseek": "3.0.55",
33
+ "@ai-sdk/openai": "4.0.79",
34
+ "@ai-sdk/provider": "4.0.19",
35
+ "@ai-sdk/provider-utils": "5.0.50"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@ai-sdk/test-server": "2.0.2",
@@ -10,6 +10,7 @@ import {
10
10
  import { DeepSeekChatLanguageModel } from '@ai-sdk/deepseek/internal';
11
11
  import {
12
12
  InvalidArgumentError,
13
+ UnsupportedFunctionalityError,
13
14
  type EmbeddingModelV4,
14
15
  type LanguageModelV4,
15
16
  type ProviderV4,
@@ -21,11 +22,20 @@ import {
21
22
  loadApiKey,
22
23
  loadSetting,
23
24
  normalizeHeaders,
25
+ parseProviderOptions,
26
+ serializeModelOptions,
27
+ WORKFLOW_DESERIALIZE,
28
+ WORKFLOW_SERIALIZE,
24
29
  withoutTrailingSlash,
25
30
  withUserAgentSuffix,
26
31
  type FetchFunction,
27
32
  } from '@ai-sdk/provider-utils';
28
33
  import { azureOpenaiTools } from './azure-openai-tools';
34
+ import { AzureSpeechTranscriptionModel } from './azure-speech-transcription-model';
35
+ import {
36
+ azureTranscriptionModelOptions,
37
+ isMAITranscribe2,
38
+ } from './azure-transcription-model-options';
29
39
  import { VERSION } from './version';
30
40
 
31
41
  export interface AzureOpenAIProvider extends ProviderV4 {
@@ -87,10 +97,16 @@ export interface AzureOpenAIProvider extends ProviderV4 {
87
97
  imageModel(deploymentId: string): ImageModelV4;
88
98
 
89
99
  /**
90
- * Creates an Azure OpenAI model for audio transcription.
100
+ * Creates an Azure transcription model. MAI-Transcribe-2 uses the Speech API
101
+ * by default; other IDs use OpenAI. Override with providerOptions.azure.api.
91
102
  */
92
103
  transcription(deploymentId: string): TranscriptionModelV4;
93
104
 
105
+ /**
106
+ * Creates an Azure transcription model. Alias of `transcription`.
107
+ */
108
+ transcriptionModel(deploymentId: string): TranscriptionModelV4;
109
+
94
110
  /**
95
111
  * Creates an Azure OpenAI model for speech generation.
96
112
  */
@@ -155,6 +171,14 @@ export interface AzureOpenAIProviderSettings {
155
171
  * `{baseURL}/v1{path}?api-version={apiVersion}`.
156
172
  */
157
173
  useDeploymentBasedUrls?: boolean;
174
+
175
+ /**
176
+ * URL prefix for Azure Speech transcription (MAI-Transcribe-2), e.g. a
177
+ * regional endpoint like `https://eastus.api.cognitive.microsoft.com`.
178
+ * Defaults to `https://{resourceName}.cognitiveservices.azure.com`.
179
+ * Speech requests do not use `baseURL` or `apiVersion`.
180
+ */
181
+ speechBaseURL?: string;
158
182
  }
159
183
 
160
184
  function getAzureOpenAIBaseURLInfo(baseURL: string | undefined) {
@@ -199,15 +223,16 @@ export function createAzure(
199
223
  });
200
224
  }
201
225
 
202
- const getHeaders = () => {
226
+ const getHeaders = (api: 'openai' | 'speech' = 'openai') => {
203
227
  const authHeaders = tokenProvider
204
228
  ? {}
205
229
  : {
206
- 'api-key': loadApiKey({
207
- apiKey: options.apiKey,
208
- environmentVariableName: 'AZURE_API_KEY',
209
- description: 'Azure OpenAI',
210
- }),
230
+ [api === 'speech' ? 'Ocp-Apim-Subscription-Key' : 'api-key']:
231
+ loadApiKey({
232
+ apiKey: options.apiKey,
233
+ environmentVariableName: 'AZURE_API_KEY',
234
+ description: api === 'speech' ? 'Azure Speech' : 'Azure OpenAI',
235
+ }),
211
236
  };
212
237
 
213
238
  return withUserAgentSuffix(
@@ -330,15 +355,34 @@ export function createAzure(
330
355
  url,
331
356
  headers: getHeaders,
332
357
  fetch,
358
+ // Azure model IDs are user-defined deployment names, so OpenAI model
359
+ // family capabilities cannot be inferred from them.
360
+ imageInputCapabilities: {
361
+ supportsFileInputs: undefined,
362
+ supportsMaskInputs: undefined,
363
+ },
333
364
  });
334
365
 
335
366
  const createTranscriptionModel = (modelId: string) =>
336
- new OpenAITranscriptionModel(modelId, {
337
- provider: 'azure.transcription',
338
- url,
339
- headers: getHeaders,
340
- fetch,
341
- });
367
+ new AzureTranscriptionModel(
368
+ modelId,
369
+ options,
370
+ new OpenAITranscriptionModel(modelId, {
371
+ provider: 'azure.transcription',
372
+ url,
373
+ headers: getHeaders,
374
+ fetch,
375
+ }),
376
+ new AzureSpeechTranscriptionModel(modelId, {
377
+ url: () =>
378
+ `${
379
+ withoutTrailingSlash(options.speechBaseURL) ??
380
+ `https://${getResourceName()}.cognitiveservices.azure.com`
381
+ }/speechtotext/transcriptions:transcribe?api-version=2025-10-15`,
382
+ headers: () => getHeaders('speech'),
383
+ fetch,
384
+ }),
385
+ );
342
386
 
343
387
  const createSpeechModel = (modelId: string) =>
344
388
  new OpenAISpeechModel(modelId, {
@@ -371,6 +415,7 @@ export function createAzure(
371
415
  provider.imageModel = createImageModel;
372
416
  provider.responses = createResponsesModel;
373
417
  provider.transcription = createTranscriptionModel;
418
+ provider.transcriptionModel = createTranscriptionModel;
374
419
  provider.speech = createSpeechModel;
375
420
  provider.tools = azureOpenaiTools;
376
421
  return provider;
@@ -380,3 +425,81 @@ export function createAzure(
380
425
  * Default Azure OpenAI provider instance.
381
426
  */
382
427
  export const azure = createAzure();
428
+
429
+ // Resolves the API per request: providerOptions also reach this model via Gateway.
430
+ class AzureTranscriptionModel implements TranscriptionModelV4 {
431
+ readonly specificationVersion = 'v4';
432
+ readonly provider = 'azure.transcription';
433
+
434
+ constructor(
435
+ readonly modelId: string,
436
+ private readonly config: AzureOpenAIProviderSettings,
437
+ private readonly openai: OpenAITranscriptionModel,
438
+ private readonly speech: AzureSpeechTranscriptionModel,
439
+ ) {}
440
+
441
+ static [WORKFLOW_SERIALIZE](model: AzureTranscriptionModel) {
442
+ return serializeModelOptions({
443
+ modelId: model.modelId,
444
+ config: model.config,
445
+ });
446
+ }
447
+
448
+ static [WORKFLOW_DESERIALIZE](options: {
449
+ modelId: string;
450
+ config: AzureOpenAIProviderSettings;
451
+ }) {
452
+ return createAzure(options.config).transcription(options.modelId);
453
+ }
454
+
455
+ async doGenerate(options: Parameters<TranscriptionModelV4['doGenerate']>[0]) {
456
+ const { api, ...speechOptions } = await this.getOptions(
457
+ options.providerOptions,
458
+ );
459
+ if (api === 'speech') {
460
+ return this.speech.doGenerate(options, speechOptions);
461
+ }
462
+
463
+ const result = await this.openai.doGenerate(options);
464
+ return {
465
+ ...result,
466
+ warnings: [
467
+ ...result.warnings,
468
+ ...Object.keys(speechOptions).map(key => ({
469
+ type: 'unsupported' as const,
470
+ feature: `providerOptions.azure.${key}`,
471
+ details: 'This option requires the Azure Speech API.',
472
+ })),
473
+ ],
474
+ };
475
+ }
476
+
477
+ async doStream(
478
+ options: Parameters<NonNullable<TranscriptionModelV4['doStream']>>[0],
479
+ ) {
480
+ const { api } = await this.getOptions(options.providerOptions);
481
+ if (api === 'speech') {
482
+ throw new UnsupportedFunctionalityError({
483
+ functionality: 'streaming transcription with the Azure Speech API',
484
+ });
485
+ }
486
+ return this.openai.doStream(options);
487
+ }
488
+
489
+ private async getOptions(
490
+ providerOptions: Parameters<
491
+ TranscriptionModelV4['doGenerate']
492
+ >[0]['providerOptions'],
493
+ ) {
494
+ const options = await parseProviderOptions({
495
+ provider: 'azure',
496
+ providerOptions,
497
+ schema: azureTranscriptionModelOptions,
498
+ });
499
+ return {
500
+ ...options,
501
+ api:
502
+ options?.api ?? (isMAITranscribe2(this.modelId) ? 'speech' : 'openai'),
503
+ };
504
+ }
505
+ }
@@ -0,0 +1,46 @@
1
+ import {
2
+ lazySchema,
3
+ zodSchema,
4
+ type InferSchema,
5
+ } from '@ai-sdk/provider-utils';
6
+ import { z } from 'zod/v4';
7
+
8
+ // Strict objects reject unknown keys (e.g. `diarization.maxSpeakers`, which
9
+ // MAI-Transcribe-2 does not support) instead of silently dropping them.
10
+ export const azureSpeechTranscriptionModelOptionsShape = () => ({
11
+ /**
12
+ * Timing granularity. Defaults to `segment` so that transcription results
13
+ * include timed segments (Azure's own default is `none`).
14
+ */
15
+ timestamps: z.enum(['word', 'segment', 'none']).optional(),
16
+
17
+ /**
18
+ * `verbatim` keeps fillers and false starts, `clean` removes them.
19
+ * Azure defaults to `verbatim`.
20
+ */
21
+ transcribeStyle: z.enum(['verbatim', 'clean']).optional(),
22
+
23
+ /**
24
+ * Forces a single language, e.g. `['en']`. Omit for automatic language
25
+ * detection and code switching.
26
+ */
27
+ locales: z.array(z.string()).length(1).optional(),
28
+
29
+ /**
30
+ * Speaker diarization. Speaker IDs are available in provider metadata.
31
+ */
32
+ diarization: z.strictObject({ enabled: z.boolean() }).optional(),
33
+
34
+ /**
35
+ * Keyword biasing for names and domain terminology.
36
+ */
37
+ phraseList: z.strictObject({ phrases: z.array(z.string()) }).optional(),
38
+ });
39
+
40
+ export const azureSpeechTranscriptionModelOptions = lazySchema(() =>
41
+ zodSchema(z.strictObject(azureSpeechTranscriptionModelOptionsShape())),
42
+ );
43
+
44
+ export type AzureTranscriptionModelSpeechOptions = InferSchema<
45
+ typeof azureSpeechTranscriptionModelOptions
46
+ >;
@@ -0,0 +1,155 @@
1
+ import type { TranscriptionModelV4 } from '@ai-sdk/provider';
2
+ import {
3
+ combineHeaders,
4
+ convertBase64ToUint8Array,
5
+ createJsonErrorResponseHandler,
6
+ createJsonResponseHandler,
7
+ mediaTypeToExtension,
8
+ postFormDataToApi,
9
+ type FetchFunction,
10
+ } from '@ai-sdk/provider-utils';
11
+ import { z } from 'zod/v4';
12
+ import type { AzureTranscriptionProviderMetadata } from './azure-transcription-provider-metadata';
13
+ import type { AzureTranscriptionModelSpeechOptions } from './azure-speech-transcription-model-options';
14
+ import { isMAITranscribe2 } from './azure-transcription-model-options';
15
+
16
+ export class AzureSpeechTranscriptionModel implements TranscriptionModelV4 {
17
+ readonly specificationVersion = 'v4';
18
+ readonly provider = 'azure.transcription';
19
+
20
+ constructor(
21
+ readonly modelId: string,
22
+ private readonly config: {
23
+ url: () => string;
24
+ headers: () => Record<string, string | undefined>;
25
+ fetch?: FetchFunction;
26
+ },
27
+ ) {}
28
+
29
+ async doGenerate(
30
+ options: Parameters<TranscriptionModelV4['doGenerate']>[0],
31
+ azureOptions: AzureTranscriptionModelSpeechOptions = {},
32
+ ): Promise<Awaited<ReturnType<TranscriptionModelV4['doGenerate']>>> {
33
+ const timestamp = new Date();
34
+ const formData = new FormData();
35
+ formData.append(
36
+ 'audio',
37
+ new Blob(
38
+ [
39
+ typeof options.audio === 'string'
40
+ ? convertBase64ToUint8Array(options.audio)
41
+ : options.audio,
42
+ ],
43
+ { type: options.mediaType },
44
+ ),
45
+ `audio.${mediaTypeToExtension(options.mediaType)}`,
46
+ );
47
+ formData.append(
48
+ 'definition',
49
+ JSON.stringify({
50
+ enhancedMode: {
51
+ enabled: true,
52
+ model: isMAITranscribe2(this.modelId)
53
+ ? 'MAI-Transcribe-2'
54
+ : this.modelId,
55
+ modelOptions: {
56
+ timestamps: azureOptions.timestamps ?? 'segment',
57
+ transcribeStyle: azureOptions.transcribeStyle,
58
+ },
59
+ },
60
+ locales: azureOptions.locales,
61
+ diarization: azureOptions.diarization,
62
+ phraseList: azureOptions.phraseList,
63
+ }),
64
+ );
65
+
66
+ const { value, rawValue, responseHeaders } = await postFormDataToApi({
67
+ url: this.config.url(),
68
+ headers: combineHeaders(this.config.headers(), options.headers),
69
+ formData,
70
+ abortSignal: options.abortSignal,
71
+ fetch: this.config.fetch,
72
+ failedResponseHandler: createJsonErrorResponseHandler({
73
+ errorSchema: z.union([
74
+ z.object({ error: z.object({ message: z.string() }) }),
75
+ z.object({ message: z.string() }),
76
+ ]),
77
+ errorToMessage: data =>
78
+ 'error' in data ? data.error.message : data.message,
79
+ }),
80
+ successfulResponseHandler: createJsonResponseHandler(responseSchema),
81
+ });
82
+
83
+ const phrases = value.phrases ?? [];
84
+ // Consider every reported locale so mixed results (e.g. en + fil) are not
85
+ // collapsed to one language; only ISO-639-1 codes are reported.
86
+ const languages = new Set(
87
+ phrases.flatMap(phrase =>
88
+ phrase.locale ? [phrase.locale.split('-')[0].toLowerCase()] : [],
89
+ ),
90
+ );
91
+ const [language] = languages;
92
+ const reportedLanguage =
93
+ languages.size === 1 && /^[a-z]{2}$/.test(language)
94
+ ? language
95
+ : undefined;
96
+
97
+ return {
98
+ text: value.combinedPhrases.map(phrase => phrase.text).join(' '),
99
+ segments: phrases.flatMap(phrase =>
100
+ phrase.offsetMilliseconds != null && phrase.durationMilliseconds != null
101
+ ? [
102
+ {
103
+ text: phrase.text,
104
+ startSecond: phrase.offsetMilliseconds / 1000,
105
+ endSecond:
106
+ (phrase.offsetMilliseconds + phrase.durationMilliseconds) /
107
+ 1000,
108
+ },
109
+ ]
110
+ : [],
111
+ ),
112
+ language: reportedLanguage,
113
+ durationInSeconds:
114
+ value.durationMilliseconds != null
115
+ ? value.durationMilliseconds / 1000
116
+ : undefined,
117
+ warnings: [],
118
+ providerMetadata: {
119
+ azure: { phrases },
120
+ } satisfies AzureTranscriptionProviderMetadata,
121
+ response: {
122
+ timestamp,
123
+ modelId: this.modelId,
124
+ headers: responseHeaders,
125
+ body: rawValue,
126
+ },
127
+ };
128
+ }
129
+ }
130
+
131
+ const responseSchema = z.object({
132
+ combinedPhrases: z.array(z.object({ text: z.string() })),
133
+ durationMilliseconds: z.number().nullish(),
134
+ phrases: z
135
+ .array(
136
+ z.object({
137
+ text: z.string(),
138
+ offsetMilliseconds: z.number().nullish(),
139
+ durationMilliseconds: z.number().nullish(),
140
+ locale: z.string().nullish(),
141
+ speaker: z.number().nullish(),
142
+ confidence: z.number().nullish(),
143
+ words: z
144
+ .array(
145
+ z.object({
146
+ text: z.string(),
147
+ offsetMilliseconds: z.number().nullish(),
148
+ durationMilliseconds: z.number().nullish(),
149
+ }),
150
+ )
151
+ .nullish(),
152
+ }),
153
+ )
154
+ .nullish(),
155
+ });
@@ -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
+ import { azureSpeechTranscriptionModelOptionsShape } from './azure-speech-transcription-model-options';
8
+
9
+ export const azureTranscriptionModelOptions = lazySchema(() =>
10
+ zodSchema(
11
+ z.strictObject({
12
+ /**
13
+ * API to use. Defaults to Speech for MAI-Transcribe-2, OpenAI otherwise.
14
+ */
15
+ api: z.enum(['openai', 'speech']).optional(),
16
+ ...azureSpeechTranscriptionModelOptionsShape(),
17
+ }),
18
+ ),
19
+ );
20
+
21
+ export type AzureTranscriptionModelOptions = InferSchema<
22
+ typeof azureTranscriptionModelOptions
23
+ >;
24
+
25
+ export function isMAITranscribe2(modelId: string): boolean {
26
+ return modelId.toLowerCase() === 'mai-transcribe-2';
27
+ }
@@ -0,0 +1,17 @@
1
+ export type AzureTranscriptionProviderMetadata = {
2
+ azure: {
3
+ phrases: Array<{
4
+ text: string;
5
+ offsetMilliseconds?: number | null;
6
+ durationMilliseconds?: number | null;
7
+ locale?: string | null;
8
+ speaker?: number | null;
9
+ confidence?: number | null;
10
+ words?: Array<{
11
+ text: string;
12
+ offsetMilliseconds?: number | null;
13
+ durationMilliseconds?: number | null;
14
+ }> | null;
15
+ }>;
16
+ };
17
+ };
package/src/index.ts CHANGED
@@ -28,3 +28,5 @@ export type {
28
28
  AzureResponsesSourceDocumentProviderMetadata,
29
29
  } from './azure-openai-provider-metadata';
30
30
  export { VERSION } from './version';
31
+ export type { AzureTranscriptionModelOptions } from './azure-transcription-model-options';
32
+ export type { AzureTranscriptionProviderMetadata } from './azure-transcription-provider-metadata';