@ai-sdk/gateway 4.0.0-beta.1 → 4.0.0-beta.108
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 +794 -4
- package/dist/index.d.ts +314 -42
- package/dist/index.js +1369 -397
- package/dist/index.js.map +1 -1
- package/docs/00-ai-gateway.mdx +447 -61
- package/package.json +15 -15
- package/src/errors/as-gateway-error.ts +2 -1
- package/src/errors/create-gateway-error.ts +17 -3
- package/src/errors/gateway-authentication-error.ts +8 -5
- package/src/errors/gateway-error.ts +8 -0
- package/src/errors/gateway-failed-dependency-error.ts +35 -0
- package/src/errors/gateway-forbidden-error.ts +34 -0
- package/src/errors/gateway-response-error.ts +1 -1
- package/src/errors/index.ts +2 -0
- package/src/errors/parse-auth-method.ts +1 -2
- package/src/gateway-config.ts +1 -1
- package/src/gateway-embedding-model-settings.ts +1 -0
- package/src/gateway-embedding-model.ts +62 -15
- package/src/gateway-fetch-metadata.ts +51 -38
- package/src/gateway-generation-info.ts +149 -0
- package/src/gateway-headers.ts +3 -0
- package/src/gateway-image-model-settings.ts +14 -1
- package/src/gateway-image-model.ts +46 -21
- package/src/gateway-language-model-settings.ts +52 -31
- package/src/gateway-language-model.ts +72 -42
- package/src/gateway-model-entry.ts +15 -3
- package/src/gateway-provider-options.ts +50 -78
- package/src/gateway-provider.ts +239 -35
- package/src/gateway-realtime-auth.ts +126 -0
- package/src/gateway-realtime-model-settings.ts +1 -0
- package/src/gateway-realtime-model.ts +107 -0
- package/src/gateway-reranking-model-settings.ts +7 -0
- package/src/gateway-reranking-model.ts +142 -0
- package/src/gateway-speech-model-settings.ts +1 -0
- package/src/gateway-speech-model.ts +145 -0
- package/src/gateway-spend-report.ts +193 -0
- package/src/gateway-transcription-model-settings.ts +1 -0
- package/src/gateway-transcription-model.ts +155 -0
- package/src/gateway-video-model-settings.ts +4 -0
- package/src/gateway-video-model.ts +29 -19
- package/src/index.ts +30 -5
- package/src/tool/parallel-search.ts +10 -11
- package/src/tool/perplexity-search.ts +10 -11
- package/dist/index.d.mts +0 -602
- package/dist/index.mjs +0 -1539
- package/dist/index.mjs.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,74 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LanguageModelV4, ProviderV4, EmbeddingModelV4, ImageModelV4, Experimental_VideoModelV4, RerankingModelV4, SpeechModelV4, TranscriptionModelV4, Experimental_RealtimeFactoryV4, TypeValidationError } from '@ai-sdk/provider';
|
|
2
2
|
import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
|
|
3
3
|
import { FetchFunction, InferSchema } from '@ai-sdk/provider-utils';
|
|
4
4
|
|
|
5
|
-
type GatewayModelId = 'alibaba/qwen-3-14b' | 'alibaba/qwen-3-235b' | 'alibaba/qwen-3-30b' | 'alibaba/qwen-3-32b' | 'alibaba/qwen3-235b-a22b-thinking' | 'alibaba/qwen3-coder' | 'alibaba/qwen3-coder-30b-a3b' | 'alibaba/qwen3-coder-next' | 'alibaba/qwen3-coder-plus' | 'alibaba/qwen3-max' | 'alibaba/qwen3-max-preview' | 'alibaba/qwen3-max-thinking' | 'alibaba/qwen3-next-80b-a3b-instruct' | 'alibaba/qwen3-next-80b-a3b-thinking' | 'alibaba/qwen3-vl-instruct' | 'alibaba/qwen3-vl-thinking' | 'alibaba/qwen3.5-flash' | 'alibaba/qwen3.5-plus' | '
|
|
5
|
+
type GatewayModelId = 'alibaba/qwen-3-14b' | 'alibaba/qwen-3-235b' | 'alibaba/qwen-3-30b' | 'alibaba/qwen-3-32b' | 'alibaba/qwen-3.6-max-preview' | 'alibaba/qwen3-235b-a22b-thinking' | 'alibaba/qwen3-coder' | 'alibaba/qwen3-coder-30b-a3b' | 'alibaba/qwen3-coder-next' | 'alibaba/qwen3-coder-plus' | 'alibaba/qwen3-max' | 'alibaba/qwen3-max-preview' | 'alibaba/qwen3-max-thinking' | 'alibaba/qwen3-next-80b-a3b-instruct' | 'alibaba/qwen3-next-80b-a3b-thinking' | 'alibaba/qwen3-vl-235b-a22b-instruct' | 'alibaba/qwen3-vl-instruct' | 'alibaba/qwen3-vl-thinking' | 'alibaba/qwen3.5-flash' | 'alibaba/qwen3.5-plus' | 'alibaba/qwen3.6-27b' | 'alibaba/qwen3.6-plus' | 'alibaba/qwen3.7-max' | 'alibaba/qwen3.7-plus' | 'amazon/nova-2-lite' | 'amazon/nova-lite' | 'amazon/nova-micro' | 'amazon/nova-pro' | 'anthropic/claude-3-haiku' | 'anthropic/claude-3.5-haiku' | 'anthropic/claude-haiku-4.5' | 'anthropic/claude-opus-4' | 'anthropic/claude-opus-4.1' | 'anthropic/claude-opus-4.5' | 'anthropic/claude-opus-4.6' | 'anthropic/claude-opus-4.7' | 'anthropic/claude-opus-4.8' | 'anthropic/claude-sonnet-4' | 'anthropic/claude-sonnet-4.5' | 'anthropic/claude-sonnet-4.6' | 'arcee-ai/trinity-large-preview' | 'arcee-ai/trinity-large-thinking' | 'arcee-ai/trinity-mini' | 'bytedance/seed-1.6' | 'bytedance/seed-1.8' | 'cohere/command-a' | 'deepseek/deepseek-r1' | 'deepseek/deepseek-v3' | 'deepseek/deepseek-v3.1' | 'deepseek/deepseek-v3.1-terminus' | 'deepseek/deepseek-v3.2' | 'deepseek/deepseek-v3.2-thinking' | 'deepseek/deepseek-v4-flash' | 'deepseek/deepseek-v4-pro' | 'google/gemini-2.5-flash' | 'google/gemini-2.5-flash-image' | 'google/gemini-2.5-flash-lite' | 'google/gemini-2.5-pro' | 'google/gemini-3-flash' | 'google/gemini-3-pro-image' | 'google/gemini-3-pro-preview' | 'google/gemini-3.1-flash-image' | 'google/gemini-3.1-flash-image-preview' | 'google/gemini-3.1-flash-lite' | 'google/gemini-3.1-flash-lite-preview' | 'google/gemini-3.1-pro-preview' | 'google/gemini-3.5-flash' | 'google/gemma-4-26b-a4b-it' | 'google/gemma-4-31b-it' | 'inception/mercury-2' | 'inception/mercury-coder-small' | 'interfaze/interfaze-beta' | 'kwaipilot/kat-coder-pro-v1' | 'kwaipilot/kat-coder-pro-v2' | 'meituan/longcat-flash-chat' | 'meituan/longcat-flash-thinking-2601' | 'meta/llama-3.1-70b' | 'meta/llama-3.1-8b' | 'meta/llama-3.2-11b' | 'meta/llama-3.2-1b' | 'meta/llama-3.2-3b' | 'meta/llama-3.2-90b' | 'meta/llama-3.3-70b' | 'meta/llama-4-maverick' | 'meta/llama-4-scout' | 'minimax/minimax-m2' | 'minimax/minimax-m2.1' | 'minimax/minimax-m2.1-lightning' | 'minimax/minimax-m2.5' | 'minimax/minimax-m2.5-highspeed' | 'minimax/minimax-m2.7' | 'minimax/minimax-m2.7-highspeed' | 'minimax/minimax-m3' | 'mistral/codestral' | 'mistral/devstral-2' | 'mistral/devstral-small' | 'mistral/devstral-small-2' | 'mistral/magistral-medium' | 'mistral/magistral-small' | 'mistral/ministral-14b' | 'mistral/ministral-3b' | 'mistral/ministral-8b' | 'mistral/mistral-large-3' | 'mistral/mistral-medium' | 'mistral/mistral-medium-3.5' | 'mistral/mistral-nemo' | 'mistral/mistral-small' | 'mistral/pixtral-12b' | 'mistral/pixtral-large' | 'moonshotai/kimi-k2' | 'moonshotai/kimi-k2-thinking' | 'moonshotai/kimi-k2.5' | 'moonshotai/kimi-k2.6' | 'moonshotai/kimi-k2.7-code' | 'moonshotai/kimi-k2.7-code-highspeed' | 'morph/morph-v3-fast' | 'morph/morph-v3-large' | 'nvidia/nemotron-3-nano-30b-a3b' | 'nvidia/nemotron-3-super-120b-a12b' | 'nvidia/nemotron-3-ultra-550b-a55b' | 'nvidia/nemotron-nano-12b-v2-vl' | 'nvidia/nemotron-nano-9b-v2' | 'openai/gpt-3.5-turbo' | 'openai/gpt-3.5-turbo-instruct' | 'openai/gpt-4-turbo' | 'openai/gpt-4.1' | 'openai/gpt-4.1-mini' | 'openai/gpt-4.1-nano' | 'openai/gpt-4o' | 'openai/gpt-4o-mini' | 'openai/gpt-4o-mini-search-preview' | 'openai/gpt-5' | 'openai/gpt-5-chat' | 'openai/gpt-5-codex' | 'openai/gpt-5-mini' | 'openai/gpt-5-nano' | 'openai/gpt-5-pro' | 'openai/gpt-5.1-codex' | 'openai/gpt-5.1-codex-max' | 'openai/gpt-5.1-codex-mini' | 'openai/gpt-5.1-instant' | 'openai/gpt-5.1-thinking' | 'openai/gpt-5.2' | 'openai/gpt-5.2-chat' | 'openai/gpt-5.2-codex' | 'openai/gpt-5.2-pro' | 'openai/gpt-5.3-chat' | 'openai/gpt-5.3-codex' | 'openai/gpt-5.4' | 'openai/gpt-5.4-mini' | 'openai/gpt-5.4-nano' | 'openai/gpt-5.4-pro' | 'openai/gpt-5.5' | 'openai/gpt-5.5-pro' | 'openai/gpt-oss-120b' | 'openai/gpt-oss-20b' | 'openai/gpt-oss-safeguard-20b' | 'openai/o1' | 'openai/o3' | 'openai/o3-deep-research' | 'openai/o3-mini' | 'openai/o3-pro' | 'openai/o4-mini' | 'perplexity/sonar' | 'perplexity/sonar-pro' | 'perplexity/sonar-reasoning-pro' | 'stepfun/step-3.5-flash' | 'stepfun/step-3.7-flash' | 'xai/grok-4.1-fast-non-reasoning' | 'xai/grok-4.1-fast-reasoning' | 'xai/grok-4.20-multi-agent' | 'xai/grok-4.20-multi-agent-beta' | 'xai/grok-4.20-non-reasoning' | 'xai/grok-4.20-non-reasoning-beta' | 'xai/grok-4.20-reasoning' | 'xai/grok-4.20-reasoning-beta' | 'xai/grok-4.3' | 'xai/grok-build-0.1' | 'xiaomi/mimo-v2-flash' | 'xiaomi/mimo-v2-pro' | 'xiaomi/mimo-v2.5' | 'xiaomi/mimo-v2.5-pro' | 'zai/glm-4.5' | 'zai/glm-4.5-air' | 'zai/glm-4.5v' | 'zai/glm-4.6' | 'zai/glm-4.6v' | 'zai/glm-4.6v-flash' | 'zai/glm-4.7' | 'zai/glm-4.7-flash' | 'zai/glm-4.7-flashx' | 'zai/glm-5' | 'zai/glm-5-turbo' | 'zai/glm-5.1' | 'zai/glm-5v-turbo' | (string & {});
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Shared WebSocket subprotocol contract for AI Gateway realtime auth.
|
|
9
|
+
*
|
|
10
|
+
* The browser `WebSocket` API cannot set request headers, so the Gateway auth
|
|
11
|
+
* (bearer) token is carried through the `Sec-WebSocket-Protocol` handshake
|
|
12
|
+
* instead of an `Authorization` header — the same workaround OpenAI uses for
|
|
13
|
+
* `openai-insecure-api-key.<token>`.
|
|
14
|
+
*
|
|
15
|
+
* This module is the single source of truth for that contract so the client and
|
|
16
|
+
* the Gateway server can't drift: the client encodes values with
|
|
17
|
+
* `getGatewayRealtimeProtocols`, and the Gateway server decodes them with
|
|
18
|
+
* `getGatewayRealtimeAuthToken` / `getGatewayRealtimeTeamIdOrSlug`.
|
|
19
|
+
*
|
|
20
|
+
* WebSocket subprotocol values must fit the RFC token grammar. The auth token is
|
|
21
|
+
* sent as-is, so callers must use tokens that are valid subprotocol tokens; the
|
|
22
|
+
* optional team scope is base64url-encoded by this module. Keep the complete
|
|
23
|
+
* `Sec-WebSocket-Protocol` header compact (target under an 8 KiB safe header
|
|
24
|
+
* budget) because intermediaries may reject large upgrade headers.
|
|
25
|
+
*/
|
|
26
|
+
/**
|
|
27
|
+
* Marker subprotocol offered on every handshake so the Gateway can echo a
|
|
28
|
+
* negotiated subprotocol on the 101 response (some clients require the server to
|
|
29
|
+
* select one of the offered subprotocols).
|
|
30
|
+
*/
|
|
31
|
+
declare const GATEWAY_REALTIME_SUBPROTOCOL = "ai-gateway-realtime.v1";
|
|
32
|
+
/** Subprotocol prefix that carries the Gateway auth (bearer) token. */
|
|
33
|
+
declare const GATEWAY_AUTH_SUBPROTOCOL_PREFIX = "ai-gateway-auth.";
|
|
34
|
+
/** Subprotocol prefix that carries optional Vercel team scoping. */
|
|
35
|
+
declare const GATEWAY_TEAM_SUBPROTOCOL_PREFIX = "ai-gateway-team.";
|
|
36
|
+
/**
|
|
37
|
+
* Client-side: build the WebSocket subprotocols that carry `token` to the
|
|
38
|
+
* Gateway. Pass the result as the second argument to `new WebSocket(url, ...)`.
|
|
39
|
+
*/
|
|
40
|
+
declare function getGatewayRealtimeProtocols(token: string, options?: {
|
|
41
|
+
teamIdOrSlug?: string;
|
|
42
|
+
}): string[];
|
|
43
|
+
/**
|
|
44
|
+
* Server-side: extract the Gateway auth (bearer) token from a
|
|
45
|
+
* `Sec-WebSocket-Protocol` header value, or `undefined` when it is absent or
|
|
46
|
+
* empty. The Gateway upgrade handler turns this into an
|
|
47
|
+
* `Authorization: Bearer <token>` before its normal auth path.
|
|
48
|
+
*
|
|
49
|
+
* Accepts the raw header value (subprotocols are comma-separated and may carry
|
|
50
|
+
* surrounding whitespace).
|
|
51
|
+
*/
|
|
52
|
+
declare function getGatewayRealtimeAuthToken(secWebSocketProtocol: string | null | undefined): string | undefined;
|
|
53
|
+
/**
|
|
54
|
+
* Server-side: extract the optional Vercel team ID or slug from the
|
|
55
|
+
* `Sec-WebSocket-Protocol` header value. Team scoping is base64url-encoded so
|
|
56
|
+
* arbitrary team slugs stay within the WebSocket subprotocol token grammar.
|
|
57
|
+
*/
|
|
58
|
+
declare function getGatewayRealtimeTeamIdOrSlug(secWebSocketProtocol: string | null | undefined): string | undefined;
|
|
8
59
|
|
|
60
|
+
type GatewayRealtimeModelId = string & {};
|
|
61
|
+
|
|
62
|
+
type GatewayRerankingModelId = 'cohere/rerank-v3.5' | 'cohere/rerank-v4-fast' | 'cohere/rerank-v4-pro' | 'voyage/rerank-2.5' | 'voyage/rerank-2.5-lite' | (string & {});
|
|
63
|
+
|
|
64
|
+
type GatewaySpeechModelId = string & {};
|
|
65
|
+
|
|
66
|
+
type GatewayTranscriptionModelId = string & {};
|
|
67
|
+
|
|
68
|
+
type GatewayVideoModelId = 'alibaba/wan-v2.5-t2v-preview' | 'alibaba/wan-v2.6-i2v' | 'alibaba/wan-v2.6-i2v-flash' | 'alibaba/wan-v2.6-r2v' | 'alibaba/wan-v2.6-r2v-flash' | 'alibaba/wan-v2.6-t2v' | 'bytedance/seedance-2.0' | 'bytedance/seedance-2.0-fast' | 'bytedance/seedance-v1.0-lite-i2v' | 'bytedance/seedance-v1.0-lite-t2v' | 'bytedance/seedance-v1.0-pro' | 'bytedance/seedance-v1.0-pro-fast' | 'bytedance/seedance-v1.5-pro' | 'google/veo-3.0-fast-generate-001' | 'google/veo-3.0-generate-001' | 'google/veo-3.1-fast-generate-001' | 'google/veo-3.1-generate-001' | 'klingai/kling-v2.5-turbo-i2v' | 'klingai/kling-v2.5-turbo-t2v' | 'klingai/kling-v2.6-i2v' | 'klingai/kling-v2.6-motion-control' | 'klingai/kling-v2.6-t2v' | 'klingai/kling-v3.0-i2v' | 'klingai/kling-v3.0-motion-control' | 'klingai/kling-v3.0-t2v' | 'xai/grok-imagine-video' | 'xai/grok-imagine-video-1.5-preview' | (string & {});
|
|
69
|
+
|
|
70
|
+
declare const KNOWN_MODEL_TYPES: readonly ["embedding", "image", "language", "reranking", "speech", "transcription", "video"];
|
|
71
|
+
type KnownModelType = (typeof KNOWN_MODEL_TYPES)[number];
|
|
9
72
|
interface GatewayLanguageModelEntry {
|
|
10
73
|
/**
|
|
11
74
|
* The model id used by the remote provider in model settings and for specifying the
|
|
@@ -50,9 +113,9 @@ interface GatewayLanguageModelEntry {
|
|
|
50
113
|
/**
|
|
51
114
|
* Optional field to differentiate between model types.
|
|
52
115
|
*/
|
|
53
|
-
modelType?:
|
|
116
|
+
modelType?: KnownModelType | null;
|
|
54
117
|
}
|
|
55
|
-
type GatewayLanguageModelSpecification = Pick<
|
|
118
|
+
type GatewayLanguageModelSpecification = Pick<LanguageModelV4, 'specificationVersion' | 'provider' | 'modelId'>;
|
|
56
119
|
|
|
57
120
|
interface GatewayFetchMetadataResponse {
|
|
58
121
|
models: GatewayLanguageModelEntry[];
|
|
@@ -64,9 +127,108 @@ interface GatewayCreditsResponse {
|
|
|
64
127
|
totalUsed: string;
|
|
65
128
|
}
|
|
66
129
|
|
|
67
|
-
|
|
130
|
+
interface GatewaySpendReportParams {
|
|
131
|
+
/** Start date in YYYY-MM-DD format (inclusive) */
|
|
132
|
+
startDate: string;
|
|
133
|
+
/** End date in YYYY-MM-DD format (inclusive) */
|
|
134
|
+
endDate: string;
|
|
135
|
+
/** Primary aggregation dimension. Defaults to 'day'. */
|
|
136
|
+
groupBy?: 'day' | 'user' | 'model' | 'tag' | 'provider' | 'credential_type';
|
|
137
|
+
/** Time granularity when groupBy is 'day'. */
|
|
138
|
+
datePart?: 'day' | 'hour';
|
|
139
|
+
/** Filter to a specific user's spend. */
|
|
140
|
+
userId?: string;
|
|
141
|
+
/** Filter to a specific model (e.g. 'anthropic/claude-sonnet-4.5'). */
|
|
142
|
+
model?: string;
|
|
143
|
+
/** Filter to a specific provider (e.g. 'anthropic'). */
|
|
144
|
+
provider?: string;
|
|
145
|
+
/** Filter to BYOK or system credentials. */
|
|
146
|
+
credentialType?: 'byok' | 'system';
|
|
147
|
+
/** Filter to requests with these tags. */
|
|
148
|
+
tags?: string[];
|
|
149
|
+
}
|
|
150
|
+
interface GatewaySpendReportRow {
|
|
151
|
+
/** Date string (present when groupBy is 'day') */
|
|
152
|
+
day?: string;
|
|
153
|
+
/** Hour timestamp (present when groupBy is 'day' and datePart is 'hour') */
|
|
154
|
+
hour?: string;
|
|
155
|
+
/** User identifier (present when groupBy is 'user') */
|
|
156
|
+
user?: string;
|
|
157
|
+
/** Model identifier (present when groupBy is 'model') */
|
|
158
|
+
model?: string;
|
|
159
|
+
/** Tag value (present when groupBy is 'tag') */
|
|
160
|
+
tag?: string;
|
|
161
|
+
/** Provider name (present when groupBy is 'provider') */
|
|
162
|
+
provider?: string;
|
|
163
|
+
/** Credential type (present when groupBy is 'credential_type') */
|
|
164
|
+
credentialType?: 'byok' | 'system';
|
|
165
|
+
/** Total cost in USD */
|
|
166
|
+
totalCost: number;
|
|
167
|
+
/** Market cost in USD */
|
|
168
|
+
marketCost?: number;
|
|
169
|
+
/** Number of input tokens */
|
|
170
|
+
inputTokens?: number;
|
|
171
|
+
/** Number of output tokens */
|
|
172
|
+
outputTokens?: number;
|
|
173
|
+
/** Number of cached input tokens */
|
|
174
|
+
cachedInputTokens?: number;
|
|
175
|
+
/** Number of cache creation input tokens */
|
|
176
|
+
cacheCreationInputTokens?: number;
|
|
177
|
+
/** Number of reasoning tokens */
|
|
178
|
+
reasoningTokens?: number;
|
|
179
|
+
/** Number of requests */
|
|
180
|
+
requestCount?: number;
|
|
181
|
+
}
|
|
182
|
+
interface GatewaySpendReportResponse {
|
|
183
|
+
results: GatewaySpendReportRow[];
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
interface GatewayGenerationInfoParams {
|
|
187
|
+
/** The generation ID to look up (format: gen_<ulid>) */
|
|
188
|
+
id: string;
|
|
189
|
+
}
|
|
190
|
+
interface GatewayGenerationInfo {
|
|
191
|
+
/** The generation ID */
|
|
192
|
+
id: string;
|
|
193
|
+
/** Total cost in USD */
|
|
194
|
+
totalCost: number;
|
|
195
|
+
/** Upstream inference cost in USD (BYOK only) */
|
|
196
|
+
upstreamInferenceCost: number;
|
|
197
|
+
/** Usage cost in USD (same as totalCost) */
|
|
198
|
+
usage: number;
|
|
199
|
+
/** ISO 8601 timestamp when the generation was created */
|
|
200
|
+
createdAt: string;
|
|
201
|
+
/** Model identifier */
|
|
202
|
+
model: string;
|
|
203
|
+
/** Whether BYOK credentials were used */
|
|
204
|
+
isByok: boolean;
|
|
205
|
+
/** Provider that served this generation */
|
|
206
|
+
providerName: string;
|
|
207
|
+
/** Whether streaming was used */
|
|
208
|
+
streamed: boolean;
|
|
209
|
+
/** Finish reason (e.g. 'stop') */
|
|
210
|
+
finishReason: string;
|
|
211
|
+
/** Time to first token in milliseconds */
|
|
212
|
+
latency: number;
|
|
213
|
+
/** Total generation time in milliseconds */
|
|
214
|
+
generationTime: number;
|
|
215
|
+
/** Number of prompt tokens */
|
|
216
|
+
promptTokens: number;
|
|
217
|
+
/** Number of completion tokens */
|
|
218
|
+
completionTokens: number;
|
|
219
|
+
/** Reasoning tokens used */
|
|
220
|
+
reasoningTokens: number;
|
|
221
|
+
/** Cached tokens used */
|
|
222
|
+
cachedTokens: number;
|
|
223
|
+
/** Cache creation input tokens */
|
|
224
|
+
cacheCreationTokens: number;
|
|
225
|
+
/** Billable web search calls */
|
|
226
|
+
billableWebSearchCalls: number;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
type GatewayEmbeddingModelId = 'alibaba/qwen3-embedding-0.6b' | 'alibaba/qwen3-embedding-4b' | 'alibaba/qwen3-embedding-8b' | 'amazon/titan-embed-text-v2' | 'cohere/embed-v4.0' | 'google/gemini-embedding-001' | 'google/gemini-embedding-2' | 'google/text-embedding-005' | 'google/text-multilingual-embedding-002' | 'mistral/codestral-embed' | 'mistral/mistral-embed' | 'openai/text-embedding-3-large' | 'openai/text-embedding-3-small' | 'openai/text-embedding-ada-002' | 'voyage/voyage-3-large' | 'voyage/voyage-3.5' | 'voyage/voyage-3.5-lite' | 'voyage/voyage-4' | 'voyage/voyage-4-large' | 'voyage/voyage-4-lite' | 'voyage/voyage-code-2' | 'voyage/voyage-code-3' | 'voyage/voyage-finance-2' | 'voyage/voyage-law-2' | (string & {});
|
|
68
230
|
|
|
69
|
-
type GatewayImageModelId = 'bfl/flux-kontext-max' | 'bfl/flux-kontext-pro' | 'bfl/flux-pro-1.0-fill' | 'bfl/flux-pro-1.1' | 'bfl/flux-pro-1.1-ultra' | 'google/imagen-4.0-fast-generate-001' | 'google/imagen-4.0-generate-001' | 'google/imagen-4.0-ultra-generate-001' | 'openai/gpt-image-1' | 'openai/gpt-image-1-mini' | 'openai/gpt-image-1.5' | 'recraft/recraft-v2' | 'recraft/recraft-v3' | 'recraft/recraft-v4' | 'recraft/recraft-v4-pro' | '
|
|
231
|
+
type GatewayImageModelId = 'bfl/flux-2-flex' | 'bfl/flux-2-klein-4b' | 'bfl/flux-2-klein-9b' | 'bfl/flux-2-max' | 'bfl/flux-2-pro' | 'bfl/flux-kontext-max' | 'bfl/flux-kontext-pro' | 'bfl/flux-pro-1.0-fill' | 'bfl/flux-pro-1.1' | 'bfl/flux-pro-1.1-ultra' | 'bytedance/seedream-4.0' | 'bytedance/seedream-4.5' | 'bytedance/seedream-5.0-lite' | 'google/imagen-4.0-fast-generate-001' | 'google/imagen-4.0-generate-001' | 'google/imagen-4.0-ultra-generate-001' | 'openai/gpt-image-1' | 'openai/gpt-image-1-mini' | 'openai/gpt-image-1.5' | 'openai/gpt-image-2' | 'prodia/flux-fast-schnell' | 'recraft/recraft-v2' | 'recraft/recraft-v3' | 'recraft/recraft-v4' | 'recraft/recraft-v4-pro' | 'recraft/recraft-v4.1' | 'recraft/recraft-v4.1-pro' | 'recraft/recraft-v4.1-utility' | 'recraft/recraft-v4.1-utility-pro' | 'xai/grok-imagine-image' | (string & {});
|
|
70
232
|
|
|
71
233
|
interface PerplexitySearchConfig {
|
|
72
234
|
/**
|
|
@@ -194,7 +356,7 @@ interface PerplexitySearchInput {
|
|
|
194
356
|
search_recency_filter?: 'day' | 'week' | 'month' | 'year';
|
|
195
357
|
}
|
|
196
358
|
type PerplexitySearchOutput = PerplexitySearchResponse | PerplexitySearchError;
|
|
197
|
-
declare const perplexitySearchToolFactory: _ai_sdk_provider_utils.
|
|
359
|
+
declare const perplexitySearchToolFactory: _ai_sdk_provider_utils.ProviderExecutedToolFactory<PerplexitySearchInput, PerplexitySearchOutput, PerplexitySearchConfig, {}>;
|
|
198
360
|
|
|
199
361
|
interface ParallelSearchSourcePolicy {
|
|
200
362
|
/**
|
|
@@ -327,7 +489,7 @@ interface ParallelSearchInput {
|
|
|
327
489
|
};
|
|
328
490
|
}
|
|
329
491
|
type ParallelSearchOutput = ParallelSearchResponse | ParallelSearchError;
|
|
330
|
-
declare const parallelSearchToolFactory: _ai_sdk_provider_utils.
|
|
492
|
+
declare const parallelSearchToolFactory: _ai_sdk_provider_utils.ProviderExecutedToolFactory<ParallelSearchInput, ParallelSearchOutput, ParallelSearchConfig, {}>;
|
|
331
493
|
|
|
332
494
|
/**
|
|
333
495
|
* Gateway-specific provider-defined tools.
|
|
@@ -352,16 +514,16 @@ declare const gatewayTools: {
|
|
|
352
514
|
perplexitySearch: (config?: PerplexitySearchConfig) => ReturnType<typeof perplexitySearchToolFactory>;
|
|
353
515
|
};
|
|
354
516
|
|
|
355
|
-
interface GatewayProvider extends
|
|
356
|
-
(modelId: GatewayModelId):
|
|
517
|
+
interface GatewayProvider extends ProviderV4 {
|
|
518
|
+
(modelId: GatewayModelId): LanguageModelV4;
|
|
357
519
|
/**
|
|
358
520
|
* Creates a model for text generation.
|
|
359
521
|
*/
|
|
360
|
-
chat(modelId: GatewayModelId):
|
|
522
|
+
chat(modelId: GatewayModelId): LanguageModelV4;
|
|
361
523
|
/**
|
|
362
524
|
* Creates a model for text generation.
|
|
363
525
|
*/
|
|
364
|
-
languageModel(modelId: GatewayModelId):
|
|
526
|
+
languageModel(modelId: GatewayModelId): LanguageModelV4;
|
|
365
527
|
/**
|
|
366
528
|
* Returns available providers and models for use with the remote provider.
|
|
367
529
|
*/
|
|
@@ -370,34 +532,73 @@ interface GatewayProvider extends ProviderV3 {
|
|
|
370
532
|
* Returns credit information for the authenticated user.
|
|
371
533
|
*/
|
|
372
534
|
getCredits(): Promise<GatewayCreditsResponse>;
|
|
535
|
+
/**
|
|
536
|
+
* Returns a spend report with cost, token, and request count data,
|
|
537
|
+
* aggregated by the specified dimension.
|
|
538
|
+
*/
|
|
539
|
+
getSpendReport(params: GatewaySpendReportParams): Promise<GatewaySpendReportResponse>;
|
|
540
|
+
/**
|
|
541
|
+
* Returns detailed information about a specific generation by its ID,
|
|
542
|
+
* including cost, token usage, latency, and provider details.
|
|
543
|
+
*/
|
|
544
|
+
getGenerationInfo(params: GatewayGenerationInfoParams): Promise<GatewayGenerationInfo>;
|
|
373
545
|
/**
|
|
374
546
|
* Creates a model for generating text embeddings.
|
|
375
547
|
*/
|
|
376
|
-
embedding(modelId: GatewayEmbeddingModelId):
|
|
548
|
+
embedding(modelId: GatewayEmbeddingModelId): EmbeddingModelV4;
|
|
377
549
|
/**
|
|
378
550
|
* Creates a model for generating text embeddings.
|
|
379
551
|
*/
|
|
380
|
-
embeddingModel(modelId: GatewayEmbeddingModelId):
|
|
552
|
+
embeddingModel(modelId: GatewayEmbeddingModelId): EmbeddingModelV4;
|
|
381
553
|
/**
|
|
382
554
|
* @deprecated Use `embeddingModel` instead.
|
|
383
555
|
*/
|
|
384
|
-
textEmbeddingModel(modelId: GatewayEmbeddingModelId):
|
|
556
|
+
textEmbeddingModel(modelId: GatewayEmbeddingModelId): EmbeddingModelV4;
|
|
385
557
|
/**
|
|
386
558
|
* Creates a model for generating images.
|
|
387
559
|
*/
|
|
388
|
-
image(modelId: GatewayImageModelId):
|
|
560
|
+
image(modelId: GatewayImageModelId): ImageModelV4;
|
|
389
561
|
/**
|
|
390
562
|
* Creates a model for generating images.
|
|
391
563
|
*/
|
|
392
|
-
imageModel(modelId: GatewayImageModelId):
|
|
564
|
+
imageModel(modelId: GatewayImageModelId): ImageModelV4;
|
|
393
565
|
/**
|
|
394
566
|
* Creates a model for generating videos.
|
|
395
567
|
*/
|
|
396
|
-
video(modelId: GatewayVideoModelId):
|
|
568
|
+
video(modelId: GatewayVideoModelId): Experimental_VideoModelV4;
|
|
397
569
|
/**
|
|
398
570
|
* Creates a model for generating videos.
|
|
399
571
|
*/
|
|
400
|
-
videoModel(modelId: GatewayVideoModelId):
|
|
572
|
+
videoModel(modelId: GatewayVideoModelId): Experimental_VideoModelV4;
|
|
573
|
+
/**
|
|
574
|
+
* Creates a model for reranking documents.
|
|
575
|
+
*/
|
|
576
|
+
reranking(modelId: GatewayRerankingModelId): RerankingModelV4;
|
|
577
|
+
/**
|
|
578
|
+
* Creates a model for reranking documents.
|
|
579
|
+
*/
|
|
580
|
+
rerankingModel(modelId: GatewayRerankingModelId): RerankingModelV4;
|
|
581
|
+
/**
|
|
582
|
+
* Creates a model for text-to-speech generation.
|
|
583
|
+
*/
|
|
584
|
+
speech(modelId: GatewaySpeechModelId): SpeechModelV4;
|
|
585
|
+
/**
|
|
586
|
+
* Creates a model for text-to-speech generation.
|
|
587
|
+
*/
|
|
588
|
+
speechModel(modelId: GatewaySpeechModelId): SpeechModelV4;
|
|
589
|
+
/**
|
|
590
|
+
* Creates a model for audio transcription.
|
|
591
|
+
*/
|
|
592
|
+
transcription(modelId: GatewayTranscriptionModelId): TranscriptionModelV4;
|
|
593
|
+
/**
|
|
594
|
+
* Creates a model for audio transcription.
|
|
595
|
+
*/
|
|
596
|
+
transcriptionModel(modelId: GatewayTranscriptionModelId): TranscriptionModelV4;
|
|
597
|
+
/**
|
|
598
|
+
* Creates an experimental realtime model for bidirectional audio/text
|
|
599
|
+
* communication over WebSocket, normalized through the AI Gateway.
|
|
600
|
+
*/
|
|
601
|
+
experimental_realtime: Experimental_RealtimeFactoryV4;
|
|
401
602
|
/**
|
|
402
603
|
* Gateway-specific tools executed server-side.
|
|
403
604
|
*/
|
|
@@ -405,13 +606,19 @@ interface GatewayProvider extends ProviderV3 {
|
|
|
405
606
|
}
|
|
406
607
|
interface GatewayProviderSettings {
|
|
407
608
|
/**
|
|
408
|
-
* The base URL prefix for API calls. Defaults to `https://ai-gateway.vercel.sh/
|
|
609
|
+
* The base URL prefix for API calls. Defaults to `https://ai-gateway.vercel.sh/v4/ai`.
|
|
409
610
|
*/
|
|
410
611
|
baseURL?: string;
|
|
411
612
|
/**
|
|
412
|
-
* API key that is being sent using the `Authorization`
|
|
613
|
+
* API key or Vercel access token that is being sent using the `Authorization`
|
|
614
|
+
* header. It defaults to the `AI_GATEWAY_API_KEY` environment variable.
|
|
413
615
|
*/
|
|
414
616
|
apiKey?: string;
|
|
617
|
+
/**
|
|
618
|
+
* Vercel team ID or slug to scope requests for access tokens that can access
|
|
619
|
+
* multiple teams.
|
|
620
|
+
*/
|
|
621
|
+
teamIdOrSlug?: string;
|
|
415
622
|
/**
|
|
416
623
|
* Custom headers to include in the requests.
|
|
417
624
|
*/
|
|
@@ -429,36 +636,62 @@ interface GatewayProviderSettings {
|
|
|
429
636
|
/**
|
|
430
637
|
* Create a remote provider instance.
|
|
431
638
|
*/
|
|
432
|
-
declare function
|
|
639
|
+
declare function createGateway(options?: GatewayProviderSettings): GatewayProvider;
|
|
433
640
|
declare const gateway: GatewayProvider;
|
|
434
641
|
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
642
|
+
type GatewayProviderOptions = {
|
|
643
|
+
/**
|
|
644
|
+
* Service-owned options may be added by the Gateway without requiring an SDK
|
|
645
|
+
* release. The Gateway service validates and applies the runtime schema.
|
|
646
|
+
*/
|
|
647
|
+
[key: string]: unknown;
|
|
648
|
+
/** Request-scoped BYOK credentials to use instead of cached credentials. */
|
|
649
|
+
byok?: Record<string, Array<Record<string, unknown>>>;
|
|
650
|
+
/** Enables automatic caching behavior when supported by the Gateway. */
|
|
651
|
+
caching?: 'auto';
|
|
652
|
+
/** Filter to providers that do not train on prompt data. */
|
|
653
|
+
disallowPromptTraining?: boolean;
|
|
654
|
+
/** Filter to providers that are HIPAA compliant with Vercel AI Gateway. */
|
|
655
|
+
hipaaCompliant?: boolean;
|
|
656
|
+
/** Array of model slugs specifying fallback models to use in order. */
|
|
657
|
+
models?: string[];
|
|
658
|
+
/** Array of provider slugs that are the only ones allowed to be used. */
|
|
659
|
+
only?: string[];
|
|
660
|
+
/** Array of provider slugs specifying the provider attempt order. */
|
|
661
|
+
order?: string[];
|
|
662
|
+
/** Per-provider timeouts for BYOK credentials in milliseconds. */
|
|
443
663
|
providerTimeouts?: {
|
|
444
|
-
byok?: Record<string, number
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
|
|
664
|
+
byok?: Record<string, number>;
|
|
665
|
+
};
|
|
666
|
+
/** Entity identifier against which quota is tracked. */
|
|
667
|
+
quotaEntityId?: string;
|
|
668
|
+
/** Unified service tier intent. */
|
|
669
|
+
serviceTier?: 'flex' | 'priority';
|
|
670
|
+
/** Sort providers by a performance or cost metric before routing. */
|
|
671
|
+
sort?: 'cost' | 'tps' | 'ttft';
|
|
672
|
+
/** User-specified tags for reporting and filtering usage. */
|
|
673
|
+
tags?: string[];
|
|
674
|
+
/** End-user identifier for spend tracking and attribution. */
|
|
675
|
+
user?: string;
|
|
676
|
+
/** Filter to providers with zero data retention agreements. */
|
|
677
|
+
zeroDataRetention?: boolean;
|
|
678
|
+
};
|
|
448
679
|
|
|
449
|
-
declare const symbol$
|
|
680
|
+
declare const symbol$8: unique symbol;
|
|
450
681
|
declare abstract class GatewayError extends Error {
|
|
451
|
-
private readonly [symbol$
|
|
682
|
+
private readonly [symbol$8];
|
|
452
683
|
abstract readonly name: string;
|
|
453
684
|
abstract readonly type: string;
|
|
454
685
|
readonly statusCode: number;
|
|
455
686
|
readonly cause?: unknown;
|
|
456
687
|
readonly generationId?: string;
|
|
457
|
-
|
|
688
|
+
readonly isRetryable: boolean;
|
|
689
|
+
constructor({ message, statusCode, cause, generationId, isRetryable, }: {
|
|
458
690
|
message: string;
|
|
459
691
|
statusCode?: number;
|
|
460
692
|
cause?: unknown;
|
|
461
693
|
generationId?: string;
|
|
694
|
+
isRetryable?: boolean;
|
|
462
695
|
});
|
|
463
696
|
/**
|
|
464
697
|
* Checks if the given error is a Gateway Error.
|
|
@@ -480,12 +713,12 @@ declare const gatewayErrorResponseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
480
713
|
}>;
|
|
481
714
|
type GatewayErrorResponse = InferSchema<typeof gatewayErrorResponseSchema>;
|
|
482
715
|
|
|
483
|
-
declare const symbol$
|
|
716
|
+
declare const symbol$7: unique symbol;
|
|
484
717
|
/**
|
|
485
718
|
* Authentication failed - invalid API key or OIDC token
|
|
486
719
|
*/
|
|
487
720
|
declare class GatewayAuthenticationError extends GatewayError {
|
|
488
|
-
private readonly [symbol$
|
|
721
|
+
private readonly [symbol$7];
|
|
489
722
|
readonly name = "GatewayAuthenticationError";
|
|
490
723
|
readonly type = "authentication_error";
|
|
491
724
|
constructor({ message, statusCode, cause, generationId, }?: {
|
|
@@ -498,7 +731,7 @@ declare class GatewayAuthenticationError extends GatewayError {
|
|
|
498
731
|
/**
|
|
499
732
|
* Creates a contextual error message when authentication fails
|
|
500
733
|
*/
|
|
501
|
-
static createContextualError({ apiKeyProvided, oidcTokenProvided,
|
|
734
|
+
static createContextualError({ apiKeyProvided, oidcTokenProvided, statusCode, cause, generationId, }: {
|
|
502
735
|
apiKeyProvided: boolean;
|
|
503
736
|
oidcTokenProvided: boolean;
|
|
504
737
|
message?: string;
|
|
@@ -508,6 +741,43 @@ declare class GatewayAuthenticationError extends GatewayError {
|
|
|
508
741
|
}): GatewayAuthenticationError;
|
|
509
742
|
}
|
|
510
743
|
|
|
744
|
+
declare const symbol$6: unique symbol;
|
|
745
|
+
/**
|
|
746
|
+
* The request could not be fulfilled because a dependency it relied on was not
|
|
747
|
+
* available on the credentials or provider used to serve it (HTTP 424). Not
|
|
748
|
+
* retryable — the caller must change the request.
|
|
749
|
+
*/
|
|
750
|
+
declare class GatewayFailedDependencyError extends GatewayError {
|
|
751
|
+
private readonly [symbol$6];
|
|
752
|
+
readonly name = "GatewayFailedDependencyError";
|
|
753
|
+
readonly type = "failed_dependency";
|
|
754
|
+
constructor({ message, statusCode, cause, generationId, }?: {
|
|
755
|
+
message?: string;
|
|
756
|
+
statusCode?: number;
|
|
757
|
+
cause?: unknown;
|
|
758
|
+
generationId?: string;
|
|
759
|
+
});
|
|
760
|
+
static isInstance(error: unknown): error is GatewayFailedDependencyError;
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
declare const symbol$5: unique symbol;
|
|
764
|
+
/**
|
|
765
|
+
* Forbidden - the request was rejected by policy (e.g. a routing rule),
|
|
766
|
+
* not an authentication failure.
|
|
767
|
+
*/
|
|
768
|
+
declare class GatewayForbiddenError extends GatewayError {
|
|
769
|
+
private readonly [symbol$5];
|
|
770
|
+
readonly name = "GatewayForbiddenError";
|
|
771
|
+
readonly type = "forbidden";
|
|
772
|
+
constructor({ message, statusCode, cause, generationId, }?: {
|
|
773
|
+
message?: string;
|
|
774
|
+
statusCode?: number;
|
|
775
|
+
cause?: unknown;
|
|
776
|
+
generationId?: string;
|
|
777
|
+
});
|
|
778
|
+
static isInstance(error: unknown): error is GatewayForbiddenError;
|
|
779
|
+
}
|
|
780
|
+
|
|
511
781
|
declare const symbol$4: unique symbol;
|
|
512
782
|
/**
|
|
513
783
|
* Internal server error from the Gateway
|
|
@@ -599,4 +869,6 @@ declare class GatewayResponseError extends GatewayError {
|
|
|
599
869
|
static isInstance(error: unknown): error is GatewayResponseError;
|
|
600
870
|
}
|
|
601
871
|
|
|
602
|
-
|
|
872
|
+
declare const VERSION: string;
|
|
873
|
+
|
|
874
|
+
export { GATEWAY_AUTH_SUBPROTOCOL_PREFIX, GATEWAY_REALTIME_SUBPROTOCOL, GATEWAY_TEAM_SUBPROTOCOL_PREFIX, GatewayAuthenticationError, type GatewayCreditsResponse, GatewayError, type GatewayErrorResponse, GatewayFailedDependencyError, GatewayForbiddenError, type GatewayGenerationInfo, type GatewayGenerationInfoParams, GatewayInternalServerError, GatewayInvalidRequestError, type GatewayLanguageModelEntry, type GatewayProviderOptions as GatewayLanguageModelOptions, type GatewayLanguageModelSpecification, type GatewayLanguageModelEntry as GatewayModelEntry, type GatewayModelId, GatewayModelNotFoundError, type GatewayProvider, type GatewayProviderOptions, type GatewayProviderSettings, GatewayRateLimitError, type GatewayRealtimeModelId, type GatewayRerankingModelId, GatewayResponseError, type GatewaySpeechModelId, type GatewaySpendReportParams, type GatewaySpendReportResponse, type GatewaySpendReportRow, type GatewayTranscriptionModelId, type GatewayVideoModelId, VERSION, createGateway, createGateway as createGatewayProvider, gateway, getGatewayRealtimeAuthToken, getGatewayRealtimeProtocols, getGatewayRealtimeTeamIdOrSlug };
|