@ai-sdk/gateway 4.0.0-beta.9 → 4.0.0-canary.100

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.
Files changed (42) hide show
  1. package/CHANGELOG.md +662 -4
  2. package/dist/index.d.ts +207 -32
  3. package/dist/index.js +1122 -397
  4. package/dist/index.js.map +1 -1
  5. package/docs/00-ai-gateway.mdx +377 -61
  6. package/package.json +14 -14
  7. package/src/errors/as-gateway-error.ts +2 -1
  8. package/src/errors/create-gateway-error.ts +9 -3
  9. package/src/errors/gateway-authentication-error.ts +8 -5
  10. package/src/errors/gateway-error.ts +8 -0
  11. package/src/errors/gateway-failed-dependency-error.ts +35 -0
  12. package/src/errors/gateway-response-error.ts +1 -1
  13. package/src/errors/index.ts +1 -0
  14. package/src/errors/parse-auth-method.ts +1 -2
  15. package/src/gateway-config.ts +1 -1
  16. package/src/gateway-embedding-model-settings.ts +1 -0
  17. package/src/gateway-embedding-model.ts +38 -14
  18. package/src/gateway-fetch-metadata.ts +51 -38
  19. package/src/gateway-generation-info.ts +149 -0
  20. package/src/gateway-headers.ts +3 -0
  21. package/src/gateway-image-model-settings.ts +8 -1
  22. package/src/gateway-image-model.ts +41 -21
  23. package/src/gateway-language-model-settings.ts +45 -24
  24. package/src/gateway-language-model.ts +72 -42
  25. package/src/gateway-model-entry.ts +15 -3
  26. package/src/gateway-provider-options.ts +47 -9
  27. package/src/gateway-provider.ts +183 -35
  28. package/src/gateway-reranking-model-settings.ts +7 -0
  29. package/src/gateway-reranking-model.ts +119 -0
  30. package/src/gateway-speech-model-settings.ts +1 -0
  31. package/src/gateway-speech-model.ts +140 -0
  32. package/src/gateway-spend-report.ts +193 -0
  33. package/src/gateway-transcription-model-settings.ts +1 -0
  34. package/src/gateway-transcription-model.ts +150 -0
  35. package/src/gateway-video-model-settings.ts +4 -0
  36. package/src/gateway-video-model.ts +24 -19
  37. package/src/index.ts +20 -5
  38. package/src/tool/parallel-search.ts +10 -11
  39. package/src/tool/perplexity-search.ts +10 -11
  40. package/dist/index.d.mts +0 -602
  41. package/dist/index.mjs +0 -1539
  42. package/dist/index.mjs.map +0 -1
