Skip to Content

Quick start

Authentication & BYOK


AI Gateway

Get authenticated in under a minute:

AI Gateway Authentication and BYOK

Every request to AI Gateway requires Vercel authentication. Use an AI Gateway API key or OpenID Connect (OIDC) token. Bring Your Own Key (BYOK) provider credentials control how AI Gateway authenticates to a model provider, but they don't replace request authentication.

Copy page

  1. Go to the AI Gateway API Keys page in your Vercel dashboard
  2. Click Create key and follow the steps to generate a new API key.
  3. Copy the API key and add it to your environment:

export AI_GATEWAY_API_KEY="your_api_key_here"


The AI SDK automatically uses this environment variable for authentication. If you are using a different SDK, you may need to pass the API key manually.

Authentication methods

API keys

API keys work anywhere, whether it's local development, external servers, or CI pipelines. They never expire unless you revoke them. To create, view, or delete keys, see API keys. To cap how much a key can spend, see Budgets.

OIDC tokens on Vercel deployments.

When you specify a model id as a plain string, the AI SDK automatically uses the Vercel AI Gateway provider and reads the API key from the AI_GATEWAY_API_KEY environment variable:

These examples use AI SDK 7 and the AI SDK for Python beta. Set AI_GATEWAY_API_KEY before running them. See API format differences for setup, request fields, and response handling.

AI SDK

See the AI SDK authentication reference for SDK configuration and usage.


Messages API

const { text } =awaitgenerateText({

});

console.log(text);

Responses / OpenResponses

prompt:"Why is the sky blue?",

import { generateText } from'ai';

model:"anthropic/claude-sonnet-5",

OIDC tokens

Vercel deployments receive an OIDC token as VERCEL_OIDC_TOKEN, so you can authenticate without creating an API key. See OIDC for setup.

// An explicit API key takes precedence over the OIDC token.

constapiKey=process.env.AI_GATEWAY_API_KEY||process.env.VERCEL_OIDC_TOKEN;


Bring Your Own Key (BYOK)

BYOK lets you use your own provider credentials. This is useful when you:

  • Have existing agreements: Use enterprise pricing or credits from providers
  • Need zero markup: BYOK requests have no additional fee
  • Require private access: Access provider features that need your own credentials
  • Want automatic fallback: If your credentials fail, requests can retry with system credentials

Next steps

Last updated September 8, 2026

Cross-link map: AI Gateway Authentication and BYOK (/docs/ai-gateway/authentication-and-byok)From the Vercel docs graph (built 2026-09-21T05:26:59.511Z), spanning vercel.com docs + KB, nextjs.org, ai-sdk.dev, and other Vercel documentation sites. Full graph as JSON: https://vercel.com/docs/graph.jsonSemantically closest pagesBring Your Own Key \(BYOK\) to AI Gateway — Learn how to configure your own provider keys with AI Gateway.AI Gateway OIDC Authentication — Authenticate AI Gateway requests from Vercel deployments with OIDC tokens. Configure the AI SDK or send bearer tokens diVercel AI Gateway: Models, Routing, and Observability — Call AI models from any infrastructure through a managed gateway. Centralize credentials, request logs, spend budgets, rAI Gateway API Keys — Create, view, and delete AI Gateway API keys, and set each key's budget and spend attribution, from the dashboard, CLI,Getting Started with AI Gateway — Set up AI Gateway with a coding agent, route the agent through AI Gateway, or make your first request with cURL, TypeScrThis page links to (6)AI GatewayAI Gateway API Keys — Create, view, and delete AI Gateway API keys, and set each key's budget and spend attribution, from the dashboard, CLI,Bring Your Own Key \(BYOK\) to AI Gateway — Learn how to configure your own provider keys with AI Gateway.AI Gateway OIDC Authentication — Authenticate AI Gateway requests from Vercel deployments with OIDC tokens. Configure the AI SDK or send bearer tokens diAI Gateway Budgets and Spend Limits — Cap AI Gateway spend for your team, a project, an individual API key, or a team member with budgets, refresh periods, spAI Gateway SDKs and APIs — Connect to AI Gateway with the AI SDK, Python, REST, or compatible OpenAI, Anthropic Messages, OpenResponses, and CoherePages that link here (23)By site: vercel-changelog (1) · vercel-kb (5) · vercel-docs (17)From vercel-changelogDeepSeek models now available via Azure on AI GatewayFrom vercel-kbHow to architect an AI evaluation dashboard on Vercel — Map eval orchestration, traces, and run storage to AI Gateway, Observability, and Marketplace Postgres, and learn when sHow to build an AI agent for Slack with Chat SDK and AI SDK — Build a Slack AI agent using Chat SDK, AI SDK's ToolLoopAgent, and Vercel AI Gateway. Covers project setup, tool definitHow to build your own AI model router — Build an AI model router with Vercel AI Gateway. Keep routing, key, and retention decisions in your code while the gatewHow to route your coding agent spend through AI Gateway — Point Claude Code, Codex, Cursor, and every other harness on your machine at AI Gateway with one CLI command, on a budgeUsing TanStack AI with Vercel AI Gateway — Connect TanStack AI to Vercel AI Gateway with the @tanstack/ai-vercel-gateway adapter to stream chat, route across proviFrom vercel-docsVercel AI Gateway: Models, Routing, and Observability — Call AI models from any infrastructure through a managed gateway. Centralize credentials, request logs, spend budgets, rAI Gateway API Keys — Create, view, and delete AI Gateway API keys, and set each key's budget and spend attribution, from the dashboard, CLI,Command Code with AI Gateway — Connect Command Code to AI Gateway with your own API key and a custom base URL. Configure models, switch between them, aGrok Build with AI Gateway — Connect Grok Build to AI Gateway with environment variables. Populate the model picker from the model catalog and monitoOpenAI Codex with AI Gateway — Connect OpenAI Codex to AI Gateway with one CLI command, or configure it manually.AI Gateway Provider Latency and Throughput Metrics — Understand how AI Gateway measures throughput and latency per provider.AI Gateway Model Filtering — Restrict AI Gateway routing to models that have specific capabilities using the has option.AI Gateway Uptime and Provider Status — See how uptime and status track AI Gateway provider health and end-to-end request success.AI Gateway Trace Drains — Forward an OpenTelemetry trace of every AI Gateway request to your own observability tool, and understand trace drain biAI Gateway SDKs and APIs — Connect to AI Gateway with the AI SDK, Python, REST, or compatible OpenAI, Anthropic Messages, OpenResponses, and CohereAI SDK with AI Gateway — Build AI-powered TypeScript applications using the AI SDK with AI Gateway for unified access to 200+ models.AI SDK for Python with AI Gateway — Build AI-powered Python applications using the AI SDK for Python with AI Gateway for unified access to 200+ models.Anthropic Messages API with AI Gateway — Use the Anthropic Messages API with AI Gateway. Configure authentication and send requests with streaming, tools, imagesOpenAI Chat Completions API with AI Gateway — Use OpenAI SDKs with the AI Gateway Chat Completions API. Configure the base URL and authentication for chat, streaming,OpenResponses API with AI Gateway — Use the OpenResponses API specification with AI Gateway for a unified, provider-agnostic interface.AI Gateway REST API Reference — Reference for AI Gateway REST endpoints: models, usage, generations, and reporting.vercel ai-gateway — Manage AI Gateway resources from the Vercel CLI: API keys, budgets, routing rules, virtual models, models, leaderboards,

Can you trust our partners?

Next

Previous

BYOK credentials are configured at the team level and work across all projects. See the BYOK documentation for setup instructions.

Rate Limits

Was this helpful?