@ai-sdk/gateway 3.0.144 → 3.0.146
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 +20 -0
- package/dist/index.d.mts +5 -3
- package/dist/index.d.ts +5 -3
- package/dist/index.js +409 -365
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +453 -409
- package/dist/index.mjs.map +1 -1
- package/docs/00-ai-gateway.mdx +1 -1
- package/package.json +5 -5
- package/src/errors/create-gateway-error.ts +12 -2
- package/src/errors/gateway-forbidden-error.ts +14 -0
- package/src/gateway-image-model.ts +7 -1
- package/src/gateway-language-model-settings.ts +5 -0
- package/src/gateway-speech-model.ts +8 -6
- package/src/gateway-transcription-model.ts +7 -2
- package/src/gateway-video-model-settings.ts +2 -0
- package/src/gateway-video-model.ts +7 -1
- package/src/map-gateway-warnings.ts +21 -0
package/docs/00-ai-gateway.mdx
CHANGED
|
@@ -419,7 +419,7 @@ import { generateText, tool } from "ai";
|
|
|
419
419
|
import { z } from "zod";
|
|
420
420
|
|
|
421
421
|
const { text } = await generateText({
|
|
422
|
-
model: "xai/grok-4",
|
|
422
|
+
model: "xai/grok-4.5",
|
|
423
423
|
prompt: "What is the weather like in San Francisco?",
|
|
424
424
|
tools: {
|
|
425
425
|
getWeather: tool({
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/gateway",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "3.0.
|
|
4
|
+
"version": "3.0.146",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"main": "./dist/index.js",
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@vercel/oidc": "3.2.0",
|
|
34
|
-
"@ai-sdk/provider": "3.0.
|
|
35
|
-
"@ai-sdk/provider-utils": "4.0.
|
|
34
|
+
"@ai-sdk/provider": "3.0.14",
|
|
35
|
+
"@ai-sdk/provider-utils": "4.0.38"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@types/node": "18.15.11",
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
"tsx": "4.19.2",
|
|
41
41
|
"typescript": "5.8.3",
|
|
42
42
|
"zod": "3.25.76",
|
|
43
|
-
"@
|
|
44
|
-
"@ai-
|
|
43
|
+
"@ai-sdk/test-server": "1.0.6",
|
|
44
|
+
"@vercel/ai-tsconfig": "0.0.0"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"zod": "^3.25.76 || ^4.1.8"
|
|
@@ -9,7 +9,10 @@ import {
|
|
|
9
9
|
} from './gateway-model-not-found-error';
|
|
10
10
|
import { GatewayInternalServerError } from './gateway-internal-server-error';
|
|
11
11
|
import { GatewayFailedDependencyError } from './gateway-failed-dependency-error';
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
GatewayForbiddenError,
|
|
14
|
+
forbiddenParamSchema,
|
|
15
|
+
} from './gateway-forbidden-error';
|
|
13
16
|
import { GatewayResponseError } from './gateway-response-error';
|
|
14
17
|
import {
|
|
15
18
|
lazySchema,
|
|
@@ -112,13 +115,20 @@ export async function createGatewayErrorFromResponse({
|
|
|
112
115
|
cause,
|
|
113
116
|
generationId,
|
|
114
117
|
});
|
|
115
|
-
case 'forbidden':
|
|
118
|
+
case 'forbidden': {
|
|
119
|
+
const ruleResult = await safeValidateTypes({
|
|
120
|
+
value: validatedResponse.error.param,
|
|
121
|
+
schema: forbiddenParamSchema,
|
|
122
|
+
});
|
|
123
|
+
|
|
116
124
|
return new GatewayForbiddenError({
|
|
117
125
|
message,
|
|
118
126
|
statusCode,
|
|
119
127
|
cause,
|
|
120
128
|
generationId,
|
|
129
|
+
ruleId: ruleResult.success ? ruleResult.value.ruleId : undefined,
|
|
121
130
|
});
|
|
131
|
+
}
|
|
122
132
|
default:
|
|
123
133
|
return new GatewayInternalServerError({
|
|
124
134
|
message,
|
|
@@ -1,9 +1,19 @@
|
|
|
1
|
+
import { z } from 'zod/v4';
|
|
1
2
|
import { GatewayError } from './gateway-error';
|
|
3
|
+
import { lazySchema, zodSchema } from '@ai-sdk/provider-utils';
|
|
2
4
|
|
|
3
5
|
const name = 'GatewayForbiddenError';
|
|
4
6
|
const marker = `vercel.ai.gateway.error.${name}`;
|
|
5
7
|
const symbol = Symbol.for(marker);
|
|
6
8
|
|
|
9
|
+
export const forbiddenParamSchema = lazySchema(() =>
|
|
10
|
+
zodSchema(
|
|
11
|
+
z.object({
|
|
12
|
+
ruleId: z.string(),
|
|
13
|
+
}),
|
|
14
|
+
),
|
|
15
|
+
);
|
|
16
|
+
|
|
7
17
|
/**
|
|
8
18
|
* Forbidden - the request was rejected by policy (e.g. a routing rule),
|
|
9
19
|
* not an authentication failure.
|
|
@@ -13,19 +23,23 @@ export class GatewayForbiddenError extends GatewayError {
|
|
|
13
23
|
|
|
14
24
|
readonly name = name;
|
|
15
25
|
readonly type = 'forbidden';
|
|
26
|
+
readonly ruleId?: string;
|
|
16
27
|
|
|
17
28
|
constructor({
|
|
18
29
|
message = 'Forbidden',
|
|
19
30
|
statusCode = 403,
|
|
20
31
|
cause,
|
|
21
32
|
generationId,
|
|
33
|
+
ruleId,
|
|
22
34
|
}: {
|
|
23
35
|
message?: string;
|
|
24
36
|
statusCode?: number;
|
|
25
37
|
cause?: unknown;
|
|
26
38
|
generationId?: string;
|
|
39
|
+
ruleId?: string;
|
|
27
40
|
} = {}) {
|
|
28
41
|
super({ message, statusCode, cause, generationId });
|
|
42
|
+
this.ruleId = ruleId;
|
|
29
43
|
}
|
|
30
44
|
|
|
31
45
|
static isInstance(error: unknown): error is GatewayForbiddenError {
|
|
@@ -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(),
|
|
@@ -156,6 +156,10 @@ export type GatewayModelId =
|
|
|
156
156
|
| 'openai/gpt-5.4-pro'
|
|
157
157
|
| 'openai/gpt-5.5'
|
|
158
158
|
| 'openai/gpt-5.5-pro'
|
|
159
|
+
| 'openai/gpt-5.6'
|
|
160
|
+
| 'openai/gpt-5.6-luna'
|
|
161
|
+
| 'openai/gpt-5.6-sol'
|
|
162
|
+
| 'openai/gpt-5.6-terra'
|
|
159
163
|
| 'openai/gpt-oss-120b'
|
|
160
164
|
| 'openai/gpt-oss-20b'
|
|
161
165
|
| 'openai/gpt-oss-safeguard-20b'
|
|
@@ -180,6 +184,7 @@ export type GatewayModelId =
|
|
|
180
184
|
| 'xai/grok-4.20-reasoning'
|
|
181
185
|
| 'xai/grok-4.20-reasoning-beta'
|
|
182
186
|
| 'xai/grok-4.3'
|
|
187
|
+
| 'xai/grok-4.5'
|
|
183
188
|
| 'xai/grok-build-0.1'
|
|
184
189
|
| 'xiaomi/mimo-v2-flash'
|
|
185
190
|
| 'xiaomi/mimo-v2-pro'
|
|
@@ -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
|
|
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
|
|
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
|
+
}
|