package/dist/index.d.ts CHANGED
@@ -1,11 +1,19 @@
1
- import { LanguageModelV3, ProviderV3, EmbeddingModelV3, ImageModelV3, Experimental_VideoModelV3, TypeValidationError } from '@ai-sdk/provider';
1
+ import { LanguageModelV4, ProviderV4, EmbeddingModelV4, ImageModelV4, Experimental_VideoModelV4, RerankingModelV4, SpeechModelV4, TranscriptionModelV4, 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' | 'amazon/nova-2-lite' | 'amazon/nova-lite' | 'amazon/nova-micro' | 'amazon/nova-pro' | 'anthropic/claude-3-haiku' | 'anthropic/claude-3-opus' | 'anthropic/claude-3.5-haiku' | 'anthropic/claude-3.5-sonnet' | 'anthropic/claude-3.5-sonnet-20240620' | 'anthropic/claude-3.7-sonnet' | '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-sonnet-4' | 'anthropic/claude-sonnet-4.5' | 'anthropic/claude-sonnet-4.6' | 'arcee-ai/trinity-large-preview' | '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' | 'google/gemini-2.0-flash' | 'google/gemini-2.0-flash-lite' | 'google/gemini-2.5-flash' | 'google/gemini-2.5-flash-image' | 'google/gemini-2.5-flash-lite' | 'google/gemini-2.5-flash-lite-preview-09-2025' | 'google/gemini-2.5-flash-preview-09-2025' | '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-preview' | 'google/gemini-3.1-flash-lite-preview' | 'google/gemini-3.1-pro-preview' | 'inception/mercury-2' | 'inception/mercury-coder-small' | 'kwaipilot/kat-coder-pro-v1' | 'meituan/longcat-flash-chat' | 'meituan/longcat-flash-thinking' | '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' | '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-nemo' | 'mistral/mistral-small' | 'mistral/mixtral-8x22b-instruct' | 'mistral/pixtral-12b' | 'mistral/pixtral-large' | 'moonshotai/kimi-k2' | 'moonshotai/kimi-k2-0905' | 'moonshotai/kimi-k2-thinking' | 'moonshotai/kimi-k2-thinking-turbo' | 'moonshotai/kimi-k2-turbo' | 'moonshotai/kimi-k2.5' | 'morph/morph-v3-fast' | 'morph/morph-v3-large' | 'nvidia/nemotron-3-nano-30b-a3b' | '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-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' | 'perplexity/sonar-reasoning-pro' | 'prime-intellect/intellect-3' | 'vercel/v0-1.0-md' | 'vercel/v0-1.5-md' | 'xai/grok-2-vision' | 'xai/grok-3' | 'xai/grok-3-fast' | 'xai/grok-3-mini' | 'xai/grok-3-mini-fast' | 'xai/grok-4' | 'xai/grok-4-fast-non-reasoning' | 'xai/grok-4-fast-reasoning' | 'xai/grok-4.1-fast-non-reasoning' | 'xai/grok-4.1-fast-reasoning' | 'xai/grok-code-fast-1' | 'xiaomi/mimo-v2-flash' | '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' | (string & {});
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-thinking-turbo' | 'moonshotai/kimi-k2-turbo' | 'moonshotai/kimi-k2.5' | 'moonshotai/kimi-k2.6' | '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
- 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-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-t2v' | 'xai/grok-imagine-video' | (string & {});
7
+ type GatewayRerankingModelId = 'cohere/rerank-v3.5' | 'cohere/rerank-v4-fast' | 'cohere/rerank-v4-pro' | 'voyage/rerank-2.5' | 'voyage/rerank-2.5-lite' | (string & {});
8
8
 
9
+ type GatewaySpeechModelId = string & {};
10
+
11
+ type GatewayTranscriptionModelId = string & {};
12
+
13
+ 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 & {});
14
+
15
+ declare const KNOWN_MODEL_TYPES: readonly ["embedding", "image", "language", "reranking", "speech", "transcription", "video"];
16
+ type KnownModelType = (typeof KNOWN_MODEL_TYPES)[number];
9
17
  interface GatewayLanguageModelEntry {
10
18
  /**
11
19
  * The model id used by the remote provider in model settings and for specifying the
@@ -50,9 +58,9 @@ interface GatewayLanguageModelEntry {
50
58
  /**
51
59
  * Optional field to differentiate between model types.
52
60
  */
53
- modelType?: 'language' | 'embedding' | 'image' | 'video' | null;
61
+ modelType?: KnownModelType | null;
54
62
  }
55
- type GatewayLanguageModelSpecification = Pick<LanguageModelV3, 'specificationVersion' | 'provider' | 'modelId'>;
63
+ type GatewayLanguageModelSpecification = Pick<LanguageModelV4, 'specificationVersion' | 'provider' | 'modelId'>;
56
64
 
