@ai-sdk/gateway 4.0.95 → 4.0.96
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 +7 -0
- package/dist/index.d.ts +8 -20
- package/dist/index.js +2 -3
- package/dist/index.js.map +1 -1
- package/docs/00-ai-gateway.mdx +4 -4
- package/package.json +1 -1
- package/src/gateway-provider-options.ts +8 -27
- package/src/index.ts +0 -1
package/docs/00-ai-gateway.mdx
CHANGED
|
@@ -1474,13 +1474,13 @@ The following gateway provider options are available:
|
|
|
1474
1474
|
|
|
1475
1475
|
- **models** _string[] | [GatewayModelFallback, ...string[]]_
|
|
1476
1476
|
|
|
1477
|
-
Specifies fallback models in attempt order. String entries keep their existing behavior: the gateway tries them when the primary model fails or is unavailable. Evaluation requests can also start the list with one conditional `{ model, when }` entry to retry a successful but uncertain evaluation 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-evaluation requests.
|
|
1477
|
+
Specifies fallback models in attempt order. String entries keep their existing behavior: the gateway tries them when the primary model fails or is unavailable. Evaluation requests can also start the list with one conditional `{ model, when }` entry to retry a successful but uncertain evaluation 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-evaluation requests.
|
|
1478
1478
|
|
|
1479
1479
|
Example: `models: ['openai/gpt-5.4-nano', 'google/gemini-3.8-flash']` will try the fallback models in order if the primary model fails.
|
|
1480
1480
|
|
|
1481
1481
|
A direct condition uses `{ question, confidenceBelow }` for Choice and Score questions, or `{ question, probabilityBetween: [minimum, maximum] }` for Boolean questions. Boolean probability is P(true), not confidence in the selected Boolean outcome. Bounds are inclusive, finite, ordered, and within `[0, 1]`.
|
|
1482
1482
|
|
|
1483
|
-
Combine conditions with `{ any: [...] }`, `{ all: [...] }`, or `{ atLeast: { count, conditions: [...] } }`. Each condition list holds 1 to 20 conditions. `atLeast.count` must be an integer from `1` through the number of conditions. Conditions nest at most 5 levels deep. Question IDs and the conditional `model`
|
|
1483
|
+
Combine conditions with `{ any: [...] }`, `{ all: [...] }`, or `{ atLeast: { count, conditions: [...] } }`. Each condition list holds 1 to 20 conditions. `atLeast.count` must be an integer from `1` through the number of conditions. Conditions nest at most 5 levels deep. Question IDs are 1 to 256 characters, and the conditional `model` must not be empty. The SDK checks these bounds before sending the request, and the gateway also checks that each question exists and has a kind that matches its condition. String error fallbacks may follow the conditional entry.
|
|
1484
1484
|
|
|
1485
1485
|
- **user** _string_
|
|
1486
1486
|
|
|
@@ -1619,7 +1619,7 @@ configuration under `providerOptions.gateway.models`. `experimental_evaluate`
|
|
|
1619
1619
|
does not have a top-level fallback option.
|
|
1620
1620
|
|
|
1621
1621
|
```ts
|
|
1622
|
-
import type {
|
|
1622
|
+
import type { GatewayProviderOptions } from '@ai-sdk/gateway';
|
|
1623
1623
|
import { experimental_evaluate } from 'ai';
|
|
1624
1624
|
|
|
1625
1625
|
const questions = {
|
|
@@ -1654,7 +1654,7 @@ const result = await experimental_evaluate({
|
|
|
1654
1654
|
},
|
|
1655
1655
|
},
|
|
1656
1656
|
],
|
|
1657
|
-
} satisfies
|
|
1657
|
+
} satisfies GatewayProviderOptions,
|
|
1658
1658
|
},
|
|
1659
1659
|
});
|
|
1660
1660
|
|
package/package.json
CHANGED
|
@@ -6,7 +6,6 @@ import { z } from './zod';
|
|
|
6
6
|
export const EVALUATION_FALLBACK_MAX_CONDITION_DEPTH = 5;
|
|
7
7
|
export const EVALUATION_FALLBACK_MAX_CONDITIONS_PER_LIST = 20;
|
|
8
8
|
export const EVALUATION_FALLBACK_MAX_QUESTION_LENGTH = 256;
|
|
9
|
-
export const EVALUATION_FALLBACK_MAX_MODEL_LENGTH = 256;
|
|
10
9
|
|
|
11
10
|
export const gatewayEvaluationProviderOptionsSchema = lazySchema(() =>
|
|
12
11
|
zodSchema(
|
|
@@ -45,7 +44,7 @@ export type GatewayModelFallback<QUESTION_ID extends string = string> =
|
|
|
45
44
|
when: EvaluationFallbackCondition<QUESTION_ID>;
|
|
46
45
|
};
|
|
47
46
|
|
|
48
|
-
export type GatewayProviderOptions = {
|
|
47
|
+
export type GatewayProviderOptions<QUESTION_ID extends string = string> = {
|
|
49
48
|
/**
|
|
50
49
|
* Service-owned options may be added by the Gateway without requiring an SDK
|
|
51
50
|
* release. The Gateway service validates and applies the runtime schema.
|
|
@@ -90,11 +89,13 @@ export type GatewayProviderOptions = {
|
|
|
90
89
|
idempotencyKey?: string;
|
|
91
90
|
|
|
92
91
|
/**
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
* `
|
|
92
|
+
* Fallback models to try in order. On evaluation requests, the first entry
|
|
93
|
+
* can be a conditional `{ model, when }` fallback that reruns the evaluation
|
|
94
|
+
* when `when` matches the primary answers. Other request types reject a
|
|
95
|
+
* conditional entry. Pass your question IDs as `QUESTION_ID` to check the
|
|
96
|
+
* `question` names in `when`.
|
|
96
97
|
*/
|
|
97
|
-
models?:
|
|
98
|
+
models?: GatewayModelFallbackList<QUESTION_ID>;
|
|
98
99
|
|
|
99
100
|
/** Array of provider slugs that are the only ones allowed to be used. */
|
|
100
101
|
only?: string[];
|
|
@@ -126,20 +127,6 @@ export type GatewayProviderOptions = {
|
|
|
126
127
|
zeroDataRetention?: boolean;
|
|
127
128
|
};
|
|
128
129
|
|
|
129
|
-
/**
|
|
130
|
-
* Gateway provider options for evaluation requests. Same as
|
|
131
|
-
* `GatewayProviderOptions`, except `models` may start with one conditional
|
|
132
|
-
* `{ model, when }` entry followed by string error fallbacks.
|
|
133
|
-
*
|
|
134
|
-
* The SDK validates `models` strictly before sending the request, so new
|
|
135
|
-
* condition shapes need an SDK release. Other keys pass through unchanged.
|
|
136
|
-
*/
|
|
137
|
-
export type GatewayEvaluationProviderOptions<
|
|
138
|
-
QUESTION_ID extends string = string,
|
|
139
|
-
> = GatewayProviderOptionsWithoutModels & {
|
|
140
|
-
models?: GatewayModelFallbackList<QUESTION_ID>;
|
|
141
|
-
};
|
|
142
|
-
|
|
143
130
|
type EvaluationFallbackConditionList<QUESTION_ID extends string> = [
|
|
144
131
|
EvaluationFallbackCondition<QUESTION_ID>,
|
|
145
132
|
...EvaluationFallbackCondition<QUESTION_ID>[],
|
|
@@ -158,12 +145,6 @@ type ExclusiveCondition<CONDITION> = CONDITION & {
|
|
|
158
145
|
[KEY in Exclude<ConditionKey, keyof CONDITION>]?: never;
|
|
159
146
|
};
|
|
160
147
|
|
|
161
|
-
type GatewayProviderOptionsWithoutModels = {
|
|
162
|
-
[KEY in keyof GatewayProviderOptions as KEY extends 'models'
|
|
163
|
-
? never
|
|
164
|
-
: KEY]: GatewayProviderOptions[KEY];
|
|
165
|
-
};
|
|
166
|
-
|
|
167
148
|
type ConditionalGatewayModelFallback<QUESTION_ID extends string> = Exclude<
|
|
168
149
|
GatewayModelFallback<QUESTION_ID>,
|
|
169
150
|
string
|
|
@@ -214,7 +195,7 @@ const groupBeyondMaxDepthSchema = z
|
|
|
214
195
|
|
|
215
196
|
const conditionalModelFallbackSchema = z
|
|
216
197
|
.object({
|
|
217
|
-
model: z.string().min(1)
|
|
198
|
+
model: z.string().min(1),
|
|
218
199
|
when: conditionSchema(1),
|
|
219
200
|
})
|
|
220
201
|
.strict();
|
package/src/index.ts
CHANGED