@ai-sdk/gateway 4.0.145 → 4.0.147
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 +18 -0
- package/dist/index.d.ts +39 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +101 -52
- package/dist/index.js.map +1 -1
- package/docs/00-ai-gateway.mdx +3 -3
- package/package.json +3 -3
- package/src/errors/create-gateway-error.ts +21 -0
- package/src/errors/gateway-access-policy-denied-error.ts +72 -0
- package/src/errors/index.ts +1 -0
- package/src/gateway-decision-model-settings.ts +2 -0
- package/src/gateway-language-model-settings.ts +4 -5
- package/src/index.ts +1 -0
package/docs/00-ai-gateway.mdx
CHANGED
|
@@ -1752,7 +1752,7 @@ The following gateway provider options are available:
|
|
|
1752
1752
|
|
|
1753
1753
|
Specifies fallback models in attempt order. String entries keep their existing behavior: the gateway tries them when the primary model fails or is unavailable. Decision requests can also start the list with one conditional `{ model, when }` entry to retry a successful but uncertain decision with another model. Only the first entry can be conditional, and only one conditional entry is allowed. If the primary model fails, the gateway also advances to the conditional entry under its existing error fallback behavior. Conditional entries are rejected on non-decision requests.
|
|
1754
1754
|
|
|
1755
|
-
Example: `models: ['openai/gpt-5.4-nano', 'google/gemini-
|
|
1755
|
+
Example: `models: ['openai/gpt-5.4-nano', 'google/gemini-4-hydrogen']` will try the fallback models in order if the primary model fails.
|
|
1756
1756
|
|
|
1757
1757
|
A direct condition uses `{ question, confidenceBelow }` for Choice and Score questions, or `{ question, probabilityBetween: [minimum, maximum] }` for Boolean questions. Leave out `question` to check every question of that type: `{ confidenceBelow: 0.6 }` matches when any Choice or Score answer is below 0.6, and a request with no Choice or Score questions never matches it. Boolean probability is P(true), not confidence in the selected Boolean outcome. Bounds are inclusive, finite, ordered, and within `[0, 1]`.
|
|
1758
1758
|
|
|
@@ -1880,7 +1880,7 @@ const { text } = await generateText({
|
|
|
1880
1880
|
prompt: 'Write a TypeScript haiku',
|
|
1881
1881
|
providerOptions: {
|
|
1882
1882
|
gateway: {
|
|
1883
|
-
models: ['openai/gpt-5.4-nano', 'google/gemini-
|
|
1883
|
+
models: ['openai/gpt-5.4-nano', 'google/gemini-4-hydrogen'], // Fallback models
|
|
1884
1884
|
} satisfies GatewayProviderOptions,
|
|
1885
1885
|
},
|
|
1886
1886
|
});
|
|
@@ -1888,7 +1888,7 @@ const { text } = await generateText({
|
|
|
1888
1888
|
// This will:
|
|
1889
1889
|
// 1. Try openai/gpt-6-astra first
|
|
1890
1890
|
// 2. If it fails, try openai/gpt-5.4-nano
|
|
1891
|
-
// 3. If that fails, try google/gemini-
|
|
1891
|
+
// 3. If that fails, try google/gemini-4-hydrogen
|
|
1892
1892
|
// 4. Return the result from the first model that succeeds
|
|
1893
1893
|
```
|
|
1894
1894
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/gateway",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "4.0.
|
|
4
|
+
"version": "4.0.147",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"sideEffects": false,
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
}
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@ai-sdk/provider": "4.0.
|
|
34
|
-
"@ai-sdk/provider-utils": "5.0.
|
|
33
|
+
"@ai-sdk/provider": "4.0.39",
|
|
34
|
+
"@ai-sdk/provider-utils": "5.0.82",
|
|
35
35
|
"@vercel/oidc": "3.2.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
@@ -14,6 +14,10 @@ import {
|
|
|
14
14
|
GatewayForbiddenError,
|
|
15
15
|
forbiddenParamSchema,
|
|
16
16
|
} from './gateway-forbidden-error';
|
|
17
|
+
import {
|
|
18
|
+
GatewayAccessPolicyDeniedError,
|
|
19
|
+
accessPolicyDeniedParamSchema,
|
|
20
|
+
} from './gateway-access-policy-denied-error';
|
|
17
21
|
import { GatewayResponseError } from './gateway-response-error';
|
|
18
22
|
import {
|
|
19
23
|
lazySchema,
|
|
@@ -138,6 +142,23 @@ export async function createGatewayErrorFromResponse({
|
|
|
138
142
|
ruleId: ruleResult.success ? ruleResult.value.ruleId : undefined,
|
|
139
143
|
});
|
|
140
144
|
}
|
|
145
|
+
case 'access_policy_denied': {
|
|
146
|
+
const paramResult = await safeValidateTypes({
|
|
147
|
+
value: validatedResponse.error.param,
|
|
148
|
+
schema: accessPolicyDeniedParamSchema,
|
|
149
|
+
});
|
|
150
|
+
const param = paramResult.success ? paramResult.value : undefined;
|
|
151
|
+
|
|
152
|
+
return new GatewayAccessPolicyDeniedError({
|
|
153
|
+
message,
|
|
154
|
+
statusCode,
|
|
155
|
+
cause,
|
|
156
|
+
generationId,
|
|
157
|
+
policyIds: param?.policyIds,
|
|
158
|
+
removedModels: param?.removedModels,
|
|
159
|
+
removedProviders: param?.removedProviders,
|
|
160
|
+
});
|
|
161
|
+
}
|
|
141
162
|
default:
|
|
142
163
|
return new GatewayInternalServerError({
|
|
143
164
|
message,
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { z } from '../zod';
|
|
2
|
+
import { GatewayError } from './gateway-error';
|
|
3
|
+
import { lazySchema, zodSchema } from '@ai-sdk/provider-utils';
|
|
4
|
+
|
|
5
|
+
const name = 'GatewayAccessPolicyDeniedError';
|
|
6
|
+
const marker = `vercel.ai.gateway.error.${name}`;
|
|
7
|
+
const symbol = Symbol.for(marker);
|
|
8
|
+
|
|
9
|
+
// Unknown keys in `param` are ignored, and each field may be absent.
|
|
10
|
+
export const accessPolicyDeniedParamSchema = lazySchema(() =>
|
|
11
|
+
zodSchema(
|
|
12
|
+
z.object({
|
|
13
|
+
policyIds: z.optional(z.array(z.string())),
|
|
14
|
+
removedModels: z.optional(z.array(z.string())),
|
|
15
|
+
removedProviders: z.optional(z.array(z.string())),
|
|
16
|
+
}),
|
|
17
|
+
),
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Access policy denied - an AI Gateway access policy that applies to the
|
|
22
|
+
* request does not allow the requested model or provider.
|
|
23
|
+
*/
|
|
24
|
+
export class GatewayAccessPolicyDeniedError extends GatewayError {
|
|
25
|
+
private readonly [symbol] = true; // used in isInstance
|
|
26
|
+
|
|
27
|
+
readonly name = name;
|
|
28
|
+
readonly type = 'access_policy_denied';
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* IDs of the access policies that denied the request, when the gateway
|
|
32
|
+
* includes them.
|
|
33
|
+
*/
|
|
34
|
+
readonly policyIds?: string[];
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Models the access policies removed, when the gateway includes them.
|
|
38
|
+
*/
|
|
39
|
+
readonly removedModels?: string[];
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Providers the access policies removed, when the gateway includes them.
|
|
43
|
+
*/
|
|
44
|
+
readonly removedProviders?: string[];
|
|
45
|
+
|
|
46
|
+
constructor({
|
|
47
|
+
message = 'Access policy denied',
|
|
48
|
+
statusCode = 403,
|
|
49
|
+
cause,
|
|
50
|
+
generationId,
|
|
51
|
+
policyIds,
|
|
52
|
+
removedModels,
|
|
53
|
+
removedProviders,
|
|
54
|
+
}: {
|
|
55
|
+
message?: string;
|
|
56
|
+
statusCode?: number;
|
|
57
|
+
cause?: unknown;
|
|
58
|
+
generationId?: string;
|
|
59
|
+
policyIds?: string[];
|
|
60
|
+
removedModels?: string[];
|
|
61
|
+
removedProviders?: string[];
|
|
62
|
+
} = {}) {
|
|
63
|
+
super({ message, statusCode, cause, generationId });
|
|
64
|
+
this.policyIds = policyIds;
|
|
65
|
+
this.removedModels = removedModels;
|
|
66
|
+
this.removedProviders = removedProviders;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
static isInstance(error: unknown): error is GatewayAccessPolicyDeniedError {
|
|
70
|
+
return GatewayError.hasMarker(error) && symbol in error;
|
|
71
|
+
}
|
|
72
|
+
}
|
package/src/errors/index.ts
CHANGED
|
@@ -5,6 +5,7 @@ export {
|
|
|
5
5
|
} from './create-gateway-error';
|
|
6
6
|
export { extractApiCallResponse } from './extract-api-call-response';
|
|
7
7
|
export { GatewayError } from './gateway-error';
|
|
8
|
+
export { GatewayAccessPolicyDeniedError } from './gateway-access-policy-denied-error';
|
|
8
9
|
export { GatewayAuthenticationError } from './gateway-authentication-error';
|
|
9
10
|
export { GatewayFailedDependencyError } from './gateway-failed-dependency-error';
|
|
10
11
|
export { GatewayForbiddenError } from './gateway-forbidden-error';
|
|
@@ -13,7 +13,9 @@ export type GatewayDecisionModelId =
|
|
|
13
13
|
| 'openai/gpt-6-luna-decisions'
|
|
14
14
|
| 'parallel/parallel-decisions-fast'
|
|
15
15
|
| 'perplexity/pplx-decider-flash-v1.2'
|
|
16
|
+
| 'perplexity/pplx-decider-flash-v1.3'
|
|
16
17
|
| 'perplexity/pplx-decider-v1.2'
|
|
18
|
+
| 'perplexity/pplx-decider-v1.3'
|
|
17
19
|
| 'scaledown/scaledown-classify-1'
|
|
18
20
|
| 'typesafe-ai/jev'
|
|
19
21
|
| 'typesafe-ai/jev-1.13.0'
|
|
@@ -25,6 +25,7 @@ export type GatewayModelId =
|
|
|
25
25
|
| 'alibaba/qwen3.8-max-0902'
|
|
26
26
|
| 'alibaba/qwen3.8-max-prime'
|
|
27
27
|
| 'alibaba/qwen3.8-omni-flash'
|
|
28
|
+
| 'alibaba/qwen4-max'
|
|
28
29
|
| 'amazon/nova-2-lite'
|
|
29
30
|
| 'amazon/nova-lite'
|
|
30
31
|
| 'amazon/nova-micro'
|
|
@@ -114,10 +115,7 @@ export type GatewayModelId =
|
|
|
114
115
|
| 'google/gemma-4-26b-a4b-it'
|
|
115
116
|
| 'google/gemma-4-31b-it'
|
|
116
117
|
| 'humansand/ampersand-v0.1'
|
|
117
|
-
| 'inception/mercury-2'
|
|
118
|
-
| 'inception/mercury-2.5'
|
|
119
118
|
| 'inception/mercury-3'
|
|
120
|
-
| 'inception/mercury-coder-small'
|
|
121
119
|
| 'inclusionai/ling-3.0-flash'
|
|
122
120
|
| 'inclusionai/ling-3.0-flash-fin'
|
|
123
121
|
| 'inclusionai/ling-3.0-flash-sante'
|
|
@@ -173,7 +171,6 @@ export type GatewayModelId =
|
|
|
173
171
|
| 'moonshotai/kimi-k3.1-pro-highspeed'
|
|
174
172
|
| 'morph/morph-v3-fast'
|
|
175
173
|
| 'morph/morph-v3-large'
|
|
176
|
-
| 'nvidia/nemotron-3-nano-30b-a3b'
|
|
177
174
|
| 'nvidia/nemotron-3-super-120b-a12b'
|
|
178
175
|
| 'nvidia/nemotron-3-ultra-550b-a55b'
|
|
179
176
|
| 'nvidia/nemotron-3.5-lightning'
|
|
@@ -264,9 +261,9 @@ export type GatewayModelId =
|
|
|
264
261
|
| 'openai/o3-mini'
|
|
265
262
|
| 'openai/o3-pro'
|
|
266
263
|
| 'openai/o4-mini'
|
|
264
|
+
| 'paperinstruments/ultramarine-1-flash'
|
|
267
265
|
| 'particle/particle-1'
|
|
268
266
|
| 'perplexity/sonar'
|
|
269
|
-
| 'poolside/laguna-s-2.1'
|
|
270
267
|
| 'quiverai/arrow-2'
|
|
271
268
|
| 'quiverai/arrow-2-telos'
|
|
272
269
|
| 'reflection/beam'
|
|
@@ -300,8 +297,10 @@ export type GatewayModelId =
|
|
|
300
297
|
| 'tencent/hy-mt2-pro'
|
|
301
298
|
| 'tencent/hy3'
|
|
302
299
|
| 'tencent/hy4'
|
|
300
|
+
| 'tencent/hy4-flash'
|
|
303
301
|
| 'tencent/hy4-preview'
|
|
304
302
|
| 'thinkingmachines/inkling'
|
|
303
|
+
| 'thinkingmachines/inkling-2-small'
|
|
305
304
|
| 'thinkingmachines/inkling-small'
|
|
306
305
|
| 'xiaomi/mimo-v2.6-flash'
|
|
307
306
|
| 'xiaomi/mimo-v2.6-pro'
|