57
65
  interface GatewayFetchMetadataResponse {
58
66
  models: GatewayLanguageModelEntry[];
@@ -64,9 +72,108 @@ interface GatewayCreditsResponse {
64
72
  totalUsed: string;
65
73
  }
66
74
 
67
- 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/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 & {});
75
+ interface GatewaySpendReportParams {
76
+ /** Start date in YYYY-MM-DD format (inclusive) */
77
+ startDate: string;
78
+ /** End date in YYYY-MM-DD format (inclusive) */
79
+ endDate: string;
80
+ /** Primary aggregation dimension. Defaults to 'day'. */
81
+ groupBy?: 'day' | 'user' | 'model' | 'tag' | 'provider' | 'credential_type';
82
+ /** Time granularity when groupBy is 'day'. */
83
+ datePart?: 'day' | 'hour';
84
+ /** Filter to a specific user's spend. */
85
+ userId?: string;
86
+ /** Filter to a specific model (e.g. 'anthropic/claude-sonnet-4.5'). */
87
+ model?: string;
88
+ /** Filter to a specific provider (e.g. 'anthropic'). */
89
+ provider?: string;
90
+ /** Filter to BYOK or system credentials. */
91
+ credentialType?: 'byok' | 'system';
92
+ /** Filter to requests with these tags. */
93
+ tags?: string[];
94
+ }
95
+ interface GatewaySpendReportRow {
96
+ /** Date string (present when groupBy is 'day') */
97
+ day?: string;
98
+ /** Hour timestamp (present when groupBy is 'day' and datePart is 'hour') */
99
+ hour?: string;
100
+ /** User identifier (present when groupBy is 'user') */
101
+ user?: string;
102
+ /** Model identifier (present when groupBy is 'model') */
103
+ model?: string;
104
+ /** Tag value (present when groupBy is 'tag') */
105
+ tag?: string;
106
+ /** Provider name (present when groupBy is 'provider') */
107
+ provider?: string;
108
+ /** Credential type (present when groupBy is 'credential_type') */
109
+ credentialType?: 'byok' | 'system';
110
+ /** Total cost in USD */
111
+ totalCost: number;
112
+ /** Market cost in USD */
113
+ marketCost?: number;
114
+ /** Number of input tokens */
115
+ inputTokens?: number;
116
+ /** Number of output tokens */
117
+ outputTokens?: number;
118
+ /** Number of cached input tokens */
119
+ cachedInputTokens?: number;
120
+ /** Number of cache creation input tokens */
121
+ cacheCreationInputTokens?: number;
122
+ /** Number of reasoning tokens */
123
+ reasoningTokens?: number;
124
+ /** Number of requests */
125
+ requestCount?: number;
126
+ }
127
+ interface GatewaySpendReportResponse {
128
+ results: GatewaySpendReportRow[];
129
+ }
68
130
 
69
- 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' | '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' | 'prodia/flux-fast-schnell' | 'recraft/recraft-v2' | 'recraft/recraft-v3' | 'recraft/recraft-v4' | 'recraft/recraft-v4-pro' | 'xai/grok-imagine-image' | 'xai/grok-imagine-image-pro' | (string & {});
131
+ interface GatewayGenerationInfoParams {
132
+ /** The generation ID to look up (format: gen_<ulid>) */
133
+ id: string;
134
+ }
135
+ interface GatewayGenerationInfo {
136
+ /** The generation ID */
137
+ id: string;
138
+ /** Total cost in USD */
139
+ totalCost: number;
140
+ /** Upstream inference cost in USD (BYOK only) */
141
+ upstreamInferenceCost: number;
142
+ /** Usage cost in USD (same as totalCost) */
143
+ usage: number;
144
+ /** ISO 8601 timestamp when the generation was created */
145
+ createdAt: string;
146
+ /** Model identifier */
147
+ model: string;
148
+ /** Whether BYOK credentials were used */
149
+ isByok: boolean;
150
+ /** Provider that served this generation */
151
+ providerName: string;
152
+ /** Whether streaming was used */
153
+ streamed: boolean;
154
+ /** Finish reason (e.g. 'stop') */
155
+ finishReason: string;
156
+ /** Time to first token in milliseconds */
157
+ latency: number;
158
+ /** Total generation time in milliseconds */
159
+ generationTime: number;
160
+ /** Number of prompt tokens */
161
+ promptTokens: number;
162
+ /** Number of completion tokens */
163
+ completionTokens: number;
164
+ /** Reasoning tokens used */
165
+ reasoningTokens: number;
166
+ /** Cached tokens used */
167
+ cachedTokens: number;
168
+ /** Cache creation input tokens */
169
+ cacheCreationTokens: number;
170
+ /** Billable web search calls */
171
+ billableWebSearchCalls: number;
172
+ }
173
+
174
+ 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 & {});
175
+
176
+ 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
177
 
