@ai-sdk/gateway 4.0.104 → 4.0.106
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 +24 -0
- package/dist/index.d.ts +8 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +23 -4
- package/dist/index.js.map +1 -1
- package/docs/00-ai-gateway.mdx +9 -0
- package/package.json +5 -5
- package/src/gateway-batch.ts +4 -1
- package/src/gateway-decision-model.ts +3 -0
- package/src/gateway-embedding-model-settings.ts +2 -0
- package/src/gateway-image-model-settings.ts +1 -0
- package/src/gateway-language-model-settings.ts +2 -0
- package/src/gateway-provider.ts +7 -0
- package/src/gateway-transcription-model.ts +48 -1
package/docs/00-ai-gateway.mdx
CHANGED
|
@@ -78,6 +78,15 @@ const gateway = createGateway({
|
|
|
78
78
|
|
|
79
79
|
You can use the following optional settings to customize the AI Gateway provider instance:
|
|
80
80
|
|
|
81
|
+
- **batchResultDownloads** _object_
|
|
82
|
+
|
|
83
|
+
Settings for downloading JSON Lines batch results.
|
|
84
|
+
- **maxLineBytes** _number_
|
|
85
|
+
|
|
86
|
+
Maximum UTF-8 bytes per row, excluding the LF delimiter. Defaults to 64 MiB
|
|
87
|
+
(67,108,864 bytes). Must be a positive safe integer. Oversized rows throw a
|
|
88
|
+
`DownloadError` and cancel the download.
|
|
89
|
+
|
|
81
90
|
- **baseURL** _string_
|
|
82
91
|
|
|
83
92
|
Use a different URL prefix for API calls. The default prefix is `https://ai-gateway.vercel.sh/v4/ai`.
|
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.106",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"sideEffects": false,
|
|
@@ -30,17 +30,17 @@
|
|
|
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.24",
|
|
34
|
+
"@ai-sdk/provider-utils": "5.0.56",
|
|
35
35
|
"@vercel/oidc": "3.2.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@ai-sdk/test-server": "2.0.
|
|
38
|
+
"@ai-sdk/test-server": "2.0.4",
|
|
39
39
|
"@types/node": "22.19.19",
|
|
40
40
|
"@vercel/ai-tsconfig": "0.0.0",
|
|
41
41
|
"tsdown": "^0.23.0",
|
|
42
42
|
"tsx": "4.23.12",
|
|
43
|
-
"typescript": "
|
|
43
|
+
"typescript": "6.0.3",
|
|
44
44
|
"zod": "3.25.76"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
package/src/gateway-batch.ts
CHANGED
|
@@ -35,7 +35,9 @@ export class GatewayBatch implements BatchV4<{ text: GatewayModelId }> {
|
|
|
35
35
|
readonly provider: string;
|
|
36
36
|
readonly supportedUrls = { '*/*': [/.*/] };
|
|
37
37
|
|
|
38
|
-
constructor(
|
|
38
|
+
constructor(
|
|
39
|
+
private readonly config: GatewayChatConfig & { maxLineBytes?: number },
|
|
40
|
+
) {
|
|
39
41
|
this.provider = `${config.provider}.batch`;
|
|
40
42
|
}
|
|
41
43
|
|
|
@@ -191,6 +193,7 @@ export class GatewayBatch implements BatchV4<{ text: GatewayModelId }> {
|
|
|
191
193
|
body: { batchId },
|
|
192
194
|
successfulResponseHandler: createJsonLinesResponseHandler(
|
|
193
195
|
gatewayBatchItemResultLineSchema,
|
|
196
|
+
{ maxLineBytes: this.config.maxLineBytes },
|
|
194
197
|
),
|
|
195
198
|
failedResponseHandler: createJsonErrorResponseHandler({
|
|
196
199
|
errorSchema: z.any(),
|
|
@@ -142,6 +142,9 @@ const gatewayDecisionAnswerSchema = z.discriminatedUnion('type', [
|
|
|
142
142
|
type: z.literal('boolean'),
|
|
143
143
|
probability: z.number(),
|
|
144
144
|
}),
|
|
145
|
+
z.object({
|
|
146
|
+
type: z.literal('refusal'),
|
|
147
|
+
}),
|
|
145
148
|
]);
|
|
146
149
|
|
|
147
150
|
const gatewayDecisionWarningSchema = z.discriminatedUnion('type', [
|
|
@@ -4,6 +4,8 @@ export type GatewayEmbeddingModelId =
|
|
|
4
4
|
| 'alibaba/qwen3-embedding-8b'
|
|
5
5
|
| 'amazon/titan-embed-text-v2'
|
|
6
6
|
| 'cohere/embed-v4.0'
|
|
7
|
+
| 'cohere/embed-v5.0-fast'
|
|
8
|
+
| 'cohere/embed-v5.0-pro'
|
|
7
9
|
| 'google/gemini-embedding-001'
|
|
8
10
|
| 'google/gemini-embedding-2'
|
|
9
11
|
| 'google/text-embedding-005'
|
|
@@ -88,6 +88,7 @@ export type GatewayModelId =
|
|
|
88
88
|
| 'google/gemini-3.6-flash'
|
|
89
89
|
| 'google/gemini-3.7-flash'
|
|
90
90
|
| 'google/gemini-3.8-flash'
|
|
91
|
+
| 'google/gemini-nano-banana-2.1'
|
|
91
92
|
| 'google/gemini-omni-flash-preview'
|
|
92
93
|
| 'google/gemma-4-26b-a4b-it'
|
|
93
94
|
| 'google/gemma-4-31b-it'
|
|
@@ -128,6 +129,7 @@ export type GatewayModelId =
|
|
|
128
129
|
| 'mistral/ministral-3b'
|
|
129
130
|
| 'mistral/ministral-8b'
|
|
130
131
|
| 'mistral/mistral-large-3'
|
|
132
|
+
| 'mistral/mistral-large-4'
|
|
131
133
|
| 'mistral/mistral-medium-3.5'
|
|
132
134
|
| 'mistral/mistral-nemo'
|
|
133
135
|
| 'mistral/mistral-small'
|
package/src/gateway-provider.ts
CHANGED
|
@@ -251,6 +251,12 @@ export interface GatewayTranscriptionFactory {
|
|
|
251
251
|
}
|
|
252
252
|
|
|
253
253
|
export interface GatewayProviderSettings {
|
|
254
|
+
/** Settings for downloading JSON Lines batch results. */
|
|
255
|
+
batchResultDownloads?: {
|
|
256
|
+
/** Maximum UTF-8 bytes per row, excluding LF. Defaults to 64 MiB. */
|
|
257
|
+
maxLineBytes?: number;
|
|
258
|
+
};
|
|
259
|
+
|
|
254
260
|
/**
|
|
255
261
|
* The base URL prefix for API calls. Defaults to `https://ai-gateway.vercel.sh/v4/ai`.
|
|
256
262
|
*/
|
|
@@ -457,6 +463,7 @@ export function createGateway(
|
|
|
457
463
|
const createBatch = () =>
|
|
458
464
|
new GatewayBatch({
|
|
459
465
|
provider: 'gateway',
|
|
466
|
+
maxLineBytes: options.batchResultDownloads?.maxLineBytes,
|
|
460
467
|
baseURL,
|
|
461
468
|
headers: getHeaders,
|
|
462
469
|
fetch: options.fetch,
|
|
@@ -99,12 +99,28 @@ export class GatewayTranscriptionModel implements TranscriptionModelV4 {
|
|
|
99
99
|
fetch: this.config.fetch,
|
|
100
100
|
});
|
|
101
101
|
|
|
102
|
+
const warnings = [
|
|
103
|
+
...(responseBody.warnings ?? []),
|
|
104
|
+
] as Array<SharedV4Warning>;
|
|
105
|
+
if (
|
|
106
|
+
isXaiTranscriptionModel(this.modelId) &&
|
|
107
|
+
requestsXaiDiarization(providerOptions) &&
|
|
108
|
+
!containsSpeaker(rawValue)
|
|
109
|
+
) {
|
|
110
|
+
warnings.push({
|
|
111
|
+
type: 'unsupported',
|
|
112
|
+
feature: 'providerOptions.xai.diarize',
|
|
113
|
+
details:
|
|
114
|
+
'AI Gateway does not currently expose xAI speaker diarization metadata.',
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
102
118
|
return {
|
|
103
119
|
text: responseBody.text,
|
|
104
120
|
segments: responseBody.segments ?? [],
|
|
105
121
|
language: responseBody.language ?? undefined,
|
|
106
122
|
durationInSeconds: responseBody.durationInSeconds ?? undefined,
|
|
107
|
-
warnings
|
|
123
|
+
warnings,
|
|
108
124
|
...(responseBody.usage != null && { usage: responseBody.usage }),
|
|
109
125
|
providerMetadata:
|
|
110
126
|
responseBody.providerMetadata as SharedV4ProviderMetadata,
|
|
@@ -177,6 +193,37 @@ export class GatewayTranscriptionModel implements TranscriptionModelV4 {
|
|
|
177
193
|
}
|
|
178
194
|
}
|
|
179
195
|
|
|
196
|
+
function isXaiTranscriptionModel(modelId: string): boolean {
|
|
197
|
+
return modelId.startsWith('spacexai/') || modelId.startsWith('xai/');
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function requestsXaiDiarization(
|
|
201
|
+
providerOptions:
|
|
202
|
+
| Parameters<TranscriptionModelV4['doGenerate']>[0]['providerOptions']
|
|
203
|
+
| undefined,
|
|
204
|
+
): boolean {
|
|
205
|
+
return (
|
|
206
|
+
providerOptions?.xai?.diarize === true ||
|
|
207
|
+
providerOptions?.spacexai?.diarize === true
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function containsSpeaker(value: unknown): boolean {
|
|
212
|
+
if (Array.isArray(value)) {
|
|
213
|
+
return value.some(containsSpeaker);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (value == null || typeof value !== 'object') {
|
|
217
|
+
return false;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
return Object.entries(value).some(
|
|
221
|
+
([key, nestedValue]) =>
|
|
222
|
+
(key === 'speaker' && nestedValue != null) ||
|
|
223
|
+
containsSpeaker(nestedValue),
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
|
|
180
227
|
/**
|
|
181
228
|
* Gateway streaming transcription WebSocket URL: HTTP(S) base upgraded to
|
|
182
229
|
* WS(S), model id in `?ai-model-id=` (browser `WebSocket` cannot set headers;
|