@ai-sdk/gateway 3.0.143 → 3.0.145

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.
@@ -159,6 +159,8 @@ You can connect your own provider credentials to use with Vercel AI Gateway. Thi
159
159
 
160
160
  To set up BYOK, add your provider credentials in your Vercel team's AI Gateway settings. Once configured, AI Gateway automatically uses your credentials. No code changes are needed.
161
161
 
162
+ For providers like Azure where you can use custom deployment names, you can configure model mappings to map gateway model slugs to your deployment names. See [model mappings](https://vercel.com/docs/ai-gateway/byok#model-mappings) for details.
163
+
162
164
  Learn more in the [BYOK documentation](https://vercel.com/docs/ai-gateway/byok).
163
165
 
164
166
  ## Language Models
@@ -935,15 +937,18 @@ The following gateway provider options are available:
935
937
 
936
938
  Each provider can have multiple credentials (tried in order). The structure is a record where keys are provider slugs and values are arrays of credential objects.
937
939
 
940
+ Each credential can optionally include a `modelMappings` array to map AI Gateway model slugs to your deployment names (for example, custom Azure deployment names). If a BYOK request fails, the gateway falls back to system credentials using the default model name.
941
+
938
942
  Examples:
939
943
 
940
944
  - Single provider: `byok: { 'anthropic': [{ apiKey: 'sk-ant-...' }] }`
941
945
  - Multiple credentials: `byok: { 'vertex': [{ project: 'proj-1', googleCredentials: { privateKey: '...', clientEmail: '...' } }, { project: 'proj-2', googleCredentials: { privateKey: '...', clientEmail: '...' } }] }`
942
946
  - Multiple providers: `byok: { 'anthropic': [{ apiKey: '...' }], 'bedrock': [{ accessKeyId: '...', secretAccessKey: '...' }] }`
947
+ - With model mappings: `byok: { 'azure': [{ apiKey: '...', resourceName: '...', modelMappings: [{ gatewayModelSlug: 'openai/gpt-5.4-nano', customModelId: 'my-deployment' }] }] }`
943
948
 
944
949
  - **zeroDataRetention** _boolean_
945
950
 
946
- Restricts routing requests to providers that have zero data retention agreements with Vercel for AI Gateway. If there are no providers available for the model with zero data retention, the request will fail. BYOK credentials are skipped when `zeroDataRetention` is set to `true` to ensure that requests are only routed to providers that support ZDR compliance. Request-level ZDR is only available for Vercel Pro and Enterprise plans.
951
+ Restricts routing to providers with zero data retention agreements with Vercel for AI Gateway. BYOK credentials are skipped by default, since your provider agreements differ from Vercel's. When this filter is on, AI Gateway routes only to providers Vercel has ZDR agreements with for the model. If you have BYOK keys marked as ZDR, those keys are tried first, then AI Gateway falls back to its system credentials. You are responsible for the accuracy of that marking. Applies to both account-wide and request-level ZDR. The request fails if no ZDR-eligible credentials are available. Request-level ZDR is only available for Vercel Pro and Enterprise plans.
947
952
 
948
953
  - **disallowPromptTraining** _boolean_
949
954
 
@@ -1036,7 +1041,7 @@ const { text } = await generateText({
1036
1041
 
1037
1042
  #### Zero Data Retention Example
1038
1043
 
1039
- Set `zeroDataRetention` to true to route requests to providers that have zero data retention agreements with Vercel for AI Gateway. If there are no providers available for the model with zero data retention, the request will fail. When `zeroDataRetention` is `false` or not specified, there is no enforcement of restricting routing. BYOK credentials are skipped when `zeroDataRetention` is set to `true` to ensure that requests are only routed to providers that support ZDR compliance. Request-level ZDR is only available for Vercel Pro and Enterprise plans.
1044
+ Set `zeroDataRetention` to true to route requests to providers with zero data retention agreements with Vercel for AI Gateway. BYOK credentials are skipped by default, since your provider agreements differ from Vercel's. When this filter is on, AI Gateway routes only to providers Vercel has ZDR agreements with for the model. If you have BYOK keys marked as ZDR, those keys are tried first, then AI Gateway falls back to its system credentials. You are responsible for the accuracy of that marking. Applies to both account-wide and request-level ZDR. The request fails if no ZDR-eligible credentials are available. When `zeroDataRetention` is `false` or not specified, there is no enforcement of restricting routing. Request-level ZDR is only available for Vercel Pro and Enterprise plans.
1040
1045
 
1041
1046
  ```ts
1042
1047
  import type { GatewayProviderOptions } from "@ai-sdk/gateway";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ai-sdk/gateway",
3
3
  "private": false,
4
- "version": "3.0.143",
4
+ "version": "3.0.145",
5
5
  "license": "Apache-2.0",
6
6
  "sideEffects": false,
7
7
  "main": "./dist/index.js",
@@ -32,7 +32,7 @@
32
32
  "dependencies": {
33
33
  "@vercel/oidc": "3.2.0",
34
34
  "@ai-sdk/provider": "3.0.13",
35
- "@ai-sdk/provider-utils": "4.0.35"
35
+ "@ai-sdk/provider-utils": "4.0.37"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@types/node": "18.15.11",
@@ -1,4 +1,5 @@
1
1
  import type { APICallError } from '@ai-sdk/provider';
2
+ import { secureJsonParse } from '@ai-sdk/provider-utils';
2
3
 
3
4
  export function extractApiCallResponse(error: APICallError): unknown {
4
5
  if (error.data !== undefined) {
@@ -6,7 +7,7 @@ export function extractApiCallResponse(error: APICallError): unknown {
6
7
  }
7
8
  if (error.responseBody != null) {
8
9
  try {
9
- return JSON.parse(error.responseBody);
10
+ return secureJsonParse(error.responseBody);
10
11
  } catch {
11
12
  return error.responseBody;
12
13
  }
@@ -13,6 +13,7 @@ import {
13
13
  type Resolvable,
14
14
  } from '@ai-sdk/provider-utils';
15
15
  import { z } from 'zod/v4';
16
+ import { mapGatewayWarnings } from './map-gateway-warnings';
16
17
  import type { GatewayConfig } from './gateway-config';
17
18
  import { asGatewayError } from './errors';
18
19
  import { parseAuthMethod } from './errors/parse-auth-method';
@@ -87,7 +88,7 @@ export class GatewayImageModel implements ImageModelV3 {
87
88
 
88
89
  return {
89
90
  images: responseBody.images, // Always base64 strings from server
90
- warnings: responseBody.warnings ?? [],
91
+ warnings: mapGatewayWarnings(responseBody.warnings),
91
92
  providerMetadata:
92
93
  responseBody.providerMetadata as ImageModelV3ProviderMetadata,
93
94
  response: {
@@ -147,6 +148,11 @@ const gatewayImageWarningSchema = z.discriminatedUnion('type', [
147
148
  feature: z.string(),
148
149
  details: z.string().optional(),
149
150
  }),
151
+ z.object({
152
+ type: z.literal('deprecated'),
153
+ setting: z.string(),
154
+ message: z.string(),
155
+ }),
150
156
  z.object({
151
157
  type: z.literal('other'),
152
158
  message: z.string(),
@@ -1,8 +1,4 @@
1
- import type {
2
- SharedV3ProviderMetadata,
3
- SharedV3Warning,
4
- SpeechModelV3,
5
- } from '@ai-sdk/provider';
1
+ import type { SharedV3ProviderMetadata, SpeechModelV3 } from '@ai-sdk/provider';
6
2
  import {
7
3
  combineHeaders,
8
4
  createJsonErrorResponseHandler,
@@ -12,6 +8,7 @@ import {
12
8
  type Resolvable,
13
9
  } from '@ai-sdk/provider-utils';
14
10
  import { z } from 'zod/v4';
11
+ import { mapGatewayWarnings } from './map-gateway-warnings';
15
12
  import { asGatewayError } from './errors';
16
13
  import { parseAuthMethod } from './errors/parse-auth-method';
17
14
  import type { GatewayConfig } from './gateway-config';
@@ -80,7 +77,7 @@ export class GatewaySpeechModel implements SpeechModelV3 {
80
77
 
81
78
  return {
82
79
  audio: responseBody.audio,
83
- warnings: (responseBody.warnings ?? []) as Array<SharedV3Warning>,
80
+ warnings: mapGatewayWarnings(responseBody.warnings),
84
81
  providerMetadata:
85
82
  responseBody.providerMetadata as SharedV3ProviderMetadata,
86
83
  response: {
@@ -123,6 +120,11 @@ const gatewaySpeechWarningSchema = z.discriminatedUnion('type', [
123
120
  feature: z.string(),
124
121
  details: z.string().optional(),
125
122
  }),
123
+ z.object({
124
+ type: z.literal('deprecated'),
125
+ setting: z.string(),
126
+ message: z.string(),
127
+ }),
126
128
  z.object({
127
129
  type: z.literal('other'),
128
130
  message: z.string(),
@@ -1,6 +1,5 @@
1
1
  import type {
2
2
  SharedV3ProviderMetadata,
3
- SharedV3Warning,
4
3
  TranscriptionModelV3,
5
4
  } from '@ai-sdk/provider';
6
5
  import {
@@ -13,6 +12,7 @@ import {
13
12
  type Resolvable,
14
13
  } from '@ai-sdk/provider-utils';
15
14
  import { z } from 'zod/v4';
15
+ import { mapGatewayWarnings } from './map-gateway-warnings';
16
16
  import { asGatewayError } from './errors';
17
17
  import { parseAuthMethod } from './errors/parse-auth-method';
18
18
  import type { GatewayConfig } from './gateway-config';
@@ -79,7 +79,7 @@ export class GatewayTranscriptionModel implements TranscriptionModelV3 {
79
79
  segments: responseBody.segments ?? [],
80
80
  language: responseBody.language ?? undefined,
81
81
  durationInSeconds: responseBody.durationInSeconds ?? undefined,
82
- warnings: (responseBody.warnings ?? []) as Array<SharedV3Warning>,
82
+ warnings: mapGatewayWarnings(responseBody.warnings),
83
83
  providerMetadata:
84
84
  responseBody.providerMetadata as SharedV3ProviderMetadata,
85
85
  response: {
@@ -122,6 +122,11 @@ const gatewayTranscriptionWarningSchema = z.discriminatedUnion('type', [
122
122
  feature: z.string(),
123
123
  details: z.string().optional(),
124
124
  }),
125
+ z.object({
126
+ type: z.literal('deprecated'),
127
+ setting: z.string(),
128
+ message: z.string(),
129
+ }),
125
130
  z.object({
126
131
  type: z.literal('other'),
127
132
  message: z.string(),
@@ -5,6 +5,8 @@ export type GatewayVideoModelId =
5
5
  | 'alibaba/wan-v2.6-r2v'
6
6
  | 'alibaba/wan-v2.6-r2v-flash'
7
7
  | 'alibaba/wan-v2.6-t2v'
8
+ | 'alibaba/wan-v2.7-r2v'
9
+ | 'alibaba/wan-v2.7-t2v'
8
10
  | 'bytedance/seedance-2.0'
9
11
  | 'bytedance/seedance-2.0-fast'
10
12
  | 'bytedance/seedance-v1.0-pro'
@@ -17,6 +17,7 @@ import {
17
17
  type Resolvable,
18
18
  } from '@ai-sdk/provider-utils';
19
19
  import { z } from 'zod/v4';
20
+ import { mapGatewayWarnings } from './map-gateway-warnings';
20
21
  import type { GatewayConfig } from './gateway-config';
21
22
  import { asGatewayError } from './errors';
22
23
  import { parseAuthMethod } from './errors/parse-auth-method';
@@ -183,7 +184,7 @@ export class GatewayVideoModel implements Experimental_VideoModelV3 {
183
184
 
184
185
  return {
185
186
  videos: responseBody.videos,
186
- warnings: responseBody.warnings ?? [],
187
+ warnings: mapGatewayWarnings(responseBody.warnings),
187
188
  providerMetadata:
188
189
  responseBody.providerMetadata as SharedV3ProviderMetadata,
189
190
  response: {
@@ -249,6 +250,11 @@ const gatewayVideoWarningSchema = z.discriminatedUnion('type', [
249
250
  feature: z.string(),
250
251
  details: z.string().optional(),
251
252
  }),
253
+ z.object({
254
+ type: z.literal('deprecated'),
255
+ setting: z.string(),
256
+ message: z.string(),
257
+ }),
252
258
  z.object({
253
259
  type: z.literal('other'),
254
260
  message: z.string(),
@@ -0,0 +1,21 @@
1
+ import type { SharedV3Warning } from '@ai-sdk/provider';
2
+
3
+ type GatewayResponseWarning =
4
+ | SharedV3Warning
5
+ | { type: 'deprecated'; setting: string; message: string };
6
+
7
+ /**
8
+ * Maps warnings from gateway responses to `SharedV3Warning`.
9
+ *
10
+ * The gateway backend can emit `deprecated` warnings, which the v3
11
+ * specification cannot represent — they are mapped to `other` warnings.
12
+ */
13
+ export function mapGatewayWarnings(
14
+ warnings: Array<GatewayResponseWarning> | undefined,
15
+ ): Array<SharedV3Warning> {
16
+ return (warnings ?? []).map(warning =>
17
+ warning.type === 'deprecated'
18
+ ? { type: 'other', message: warning.message }
19
+ : warning,
20
+ );
21
+ }