71
178
  interface PerplexitySearchConfig {
72
179
  /**
@@ -194,7 +301,7 @@ interface PerplexitySearchInput {
194
301
  search_recency_filter?: 'day' | 'week' | 'month' | 'year';
195
302
  }
196
303
  type PerplexitySearchOutput = PerplexitySearchResponse | PerplexitySearchError;
197
- declare const perplexitySearchToolFactory: _ai_sdk_provider_utils.ProviderToolFactoryWithOutputSchema<PerplexitySearchInput, PerplexitySearchOutput, PerplexitySearchConfig>;
304
+ declare const perplexitySearchToolFactory: _ai_sdk_provider_utils.ProviderExecutedToolFactory<PerplexitySearchInput, PerplexitySearchOutput, PerplexitySearchConfig, {}>;
198
305
 
199
306
  interface ParallelSearchSourcePolicy {
200
307
  /**
@@ -327,7 +434,7 @@ interface ParallelSearchInput {
327
434
  };
328
435
  }
329
436
  type ParallelSearchOutput = ParallelSearchResponse | ParallelSearchError;
330
- declare const parallelSearchToolFactory: _ai_sdk_provider_utils.ProviderToolFactoryWithOutputSchema<ParallelSearchInput, ParallelSearchOutput, ParallelSearchConfig>;
437
+ declare const parallelSearchToolFactory: _ai_sdk_provider_utils.ProviderExecutedToolFactory<ParallelSearchInput, ParallelSearchOutput, ParallelSearchConfig, {}>;
331
438
 
332
439
  /**
333
440
  * Gateway-specific provider-defined tools.
@@ -352,16 +459,16 @@ declare const gatewayTools: {
352
459
  perplexitySearch: (config?: PerplexitySearchConfig) => ReturnType<typeof perplexitySearchToolFactory>;
353
460
  };
354
461
 
355
- interface GatewayProvider extends ProviderV3 {
356
- (modelId: GatewayModelId): LanguageModelV3;
462
+ interface GatewayProvider extends ProviderV4 {
463
+ (modelId: GatewayModelId): LanguageModelV4;
357
464
  /**
358
465
  * Creates a model for text generation.
359
466
  */
360
- chat(modelId: GatewayModelId): LanguageModelV3;
467
+ chat(modelId: GatewayModelId): LanguageModelV4;
361
468
  /**
362
469
  * Creates a model for text generation.
363
470
  */
364
- languageModel(modelId: GatewayModelId): LanguageModelV3;
471
+ languageModel(modelId: GatewayModelId): LanguageModelV4;
365
472
  /**
366
473
  * Returns available providers and models for use with the remote provider.
367
474
  */
@@ -370,34 +477,68 @@ interface GatewayProvider extends ProviderV3 {
370
477
  * Returns credit information for the authenticated user.
371
478
  */
372
479
  getCredits(): Promise<GatewayCreditsResponse>;
480
+ /**
481
+ * Returns a spend report with cost, token, and request count data,
482
+ * aggregated by the specified dimension.
483
+ */
484
+ getSpendReport(params: GatewaySpendReportParams): Promise<GatewaySpendReportResponse>;
485
+ /**
486
+ * Returns detailed information about a specific generation by its ID,
487
+ * including cost, token usage, latency, and provider details.
488
+ */
489
+ getGenerationInfo(params: GatewayGenerationInfoParams): Promise<GatewayGenerationInfo>;
373
490
  /**
374
491
  * Creates a model for generating text embeddings.
375
492
  */
376
- embedding(modelId: GatewayEmbeddingModelId): EmbeddingModelV3;
493
+ embedding(modelId: GatewayEmbeddingModelId): EmbeddingModelV4;
377
494
  /**
378
495
  * Creates a model for generating text embeddings.
379
496
  */
380
- embeddingModel(modelId: GatewayEmbeddingModelId): EmbeddingModelV3;
497
+ embeddingModel(modelId: GatewayEmbeddingModelId): EmbeddingModelV4;
381
498
  /**
382
499
  * @deprecated Use `embeddingModel` instead.
383
500
  */
384
- textEmbeddingModel(modelId: GatewayEmbeddingModelId): EmbeddingModelV3;
501
+ textEmbeddingModel(modelId: GatewayEmbeddingModelId): EmbeddingModelV4;
385
502
  /**
386
503
  * Creates a model for generating images.
387
504
  */
388
- image(modelId: GatewayImageModelId): ImageModelV3;
505
+ image(modelId: GatewayImageModelId): ImageModelV4;
389
506
  /**
390
507
  * Creates a model for generating images.
391
508
  */
392
- imageModel(modelId: GatewayImageModelId): ImageModelV3;
509
+ imageModel(modelId: GatewayImageModelId): ImageModelV4;
393
510
  /**
394
511
  * Creates a model for generating videos.
395
512
  */
396
- video(modelId: GatewayVideoModelId): Experimental_VideoModelV3;
513
+ video(modelId: GatewayVideoModelId): Experimental_VideoModelV4;
397
514
  /**
398
515
  * Creates a model for generating videos.
399
516
  */
400
- videoModel(modelId: GatewayVideoModelId): Experimental_VideoModelV3;
517
+ videoModel(modelId: GatewayVideoModelId): Experimental_VideoModelV4;
518
+ /**
519
+ * Creates a model for reranking documents.
520
+ */
521
+ reranking(modelId: GatewayRerankingModelId): RerankingModelV4;
522
+ /**
523
+ * Creates a model for reranking documents.
524
+ */
525
+ rerankingModel(modelId: GatewayRerankingModelId): RerankingModelV4;
526
+ /**
527
+ * Creates a model for text-to-speech generation.
528
+ */
529
+ speech(modelId: GatewaySpeechModelId): SpeechModelV4;
530
+ /**
531
+ * Creates a model for text-to-speech generation.
532
+ */
533
+ speechModel(modelId: GatewaySpeechModelId): SpeechModelV4;
534
+ /**
535
+ * Creates a model for audio transcription.
536
+ */
537
+ transcription(modelId: GatewayTranscriptionModelId): TranscriptionModelV4;
538
+ /**
539
+ * Creates a model for audio transcription.
540
+ */
541
+ transcriptionModel(modelId: GatewayTranscriptionModelId): TranscriptionModelV4;
401
542
  /**
402
543
  * Gateway-specific tools executed server-side.
403
544
  */
@@ -405,13 +546,19 @@ interface GatewayProvider extends ProviderV3 {
405
546
  }
406
547
  interface GatewayProviderSettings {
407
548
  /**
408
- * The base URL prefix for API calls. Defaults to `https://ai-gateway.vercel.sh/v1/ai`.
549
+ * The base URL prefix for API calls. Defaults to `https://ai-gateway.vercel.sh/v4/ai`.
409
550
  */
410
551
  baseURL?: string;
411
552
  /**
412
- * API key that is being sent using the `Authorization` header.
553
+ * API key or Vercel access token that is being sent using the `Authorization`
554
+ * header. It defaults to the `AI_GATEWAY_API_KEY` environment variable.
413
555
  */
414
556
  apiKey?: string;
557
+ /**
558
+ * Vercel team ID or slug to scope requests for access tokens that can access
559
+ * multiple teams.
560
+ */
561
+ teamIdOrSlug?: string;
415
562
  /**
416
563
  * Custom headers to include in the requests.
417
564
  */
@@ -429,36 +576,43 @@ interface GatewayProviderSettings {
429
576
  /**
430
577
  * Create a remote provider instance.
431
578
  */
432
- declare function createGatewayProvider(options?: GatewayProviderSettings): GatewayProvider;
579
+ declare function createGateway(options?: GatewayProviderSettings): GatewayProvider;
433
580
  declare const gateway: GatewayProvider;
434
581
 
435
- declare const gatewayLanguageModelOptions: _ai_sdk_provider_utils.LazySchema<{
582
+ declare const gatewayProviderOptions: _ai_sdk_provider_utils.LazySchema<{
436
583
  only?: string[] | undefined;
437
584
  order?: string[] | undefined;
585
+ sort?: "cost" | "ttft" | "tps" | undefined;
438
586
  user?: string | undefined;
439
587
  tags?: string[] | undefined;
440
588
  models?: string[] | undefined;
441
589
  byok?: Record<string, Record<string, unknown>[]> | undefined;
442
590
  zeroDataRetention?: boolean | undefined;
591
+ disallowPromptTraining?: boolean | undefined;
592
+ hipaaCompliant?: boolean | undefined;
593
+ quotaEntityId?: string | undefined;
443
594
  providerTimeouts?: {
444
595
  byok?: Record<string, number> | undefined;
445
596
  } | undefined;
597
+ serviceTier?: "flex" | "priority" | undefined;
446
598
  }>;
447
- type GatewayLanguageModelOptions = InferSchema<typeof gatewayLanguageModelOptions>;
599
+ type GatewayProviderOptions = InferSchema<typeof gatewayProviderOptions>;
448
600
 
449
- declare const symbol$6: unique symbol;
601
+ declare const symbol$7: unique symbol;
450
602
  declare abstract class GatewayError extends Error {
451
- private readonly [symbol$6];
603
+ private readonly [symbol$7];
452
604
  abstract readonly name: string;
453
605
  abstract readonly type: string;
454
606
  readonly statusCode: number;
455
607
  readonly cause?: unknown;
456
608
  readonly generationId?: string;
457
- constructor({ message, statusCode, cause, generationId, }: {
609
+ readonly isRetryable: boolean;
610
+ constructor({ message, statusCode, cause, generationId, isRetryable, }: {
458
611
  message: string;
459
612
  statusCode?: number;
460
613
  cause?: unknown;
461
614
  generationId?: string;
615
+ isRetryable?: boolean;
462
616
  });
463
617
  /**
464
618
  * Checks if the given error is a Gateway Error.
@@ -480,12 +634,12 @@ declare const gatewayErrorResponseSchema: _ai_sdk_provider_utils.LazySchema<{
480
634
  }>;
481
635
  type GatewayErrorResponse = InferSchema<typeof gatewayErrorResponseSchema>;
482
636
 
483
- declare const symbol$5: unique symbol;
637
+ declare const symbol$6: unique symbol;
484
638
  /**
485
639
  * Authentication failed - invalid API key or OIDC token
486
640
  */
487
641
  declare class GatewayAuthenticationError extends GatewayError {
488
- private readonly [symbol$5];
642
+ private readonly [symbol$6];
489
643
  readonly name = "GatewayAuthenticationError";
490
644
  readonly type = "authentication_error";
491
645
  constructor({ message, statusCode, cause, generationId, }?: {
@@ -498,7 +652,7 @@ declare class GatewayAuthenticationError extends GatewayError {
498
652
  /**
499
653
  * Creates a contextual error message when authentication fails
500
654
  */
501
- static createContextualError({ apiKeyProvided, oidcTokenProvided, message, statusCode, cause, generationId, }: {
655
+ static createContextualError({ apiKeyProvided, oidcTokenProvided, statusCode, cause, generationId, }: {
502
656
  apiKeyProvided: boolean;
503
657
  oidcTokenProvided: boolean;
504
658
  message?: string;
@@ -508,6 +662,25 @@ declare class GatewayAuthenticationError extends GatewayError {
508
662
  }): GatewayAuthenticationError;
509
663
  }
510
664
 
665
+ declare const symbol$5: unique symbol;
666
+ /**
667
+ * The request could not be fulfilled because a dependency it relied on was not
668
+ * available on the credentials or provider used to serve it (HTTP 424). Not
669
+ * retryable — the caller must change the request.
670
+ */
671
+ declare class GatewayFailedDependencyError extends GatewayError {
672
+ private readonly [symbol$5];
673
+ readonly name = "GatewayFailedDependencyError";
674
+ readonly type = "failed_dependency";
675
+ constructor({ message, statusCode, cause, generationId, }?: {
676
+ message?: string;
677
+ statusCode?: number;
678
+ cause?: unknown;
679
+ generationId?: string;
680
+ });
681
+ static isInstance(error: unknown): error is GatewayFailedDependencyError;
682
+ }
683
+
511
684
  declare const symbol$4: unique symbol;
512
685
  /**
513
686
  * Internal server error from the Gateway
@@ -599,4 +772,6 @@ declare class GatewayResponseError extends GatewayError {
599
772
  static isInstance(error: unknown): error is GatewayResponseError;
600
773
  }
601
774
 
602
- export { GatewayAuthenticationError, type GatewayCreditsResponse, GatewayError, type GatewayErrorResponse, GatewayInternalServerError, GatewayInvalidRequestError, type GatewayLanguageModelEntry, type GatewayLanguageModelOptions, type GatewayLanguageModelSpecification, type GatewayLanguageModelEntry as GatewayModelEntry, type GatewayModelId, GatewayModelNotFoundError, type GatewayProvider, type GatewayLanguageModelOptions as GatewayProviderOptions, type GatewayProviderSettings, GatewayRateLimitError, GatewayResponseError, type GatewayVideoModelId, createGatewayProvider as createGateway, createGatewayProvider, gateway };
775
+ declare const VERSION: string;
776
+
777
+ export { GatewayAuthenticationError, type GatewayCreditsResponse, GatewayError, type GatewayErrorResponse, GatewayFailedDependencyError, 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 GatewayRerankingModelId, GatewayResponseError, type GatewaySpeechModelId, type GatewaySpendReportParams, type GatewaySpendReportResponse, type GatewaySpendReportRow, type GatewayTranscriptionModelId, type GatewayVideoModelId, VERSION, createGateway, createGateway as createGatewayProvider, gateway };