页面简介
A hosted AI gateway for any cloud or language. Centralize credentials, request logs, cost tracking, budgets, prompt caching, and provider failover.
正文摘录
Copy pageCopy pageCopy pageCopy pageCall AI models across providers with Vercel AI GatewayUse one managed gateway from any infrastructure to centralize credentials, log requests, control spend, and fail over across providers.Make your first requestBrowse modelsAI SDKcURLindex.mtsimport { generateText } from 'ai'; const { text } = await generateText({ model: 'openai/gpt-6-astra', prompt: 'Explain AI Gateway in one sentence.', }); console.log(text);terminalcurl https://ai-gateway.vercel.sh/v1/chat/completions \ -H "Authorization: Bearer $AI_GATEWAY_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "openai/gpt-6-astra", "messages": [ { "role": "user", "content": "Explain AI Gateway in one sentence." } ] }' AI Gateway is available on all plans. Your use of each AI provider is subject to their terms listed on each model's page and subject to Vercel's AI Product Terms. Use AI Gateway across modalities and clients Vercel AI Gateway gives applications and coding agents shared access to models across providers. It supports modalities including text generation, image generation, video generation, speech, transcription, realtime, embeddings, reranking, and decisions. Add files and tool calls where the selected model supports them. Call AI Gateway from any environment with the AI SDK, OpenAI Chat Completions, OpenAI Responses API, Anthropic Messages, coding agents and desktop apps like Claude Code, Claude Desktop, and OpenAI Codex (see all coding agents), or a framework integration. AI Gateway routes requests across providers and fallback models, then records status, provider, latency, token usage, cost, and every routing attempt. To prefer an inference provider and verify which provider served the request, set a provider order and read the response metadata. Configure budgets, access policies, data handling, and Bring Your Own Key (BYOK) for your team. AI Gateway adds zero markup to provider token prices, including with BYOK. Use AI Gateway from any cloud or language AI Gateway is a hosted API at https://ai-gateway.vercel.sh. Your application does not need to run on Vercel. Call AI Gateway from any server, cloud, or local environment with an AI Gateway API key. You need a Vercel account to create the key and manage billing, but not a Vercel project or deployment. Vercel deployments can use OpenID Connect (OIDC) instead of a key. LanguageConnect withTypeScript and JavaScriptThe AI SDK, or the OpenAI or Anthropic SDK with the AI Gateway base URLPythonThe OpenAI or Anthropic Python SDK, the AI SDK for Python, or a framework integration such as LangChain, LiteLLM, or Pydantic AIGoThe OpenAI or Anthropic Go SDK with the AI Gateway base URLOther languagesAny client for the OpenAI Chat Completions, OpenAI Responses, or Anthropic Messages API, or the REST API Centralize multi-provider AI operations Use AI Gateway when you want these controls without operating your own proxy, database, and routing control plane: RequirementHow AI Gateway handles itCentralized credentialsAuthenticate your application once, then use Vercel's provider keys or your own provider accounts through BYOK.Request loggingInspect each request's model, provider attempts, latency, token usage, status, and cost in request logs.Cost trackingSee spend by model in the dashboard and the cost of each request in request logs. Query spend by user, tag, or provider with Custom Reporting, which has its own pricing.Spending controlsSet budgets for a team, project, API key, or team member. AI Gateway rejects new requests after an applicable budget is exceeded.CachingSet caching: 'auto' for prompt caching across providers. You pay the provider's reduced cache-read rate for cached input tokens. To reuse full responses, cache them in your application.Provider failoverRoute a model across healthy providers and configure ordered provider and model fallbacks. Budgets cover spend billed through Vercel's provider keys. BYOK spend is metered separately and does not count toward those limits. The BYOK without fallback fee is the exception. If a BYOK request fails, AI Gateway can fall back to Vercel's provider keys. After a budget is exceeded, AI Gateway rejects every request in that budget's scope with an HTTP 402 response. This includes BYOK requests. Review the BYOK behavior and soft-cap budget semantics when strict provider-account use or zero-overshoot limits are requirements. Choose how to start Make your first requestStart with a coding agent, cURL, TypeScript, or Python.Build an AI agent with AI SDKFollow a step-by-step guide to add streaming, tools, and model fallbacks.Use an SDK or APIConnect an existing AI SDK, OpenAI, Anthropic, or HTTP client.Connect a coding agentRoute Claude Code, Claude Desktop, Codex, and other coding agents through AI Gateway.Migrate existing model callsKeep your current request format while moving model execution to AI Gateway. Configure and operate AI Gateway Models and providersChoose models and configure routing, filtering, fallbacks, caching, and service tiers.ModalitiesWork with text, images, video, speech, realtime, embeddings, reranking, and decisions.Observability and spendInspect requests, usage, latency, routing attempts, and cost.Authentication and BYOKAuthenticate with team-scoped API keys or OIDC, and connect provider credentials.Security and complianceConfigure access, data handling, regional inference, and safety controls.PricingReview model prices, credits, payment options, and discounts. Explore coding agents and chat platforms (including OpenAI Codex, Cursor, and OpenCode) and ecosystem integrations, learn how to handle 429 responses, or see the AI Gateway FAQ for common questions about model availability, pricing, and request errors. You and your coding agent can search the Knowledge Base for AI Gateway guides with vercel kb search, without logging in: terminalnpx vercel@latest kb search "AI Gateway"Related guidesBuild an AI app with Rust and Vercel AI Gateway: Build a support chat app with a Next.js AI SDK UI frontend, a Rust Vercel Function that streams UI message events, and AI Gateway for model calls.Build your startup's AI product with the AI SDK: Build streaming chat, decision-model triage, structured output, and tool-using agents with the AI SDK, then add tracing and cost controls before customers rely on them.Build your startup's AI features on Vercel AI Gateway: Build customer-facing AI features with Vercel AI Gateway, including authentication, model fallbacks, usage attribution for each customer, data controls, and budgets.Vercel AI Gateway vs Datadog AI Gateway: Compare Vercel AI Gateway and Datadog AI Gateway as LLM gateways, including providers, routing, access control, spend limits, guardrails, and observability.PreviousStart / Agent ChecklistNextGetting StartedWas this helpful?