@ai-sdk/gateway 4.0.101 → 4.0.102
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 +16 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -4
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/gateway-evaluation-model-settings.ts +4 -1
- package/src/gateway-fetch-metadata.ts +31 -4
- package/src/gateway-language-model-settings.ts +4 -1
- package/src/gateway-speech-model.ts +2 -0
- package/src/gateway-transcription-model.ts +2 -0
- package/src/zod.ts +2 -0
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.102",
|
|
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.21",
|
|
34
|
+
"@ai-sdk/provider-utils": "5.0.53",
|
|
35
35
|
"@vercel/oidc": "3.2.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
import { z } from './zod';
|
|
11
11
|
import { asGatewayError } from './errors';
|
|
12
12
|
import type { GatewayConfig } from './gateway-config';
|
|
13
|
+
import { VERCEL_AI_GATEWAY_TEAM_HEADER } from './gateway-headers';
|
|
13
14
|
import {
|
|
14
15
|
KNOWN_MODEL_TYPES,
|
|
15
16
|
type GatewayLanguageModelEntry,
|
|
@@ -58,13 +59,27 @@ export class GatewayFetchMetadata {
|
|
|
58
59
|
async getCredits(): Promise<GatewayCreditsResponse> {
|
|
59
60
|
try {
|
|
60
61
|
const baseUrl = new URL(this.config.baseURL);
|
|
62
|
+
const headers = this.config.headers
|
|
63
|
+
? await resolve(this.config.headers)
|
|
64
|
+
: undefined;
|
|
65
|
+
|
|
66
|
+
// The credits endpoint selects the team from the `teamId` / `slug`
|
|
67
|
+
// query parameter rather than the team header, so forward it there.
|
|
68
|
+
// Without it, tokens that can access multiple teams (e.g. Vercel access
|
|
69
|
+
// tokens) cannot be scoped to a team and the request is rejected.
|
|
70
|
+
const url = new URL('/v1/credits', baseUrl.origin);
|
|
71
|
+
const teamIdOrSlug = getTeamIdOrSlug(headers);
|
|
72
|
+
if (teamIdOrSlug) {
|
|
73
|
+
url.searchParams.set(
|
|
74
|
+
teamIdOrSlug.startsWith('team_') ? 'teamId' : 'slug',
|
|
75
|
+
teamIdOrSlug,
|
|
76
|
+
);
|
|
77
|
+
}
|
|
61
78
|
|
|
62
79
|
const { value } = await getFromApi({
|
|
63
|
-
url:
|
|
80
|
+
url: url.toString(),
|
|
64
81
|
validateUrl: false,
|
|
65
|
-
headers
|
|
66
|
-
? await resolve(this.config.headers)
|
|
67
|
-
: undefined,
|
|
82
|
+
headers,
|
|
68
83
|
successfulResponseHandler: createJsonResponseHandler(
|
|
69
84
|
gatewayCreditsResponseSchema,
|
|
70
85
|
),
|
|
@@ -82,6 +97,18 @@ export class GatewayFetchMetadata {
|
|
|
82
97
|
}
|
|
83
98
|
}
|
|
84
99
|
|
|
100
|
+
function getTeamIdOrSlug(
|
|
101
|
+
headers: Record<string, string | undefined> | undefined,
|
|
102
|
+
): string | undefined {
|
|
103
|
+
if (!headers) return undefined;
|
|
104
|
+
for (const [name, value] of Object.entries(headers)) {
|
|
105
|
+
if (name.toLowerCase() === VERCEL_AI_GATEWAY_TEAM_HEADER) {
|
|
106
|
+
return value?.trim() || undefined;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return undefined;
|
|
110
|
+
}
|
|
111
|
+
|
|
85
112
|
const gatewayAvailableModelsResponseSchema = lazySchema(() =>
|
|
86
113
|
zodSchema(
|
|
87
114
|
z.object({
|
|
@@ -98,6 +98,8 @@ export type GatewayModelId =
|
|
|
98
98
|
| 'inclusionai/ling-3.0-flash-sante'
|
|
99
99
|
| 'inclusionai/ling-3.0-flash-sante-free'
|
|
100
100
|
| 'inclusionai/ling-3.0-flash-vl'
|
|
101
|
+
| 'inclusionai/ling-3.1-flash'
|
|
102
|
+
| 'inclusionai/ling-3.1-flash-free'
|
|
101
103
|
| 'inference-net/schematron-v2-small'
|
|
102
104
|
| 'inference-net/schematron-v2-turbo'
|
|
103
105
|
| 'interfaze/interfaze-beta'
|
|
@@ -193,11 +195,12 @@ export type GatewayModelId =
|
|
|
193
195
|
| 'openai/gpt-5.6-terra-fast'
|
|
194
196
|
| 'openai/gpt-6-astra'
|
|
195
197
|
| 'openai/gpt-6-astra-fast'
|
|
196
|
-
| 'openai/gpt-6.1-sol'
|
|
197
198
|
| 'openai/gpt-6-luna'
|
|
198
199
|
| 'openai/gpt-6-luna-fast'
|
|
199
200
|
| 'openai/gpt-6-sol'
|
|
200
201
|
| 'openai/gpt-6-sol-fast'
|
|
202
|
+
| 'openai/gpt-6.1-sol'
|
|
203
|
+
| 'openai/gpt-6.1-sol-fast'
|
|
201
204
|
| 'openai/gpt-oss-120b'
|
|
202
205
|
| 'openai/gpt-oss-20b'
|
|
203
206
|
| 'openai/gpt-oss-safeguard-120b'
|
|
@@ -84,6 +84,7 @@ export class GatewaySpeechModel implements SpeechModelV4 {
|
|
|
84
84
|
return {
|
|
85
85
|
audio: responseBody.audio,
|
|
86
86
|
warnings: (responseBody.warnings ?? []) as Array<SharedV4Warning>,
|
|
87
|
+
...(responseBody.usage != null && { usage: responseBody.usage }),
|
|
87
88
|
providerMetadata:
|
|
88
89
|
responseBody.providerMetadata as SharedV4ProviderMetadata,
|
|
89
90
|
response: {
|
|
@@ -140,6 +141,7 @@ const gatewaySpeechWarningSchema = z.discriminatedUnion('type', [
|
|
|
140
141
|
const gatewaySpeechResponseSchema = z.object({
|
|
141
142
|
audio: z.string(),
|
|
142
143
|
warnings: z.array(gatewaySpeechWarningSchema).optional(),
|
|
144
|
+
usage: z.record(z.string(), z.json()).optional(),
|
|
143
145
|
providerMetadata: z
|
|
144
146
|
.record(z.string(), providerMetadataEntrySchema)
|
|
145
147
|
.optional(),
|
|
@@ -105,6 +105,7 @@ export class GatewayTranscriptionModel implements TranscriptionModelV4 {
|
|
|
105
105
|
language: responseBody.language ?? undefined,
|
|
106
106
|
durationInSeconds: responseBody.durationInSeconds ?? undefined,
|
|
107
107
|
warnings: (responseBody.warnings ?? []) as Array<SharedV4Warning>,
|
|
108
|
+
...(responseBody.usage != null && { usage: responseBody.usage }),
|
|
108
109
|
providerMetadata:
|
|
109
110
|
responseBody.providerMetadata as SharedV4ProviderMetadata,
|
|
110
111
|
response: {
|
|
@@ -433,6 +434,7 @@ const gatewayTranscriptionResponseSchema = z.object({
|
|
|
433
434
|
language: z.string().nullish(),
|
|
434
435
|
durationInSeconds: z.number().nullish(),
|
|
435
436
|
warnings: z.array(gatewayTranscriptionWarningSchema).optional(),
|
|
437
|
+
usage: z.record(z.string(), z.json()).optional(),
|
|
436
438
|
providerMetadata: z
|
|
437
439
|
.record(z.string(), providerMetadataEntrySchema)
|
|
438
440
|
.optional(),
|
package/src/zod.ts
CHANGED