@ai-sdk/gateway 4.0.0-beta.4 → 4.0.0-beta.41
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 +252 -4
- package/dist/index.d.mts +143 -21
- package/dist/index.d.ts +143 -21
- package/dist/index.js +454 -144
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +518 -186
- package/dist/index.mjs.map +1 -1
- package/docs/00-ai-gateway.mdx +292 -44
- package/package.json +4 -6
- package/src/gateway-embedding-model-settings.ts +1 -0
- package/src/gateway-embedding-model.ts +8 -8
- package/src/gateway-fetch-metadata.ts +1 -1
- package/src/gateway-generation-info.ts +147 -0
- package/src/gateway-image-model-settings.ts +6 -0
- package/src/gateway-image-model.ts +10 -10
- package/src/gateway-language-model-settings.ts +21 -10
- package/src/gateway-language-model.ts +19 -19
- package/src/gateway-model-entry.ts +2 -2
- package/src/gateway-provider-options.ts +27 -8
- package/src/gateway-provider.ts +99 -17
- package/src/gateway-reranking-model-settings.ts +1 -0
- package/src/gateway-reranking-model.ts +114 -0
- package/src/gateway-spend-report.ts +191 -0
- package/src/gateway-video-model.ts +15 -15
- package/src/index.ts +13 -3
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createJsonErrorResponseHandler,
|
|
3
|
+
createJsonResponseHandler,
|
|
4
|
+
getFromApi,
|
|
5
|
+
lazySchema,
|
|
6
|
+
resolve,
|
|
7
|
+
zodSchema,
|
|
8
|
+
} from '@ai-sdk/provider-utils';
|
|
9
|
+
import { z } from 'zod/v4';
|
|
10
|
+
import { asGatewayError } from './errors';
|
|
11
|
+
import type { GatewayConfig } from './gateway-config';
|
|
12
|
+
|
|
13
|
+
export interface GatewayGenerationInfoParams {
|
|
14
|
+
/** The generation ID to look up (format: gen_<ulid>) */
|
|
15
|
+
id: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface GatewayGenerationInfo {
|
|
19
|
+
/** The generation ID */
|
|
20
|
+
id: string;
|
|
21
|
+
/** Total cost in USD */
|
|
22
|
+
totalCost: number;
|
|
23
|
+
/** Upstream inference cost in USD (BYOK only) */
|
|
24
|
+
upstreamInferenceCost: number;
|
|
25
|
+
/** Usage cost in USD (same as totalCost) */
|
|
26
|
+
usage: number;
|
|
27
|
+
/** ISO 8601 timestamp when the generation was created */
|
|
28
|
+
createdAt: string;
|
|
29
|
+
/** Model identifier */
|
|
30
|
+
model: string;
|
|
31
|
+
/** Whether BYOK credentials were used */
|
|
32
|
+
isByok: boolean;
|
|
33
|
+
/** Provider that served this generation */
|
|
34
|
+
providerName: string;
|
|
35
|
+
/** Whether streaming was used */
|
|
36
|
+
streamed: boolean;
|
|
37
|
+
/** Finish reason (e.g. 'stop') */
|
|
38
|
+
finishReason: string;
|
|
39
|
+
/** Time to first token in milliseconds */
|
|
40
|
+
latency: number;
|
|
41
|
+
/** Total generation time in milliseconds */
|
|
42
|
+
generationTime: number;
|
|
43
|
+
/** Number of prompt tokens */
|
|
44
|
+
promptTokens: number;
|
|
45
|
+
/** Number of completion tokens */
|
|
46
|
+
completionTokens: number;
|
|
47
|
+
/** Reasoning tokens used */
|
|
48
|
+
reasoningTokens: number;
|
|
49
|
+
/** Cached tokens used */
|
|
50
|
+
cachedTokens: number;
|
|
51
|
+
/** Cache creation input tokens */
|
|
52
|
+
cacheCreationTokens: number;
|
|
53
|
+
/** Billable web search calls */
|
|
54
|
+
billableWebSearchCalls: number;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export class GatewayGenerationInfoFetcher {
|
|
58
|
+
constructor(private readonly config: GatewayConfig) {}
|
|
59
|
+
|
|
60
|
+
async getGenerationInfo(
|
|
61
|
+
params: GatewayGenerationInfoParams,
|
|
62
|
+
): Promise<GatewayGenerationInfo> {
|
|
63
|
+
try {
|
|
64
|
+
const baseUrl = new URL(this.config.baseURL);
|
|
65
|
+
|
|
66
|
+
const { value } = await getFromApi({
|
|
67
|
+
url: `${baseUrl.origin}/v1/generation?id=${encodeURIComponent(params.id)}`,
|
|
68
|
+
headers: await resolve(this.config.headers()),
|
|
69
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
70
|
+
gatewayGenerationInfoResponseSchema,
|
|
71
|
+
),
|
|
72
|
+
failedResponseHandler: createJsonErrorResponseHandler({
|
|
73
|
+
errorSchema: z.any(),
|
|
74
|
+
errorToMessage: data => data,
|
|
75
|
+
}),
|
|
76
|
+
fetch: this.config.fetch,
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
return value;
|
|
80
|
+
} catch (error) {
|
|
81
|
+
throw await asGatewayError(error);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const gatewayGenerationInfoResponseSchema = lazySchema(() =>
|
|
87
|
+
zodSchema(
|
|
88
|
+
z
|
|
89
|
+
.object({
|
|
90
|
+
data: z
|
|
91
|
+
.object({
|
|
92
|
+
id: z.string(),
|
|
93
|
+
total_cost: z.number(),
|
|
94
|
+
upstream_inference_cost: z.number(),
|
|
95
|
+
usage: z.number(),
|
|
96
|
+
created_at: z.string(),
|
|
97
|
+
model: z.string(),
|
|
98
|
+
is_byok: z.boolean(),
|
|
99
|
+
provider_name: z.string(),
|
|
100
|
+
streamed: z.boolean(),
|
|
101
|
+
finish_reason: z.string(),
|
|
102
|
+
latency: z.number(),
|
|
103
|
+
generation_time: z.number(),
|
|
104
|
+
native_tokens_prompt: z.number(),
|
|
105
|
+
native_tokens_completion: z.number(),
|
|
106
|
+
native_tokens_reasoning: z.number(),
|
|
107
|
+
native_tokens_cached: z.number(),
|
|
108
|
+
native_tokens_cache_creation: z.number(),
|
|
109
|
+
billable_web_search_calls: z.number(),
|
|
110
|
+
})
|
|
111
|
+
.transform(
|
|
112
|
+
({
|
|
113
|
+
total_cost,
|
|
114
|
+
upstream_inference_cost,
|
|
115
|
+
created_at,
|
|
116
|
+
is_byok,
|
|
117
|
+
provider_name,
|
|
118
|
+
finish_reason,
|
|
119
|
+
generation_time,
|
|
120
|
+
native_tokens_prompt,
|
|
121
|
+
native_tokens_completion,
|
|
122
|
+
native_tokens_reasoning,
|
|
123
|
+
native_tokens_cached,
|
|
124
|
+
native_tokens_cache_creation,
|
|
125
|
+
billable_web_search_calls,
|
|
126
|
+
...rest
|
|
127
|
+
}) => ({
|
|
128
|
+
...rest,
|
|
129
|
+
totalCost: total_cost,
|
|
130
|
+
upstreamInferenceCost: upstream_inference_cost,
|
|
131
|
+
createdAt: created_at,
|
|
132
|
+
isByok: is_byok,
|
|
133
|
+
providerName: provider_name,
|
|
134
|
+
finishReason: finish_reason,
|
|
135
|
+
generationTime: generation_time,
|
|
136
|
+
promptTokens: native_tokens_prompt,
|
|
137
|
+
completionTokens: native_tokens_completion,
|
|
138
|
+
reasoningTokens: native_tokens_reasoning,
|
|
139
|
+
cachedTokens: native_tokens_cached,
|
|
140
|
+
cacheCreationTokens: native_tokens_cache_creation,
|
|
141
|
+
billableWebSearchCalls: billable_web_search_calls,
|
|
142
|
+
}),
|
|
143
|
+
),
|
|
144
|
+
})
|
|
145
|
+
.transform(({ data }) => data),
|
|
146
|
+
),
|
|
147
|
+
);
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
export type GatewayImageModelId =
|
|
2
|
+
| 'bfl/flux-2-flex'
|
|
3
|
+
| 'bfl/flux-2-klein-4b'
|
|
4
|
+
| 'bfl/flux-2-klein-9b'
|
|
5
|
+
| 'bfl/flux-2-max'
|
|
6
|
+
| 'bfl/flux-2-pro'
|
|
2
7
|
| 'bfl/flux-kontext-max'
|
|
3
8
|
| 'bfl/flux-kontext-pro'
|
|
4
9
|
| 'bfl/flux-pro-1.0-fill'
|
|
@@ -10,6 +15,7 @@ export type GatewayImageModelId =
|
|
|
10
15
|
| 'openai/gpt-image-1'
|
|
11
16
|
| 'openai/gpt-image-1-mini'
|
|
12
17
|
| 'openai/gpt-image-1.5'
|
|
18
|
+
| 'prodia/flux-fast-schnell'
|
|
13
19
|
| 'recraft/recraft-v2'
|
|
14
20
|
| 'recraft/recraft-v3'
|
|
15
21
|
| 'recraft/recraft-v4'
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
ImageModelV4,
|
|
3
|
+
ImageModelV4File,
|
|
4
|
+
ImageModelV4ProviderMetadata,
|
|
5
5
|
} from '@ai-sdk/provider';
|
|
6
6
|
import {
|
|
7
7
|
combineHeaders,
|
|
@@ -17,8 +17,8 @@ import type { GatewayConfig } from './gateway-config';
|
|
|
17
17
|
import { asGatewayError } from './errors';
|
|
18
18
|
import { parseAuthMethod } from './errors/parse-auth-method';
|
|
19
19
|
|
|
20
|
-
export class GatewayImageModel implements
|
|
21
|
-
readonly specificationVersion = '
|
|
20
|
+
export class GatewayImageModel implements ImageModelV4 {
|
|
21
|
+
readonly specificationVersion = 'v4' as const;
|
|
22
22
|
// Set a very large number to prevent client-side splitting of requests
|
|
23
23
|
readonly maxImagesPerCall = Number.MAX_SAFE_INTEGER;
|
|
24
24
|
|
|
@@ -45,8 +45,8 @@ export class GatewayImageModel implements ImageModelV3 {
|
|
|
45
45
|
providerOptions,
|
|
46
46
|
headers,
|
|
47
47
|
abortSignal,
|
|
48
|
-
}: Parameters<
|
|
49
|
-
Awaited<ReturnType<
|
|
48
|
+
}: Parameters<ImageModelV4['doGenerate']>[0]): Promise<
|
|
49
|
+
Awaited<ReturnType<ImageModelV4['doGenerate']>>
|
|
50
50
|
> {
|
|
51
51
|
const resolvedHeaders = await resolve(this.config.headers());
|
|
52
52
|
try {
|
|
@@ -89,7 +89,7 @@ export class GatewayImageModel implements ImageModelV3 {
|
|
|
89
89
|
images: responseBody.images, // Always base64 strings from server
|
|
90
90
|
warnings: responseBody.warnings ?? [],
|
|
91
91
|
providerMetadata:
|
|
92
|
-
responseBody.providerMetadata as
|
|
92
|
+
responseBody.providerMetadata as ImageModelV4ProviderMetadata,
|
|
93
93
|
response: {
|
|
94
94
|
timestamp: new Date(),
|
|
95
95
|
modelId: this.modelId,
|
|
@@ -114,13 +114,13 @@ export class GatewayImageModel implements ImageModelV3 {
|
|
|
114
114
|
|
|
115
115
|
private getModelConfigHeaders() {
|
|
116
116
|
return {
|
|
117
|
-
'ai-image-model-specification-version': '
|
|
117
|
+
'ai-image-model-specification-version': '4',
|
|
118
118
|
'ai-model-id': this.modelId,
|
|
119
119
|
};
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
-
function maybeEncodeImageFile(file:
|
|
123
|
+
function maybeEncodeImageFile(file: ImageModelV4File) {
|
|
124
124
|
if (file.type === 'file' && file.data instanceof Uint8Array) {
|
|
125
125
|
return {
|
|
126
126
|
...file,
|
|
@@ -17,6 +17,7 @@ export type GatewayModelId =
|
|
|
17
17
|
| 'alibaba/qwen3-vl-thinking'
|
|
18
18
|
| 'alibaba/qwen3.5-flash'
|
|
19
19
|
| 'alibaba/qwen3.5-plus'
|
|
20
|
+
| 'alibaba/qwen3.6-plus'
|
|
20
21
|
| 'amazon/nova-2-lite'
|
|
21
22
|
| 'amazon/nova-lite'
|
|
22
23
|
| 'amazon/nova-micro'
|
|
@@ -24,8 +25,6 @@ export type GatewayModelId =
|
|
|
24
25
|
| 'anthropic/claude-3-haiku'
|
|
25
26
|
| 'anthropic/claude-3-opus'
|
|
26
27
|
| 'anthropic/claude-3.5-haiku'
|
|
27
|
-
| 'anthropic/claude-3.5-sonnet'
|
|
28
|
-
| 'anthropic/claude-3.5-sonnet-20240620'
|
|
29
28
|
| 'anthropic/claude-3.7-sonnet'
|
|
30
29
|
| 'anthropic/claude-haiku-4.5'
|
|
31
30
|
| 'anthropic/claude-opus-4'
|
|
@@ -36,6 +35,7 @@ export type GatewayModelId =
|
|
|
36
35
|
| 'anthropic/claude-sonnet-4.5'
|
|
37
36
|
| 'anthropic/claude-sonnet-4.6'
|
|
38
37
|
| 'arcee-ai/trinity-large-preview'
|
|
38
|
+
| 'arcee-ai/trinity-large-thinking'
|
|
39
39
|
| 'arcee-ai/trinity-mini'
|
|
40
40
|
| 'bytedance/seed-1.6'
|
|
41
41
|
| 'bytedance/seed-1.8'
|
|
@@ -51,8 +51,6 @@ export type GatewayModelId =
|
|
|
51
51
|
| 'google/gemini-2.5-flash'
|
|
52
52
|
| 'google/gemini-2.5-flash-image'
|
|
53
53
|
| 'google/gemini-2.5-flash-lite'
|
|
54
|
-
| 'google/gemini-2.5-flash-lite-preview-09-2025'
|
|
55
|
-
| 'google/gemini-2.5-flash-preview-09-2025'
|
|
56
54
|
| 'google/gemini-2.5-pro'
|
|
57
55
|
| 'google/gemini-3-flash'
|
|
58
56
|
| 'google/gemini-3-pro-image'
|
|
@@ -60,11 +58,14 @@ export type GatewayModelId =
|
|
|
60
58
|
| 'google/gemini-3.1-flash-image-preview'
|
|
61
59
|
| 'google/gemini-3.1-flash-lite-preview'
|
|
62
60
|
| 'google/gemini-3.1-pro-preview'
|
|
61
|
+
| 'google/gemma-4-26b-a4b-it'
|
|
62
|
+
| 'google/gemma-4-31b-it'
|
|
63
63
|
| 'inception/mercury-2'
|
|
64
64
|
| 'inception/mercury-coder-small'
|
|
65
65
|
| 'kwaipilot/kat-coder-pro-v1'
|
|
66
|
+
| 'kwaipilot/kat-coder-pro-v2'
|
|
66
67
|
| 'meituan/longcat-flash-chat'
|
|
67
|
-
| 'meituan/longcat-flash-thinking'
|
|
68
|
+
| 'meituan/longcat-flash-thinking-2601'
|
|
68
69
|
| 'meta/llama-3.1-70b'
|
|
69
70
|
| 'meta/llama-3.1-8b'
|
|
70
71
|
| 'meta/llama-3.2-11b'
|
|
@@ -79,6 +80,8 @@ export type GatewayModelId =
|
|
|
79
80
|
| 'minimax/minimax-m2.1-lightning'
|
|
80
81
|
| 'minimax/minimax-m2.5'
|
|
81
82
|
| 'minimax/minimax-m2.5-highspeed'
|
|
83
|
+
| 'minimax/minimax-m2.7'
|
|
84
|
+
| 'minimax/minimax-m2.7-highspeed'
|
|
82
85
|
| 'mistral/codestral'
|
|
83
86
|
| 'mistral/devstral-2'
|
|
84
87
|
| 'mistral/devstral-small'
|
|
@@ -104,9 +107,9 @@ export type GatewayModelId =
|
|
|
104
107
|
| 'morph/morph-v3-fast'
|
|
105
108
|
| 'morph/morph-v3-large'
|
|
106
109
|
| 'nvidia/nemotron-3-nano-30b-a3b'
|
|
110
|
+
| 'nvidia/nemotron-3-super-120b-a12b'
|
|
107
111
|
| 'nvidia/nemotron-nano-12b-v2-vl'
|
|
108
112
|
| 'nvidia/nemotron-nano-9b-v2'
|
|
109
|
-
| 'openai/codex-mini'
|
|
110
113
|
| 'openai/gpt-3.5-turbo'
|
|
111
114
|
| 'openai/gpt-3.5-turbo-instruct'
|
|
112
115
|
| 'openai/gpt-4-turbo'
|
|
@@ -134,6 +137,8 @@ export type GatewayModelId =
|
|
|
134
137
|
| 'openai/gpt-5.3-chat'
|
|
135
138
|
| 'openai/gpt-5.3-codex'
|
|
136
139
|
| 'openai/gpt-5.4'
|
|
140
|
+
| 'openai/gpt-5.4-mini'
|
|
141
|
+
| 'openai/gpt-5.4-nano'
|
|
137
142
|
| 'openai/gpt-5.4-pro'
|
|
138
143
|
| 'openai/gpt-oss-120b'
|
|
139
144
|
| 'openai/gpt-oss-20b'
|
|
@@ -146,12 +151,8 @@ export type GatewayModelId =
|
|
|
146
151
|
| 'openai/o4-mini'
|
|
147
152
|
| 'perplexity/sonar'
|
|
148
153
|
| 'perplexity/sonar-pro'
|
|
149
|
-
| 'perplexity/sonar-reasoning'
|
|
150
154
|
| 'perplexity/sonar-reasoning-pro'
|
|
151
155
|
| 'prime-intellect/intellect-3'
|
|
152
|
-
| 'vercel/v0-1.0-md'
|
|
153
|
-
| 'vercel/v0-1.5-md'
|
|
154
|
-
| 'xai/grok-2-vision'
|
|
155
156
|
| 'xai/grok-3'
|
|
156
157
|
| 'xai/grok-3-fast'
|
|
157
158
|
| 'xai/grok-3-mini'
|
|
@@ -161,8 +162,15 @@ export type GatewayModelId =
|
|
|
161
162
|
| 'xai/grok-4-fast-reasoning'
|
|
162
163
|
| 'xai/grok-4.1-fast-non-reasoning'
|
|
163
164
|
| 'xai/grok-4.1-fast-reasoning'
|
|
165
|
+
| 'xai/grok-4.20-multi-agent'
|
|
166
|
+
| 'xai/grok-4.20-multi-agent-beta'
|
|
167
|
+
| 'xai/grok-4.20-non-reasoning'
|
|
168
|
+
| 'xai/grok-4.20-non-reasoning-beta'
|
|
169
|
+
| 'xai/grok-4.20-reasoning'
|
|
170
|
+
| 'xai/grok-4.20-reasoning-beta'
|
|
164
171
|
| 'xai/grok-code-fast-1'
|
|
165
172
|
| 'xiaomi/mimo-v2-flash'
|
|
173
|
+
| 'xiaomi/mimo-v2-pro'
|
|
166
174
|
| 'zai/glm-4.5'
|
|
167
175
|
| 'zai/glm-4.5-air'
|
|
168
176
|
| 'zai/glm-4.5v'
|
|
@@ -173,4 +181,7 @@ export type GatewayModelId =
|
|
|
173
181
|
| 'zai/glm-4.7-flash'
|
|
174
182
|
| 'zai/glm-4.7-flashx'
|
|
175
183
|
| 'zai/glm-5'
|
|
184
|
+
| 'zai/glm-5-turbo'
|
|
185
|
+
| 'zai/glm-5.1'
|
|
186
|
+
| 'zai/glm-5v-turbo'
|
|
176
187
|
| (string & {});
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
LanguageModelV4,
|
|
3
|
+
LanguageModelV4CallOptions,
|
|
4
|
+
SharedV4Warning,
|
|
5
|
+
LanguageModelV4FilePart,
|
|
6
|
+
LanguageModelV4StreamPart,
|
|
7
|
+
LanguageModelV4GenerateResult,
|
|
8
|
+
LanguageModelV4StreamResult,
|
|
9
9
|
} from '@ai-sdk/provider';
|
|
10
10
|
import {
|
|
11
11
|
combineHeaders,
|
|
@@ -28,8 +28,8 @@ type GatewayChatConfig = GatewayConfig & {
|
|
|
28
28
|
o11yHeaders: Resolvable<Record<string, string>>;
|
|
29
29
|
};
|
|
30
30
|
|
|
31
|
-
export class GatewayLanguageModel implements
|
|
32
|
-
readonly specificationVersion = '
|
|
31
|
+
export class GatewayLanguageModel implements LanguageModelV4 {
|
|
32
|
+
readonly specificationVersion = 'v4';
|
|
33
33
|
readonly supportedUrls = { '*/*': [/.*/] };
|
|
34
34
|
|
|
35
35
|
constructor(
|
|
@@ -41,7 +41,7 @@ export class GatewayLanguageModel implements LanguageModelV3 {
|
|
|
41
41
|
return this.config.provider;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
private async getArgs(options:
|
|
44
|
+
private async getArgs(options: LanguageModelV4CallOptions) {
|
|
45
45
|
const { abortSignal: _abortSignal, ...optionsWithoutSignal } = options;
|
|
46
46
|
|
|
47
47
|
return {
|
|
@@ -51,8 +51,8 @@ export class GatewayLanguageModel implements LanguageModelV3 {
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
async doGenerate(
|
|
54
|
-
options:
|
|
55
|
-
): Promise<
|
|
54
|
+
options: LanguageModelV4CallOptions,
|
|
55
|
+
): Promise<LanguageModelV4GenerateResult> {
|
|
56
56
|
const { args, warnings } = await this.getArgs(options);
|
|
57
57
|
const { abortSignal } = options;
|
|
58
58
|
|
|
@@ -93,8 +93,8 @@ export class GatewayLanguageModel implements LanguageModelV3 {
|
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
async doStream(
|
|
96
|
-
options:
|
|
97
|
-
): Promise<
|
|
96
|
+
options: LanguageModelV4CallOptions,
|
|
97
|
+
): Promise<LanguageModelV4StreamResult> {
|
|
98
98
|
const { args, warnings } = await this.getArgs(options);
|
|
99
99
|
const { abortSignal } = options;
|
|
100
100
|
|
|
@@ -122,8 +122,8 @@ export class GatewayLanguageModel implements LanguageModelV3 {
|
|
|
122
122
|
return {
|
|
123
123
|
stream: response.pipeThrough(
|
|
124
124
|
new TransformStream<
|
|
125
|
-
ParseResult<
|
|
126
|
-
|
|
125
|
+
ParseResult<LanguageModelV4StreamPart>,
|
|
126
|
+
LanguageModelV4StreamPart
|
|
127
127
|
>({
|
|
128
128
|
start(controller) {
|
|
129
129
|
if (warnings.length > 0) {
|
|
@@ -177,11 +177,11 @@ export class GatewayLanguageModel implements LanguageModelV3 {
|
|
|
177
177
|
* @param options - The options to encode.
|
|
178
178
|
* @returns The options with the file parts encoded.
|
|
179
179
|
*/
|
|
180
|
-
private maybeEncodeFileParts(options:
|
|
180
|
+
private maybeEncodeFileParts(options: LanguageModelV4CallOptions) {
|
|
181
181
|
for (const message of options.prompt) {
|
|
182
182
|
for (const part of message.content) {
|
|
183
183
|
if (this.isFilePart(part)) {
|
|
184
|
-
const filePart = part as
|
|
184
|
+
const filePart = part as LanguageModelV4FilePart;
|
|
185
185
|
// If the file part is a URL it will get cleanly converted to a string.
|
|
186
186
|
// If it's a binary file attachment we convert it to a data url.
|
|
187
187
|
// In either case, server-side we should only ever see URLs as strings.
|
|
@@ -204,7 +204,7 @@ export class GatewayLanguageModel implements LanguageModelV3 {
|
|
|
204
204
|
|
|
205
205
|
private getModelConfigHeaders(modelId: string, streaming: boolean) {
|
|
206
206
|
return {
|
|
207
|
-
'ai-language-model-specification-version': '
|
|
207
|
+
'ai-language-model-specification-version': '4',
|
|
208
208
|
'ai-language-model-id': modelId,
|
|
209
209
|
'ai-language-model-streaming': String(streaming),
|
|
210
210
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { LanguageModelV4 } from '@ai-sdk/provider';
|
|
2
2
|
|
|
3
3
|
export interface GatewayLanguageModelEntry {
|
|
4
4
|
/**
|
|
@@ -53,6 +53,6 @@ export interface GatewayLanguageModelEntry {
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
export type GatewayLanguageModelSpecification = Pick<
|
|
56
|
-
|
|
56
|
+
LanguageModelV4,
|
|
57
57
|
'specificationVersion' | 'provider' | 'modelId'
|
|
58
58
|
>;
|
|
@@ -2,7 +2,7 @@ import { InferSchema, lazySchema, zodSchema } from '@ai-sdk/provider-utils';
|
|
|
2
2
|
import { z } from 'zod/v4';
|
|
3
3
|
|
|
4
4
|
// https://vercel.com/docs/ai-gateway/provider-options
|
|
5
|
-
const
|
|
5
|
+
const gatewayProviderOptions = lazySchema(() =>
|
|
6
6
|
zodSchema(
|
|
7
7
|
z.object({
|
|
8
8
|
/**
|
|
@@ -53,12 +53,33 @@ const gatewayLanguageModelOptions = lazySchema(() =>
|
|
|
53
53
|
.record(z.string(), z.array(z.record(z.string(), z.unknown())))
|
|
54
54
|
.optional(),
|
|
55
55
|
/**
|
|
56
|
-
* Whether to filter by only providers that
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
56
|
+
* Whether to filter by only providers that have zero data retention
|
|
57
|
+
* agreements with Vercel for AI Gateway. When using BYOK credentials,
|
|
58
|
+
* this filter is not applied. If BYOK credentials fail and the request
|
|
59
|
+
* falls back to system credentials, only providers with zero data
|
|
60
|
+
* retention agreements will be used.
|
|
60
61
|
*/
|
|
61
62
|
zeroDataRetention: z.boolean().optional(),
|
|
63
|
+
/**
|
|
64
|
+
* Whether to filter by only providers that do not train on prompt data.
|
|
65
|
+
* When using BYOK credentials, this filter is not applied. If BYOK
|
|
66
|
+
* credentials fail and the request falls back to system credentials,
|
|
67
|
+
* only providers that have agreements with Vercel for AI Gateway to not
|
|
68
|
+
* use prompts for model training will be used.
|
|
69
|
+
*/
|
|
70
|
+
disallowPromptTraining: z.boolean().optional(),
|
|
71
|
+
/**
|
|
72
|
+
* Whether to filter by only providers that are HIPAA compliant with
|
|
73
|
+
* Vercel AI Gateway. When enabled, only providers that have agreements
|
|
74
|
+
* with Vercel AI Gateway for HIPAA compliance will be used.
|
|
75
|
+
*/
|
|
76
|
+
hipaaCompliant: z.boolean().optional(),
|
|
77
|
+
/**
|
|
78
|
+
* The unique identifier for the entity against which quota is tracked.
|
|
79
|
+
*
|
|
80
|
+
* Used for quota management and enforcement purposes.
|
|
81
|
+
*/
|
|
82
|
+
quotaEntityId: z.string().optional(),
|
|
62
83
|
/**
|
|
63
84
|
* Per-provider timeouts for BYOK credentials in milliseconds.
|
|
64
85
|
* Controls how long to wait for a provider to start responding
|
|
@@ -75,6 +96,4 @@ const gatewayLanguageModelOptions = lazySchema(() =>
|
|
|
75
96
|
),
|
|
76
97
|
);
|
|
77
98
|
|
|
78
|
-
export type
|
|
79
|
-
typeof gatewayLanguageModelOptions
|
|
80
|
-
>;
|
|
99
|
+
export type GatewayProviderOptions = InferSchema<typeof gatewayProviderOptions>;
|