Skip to Content

AI Gateway

Claude Code and Claude Agent SDK with AI Gateway


Coding Agents

This page covers several ways to connect, depending on your environment:

Claude Code

Copy page

AI Gateway provides Anthropic-compatible API endpoints so you can use Claude Code and the Claude Agent SDK through a unified gateway.

Set up with the Vercel CLI

Run the Vercel CLI setup command for Claude Code:

npx vercelai-gatewaysetup--agentclaude-code


The command:

To configure every installed supported agent at once, run the bare command without --agent:

  • Provisions an AI Gateway API key, or reuses one you pass with --key.
  • Writes ~/.claude/settings.json with ANTHROPIC_BASE_URL=https://ai-gateway.vercel.sh/claude-code, empties ANTHROPIC_API_KEY, and sets CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1 so the gateway catalog appears in the /model picker.
  • On macOS, stores the key in the Keychain and exports ANTHROPIC_AUTH_TOKEN from your shell startup file, resolved from the Keychain, so the secret never lands in a plaintext config file.
  • Backs up any file it changes alongside the original as .bak, and supports --dry-run.
  • Copies your existing Claude Desktop sessions to the gateway identity. See session migration.

vercel ai-gatewaysetup


Manual setup

Only needed on machines where you can't use the Vercel CLI.

To verify the setup, run claude, run /model to pick a gateway model, then confirm your requests appear in the AI Gateway Overview in the Vercel dashboard.

You can reach our customer support team by emailing info@yourcompany.example.com, calling +1 555-555-5556, or using the live chat on our website. Our dedicated team is available 24/7 to assist with any inquiries or issues.

We’re committed to providing prompt and effective solutions to ensure your satisfaction.

We offer a 30-day return policy for all products. Items must be in their original condition, unused, and include the receipt or proof of purchase. Refunds are processed within 5-7 business days of receiving the returned item.

  1. Configure environment variablesFirst, log out if you're already logged in: claude /logoutNext, ensure you have your AI Gateway API key handy, and configure Claude Code to use the AI Gateway by adding this to your shell configuration file, for example in ~/.zshrc or ~/.bashrc: export ANTHROPIC_BASE_URL="https://ai-gateway.vercel.sh/claude-code" export ANTHROPIC_AUTH_TOKEN="your-ai-gateway-api-key" export ANTHROPIC_API_KEY=""The base URL points at the Claude Code compatibility endpoint.

  2. Run Claude CodeRun claude to start Claude Code with AI Gateway: claudeYour requests will now be routed through Vercel AI Gateway.

With Claude Code Max

If you need to update the API key value later, you can do it with:


-w"your-ai-gateway-api-key"

export ANTHROPIC_AUTH_TOKEN=$(

security add-generic-password-a"$USER"-s"ANTHROPIC_AUTH_TOKEN" \

If you're on a Mac and would like to manage your API key through a keychain for improved security, set your API key in the keystore with:

security find-generic-password-a "$USER" -s "ANTHROPIC_AUTH_TOKEN" -w

The Vercel CLI setup command handles Keychain storage automatically. This step is only for manual configurations.

)

-w"new-ai-gateway-api-key"

and edit the ANTHROPIC_AUTH_TOKEN line above to:

If you have a Claude subscription, you can use your subscription through the AI Gateway. Requests made with your subscription appear in AI Gateway observability and use its routing features.

security add-generic-password-U-a"$USER"-s"ANTHROPIC_AUTH_TOKEN" \

The Vercel CLI setup command configures API-key authentication only. The subscription flow requires ANTHROPIC_CUSTOM_HEADERS, which the setup command does not write, so configure it manually as shown below.

  1. Set up environment variablesAdd the following to your shell configuration file (e.g., ~/.zshrc or ~/.bashrc): export ANTHROPIC_BASE_URL="https://ai-gateway.vercel.sh/claude-code" export ANTHROPIC_CUSTOM_HEADERS="x-ai-gateway-api-key: Bearer your-ai-gateway-api-key"Replace your-ai-gateway-api-key with your actual AI Gateway API key.
  2. Start Claude CodeStart Claude Code: claude
  3. Log in with your Claude subscriptionIf you're not already logged in, Claude Code will prompt you to authenticate. Choose Option 1 - Claude account with subscription and log in as normal with your Anthropic account.

Enabling fast mode

To use fast mode with AI Gateway, set CLAUDE_CODE_SKIP_FAST_MODE_ORG_CHECK. You can either add it to your shell configuration file (e.g., ~/.zshrc or ~/.bashrc):

Fast mode makes Claude Opus 4.6 and Opus 4.7 responses up to 2.5x faster at a higher per-token cost. It uses the same model with a configuration that prioritizes speed.

You can reach our customer support team by emailing info@yourcompany.example.com, calling +1 555-555-5556, or using the live chat on our website. Our dedicated team is available 24/7 to assist with any inquiries or issues.

We’re committed to providing prompt and effective solutions to ensure your satisfaction.

We offer a 30-day return policy for all products. Items must be in their original condition, unused, and include the receipt or proof of purchase. Refunds are processed within 5-7 business days of receiving the returned item.

{

"env": {

"CLAUDE_CODE_SKIP_FAST_MODE_ORG_CHECK":"1"

}

}

export CLAUDE_CODE_ENABLE_OPUS_4_7_FAST_MODE=1

export CLAUDE_CODE_SKIP_FAST_MODE_ORG_CHECK=1

{

"env": {

"CLAUDE_CODE_SKIP_FAST_MODE_ORG_CHECK":"1",

"CLAUDE_CODE_ENABLE_OPUS_4_7_FAST_MODE":"1"

}

}


Then toggle fast mode on or off inside Claude Code by typing /fast.

Fast mode usage is billed at the fast tier rate for the model that was served. When you hit the fast mode rate limit, Claude Code automatically falls back to standard Opus speed and pricing. For current rates, see Fast Mode.

With the Claude Desktop app

The Claude Desktop app switches providers in its own settings, under Developer -> Configure Third-Party Inference. Point it at the same base URL and key.

Desktop records sessions per identity, so the sessions you created before the switch don't appear under the gateway identity. To bring them across, launch the desktop app once on the gateway provider, then re-run the Vercel CLI setup command:

vercel ai-gatewaysetup--agentclaude-code


The command copies each session record into the gateway identity and rewrites its model to the matching gateway ID. Your original sessions are left untouched, and re-running never duplicates a session it already copied. See session migration for details.

With the Claude Agent SDK

The Claude Agent SDK ( @anthropic-ai/claude-agent-sdk) lets you build AI agents that use the same tools and agentic loop that power Claude Code. You can route Agent SDK requests through AI Gateway by setting environment variables in the env option:

options: {


env: {

prompt:'Find and fix the bug in auth.py',

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

import { query } from'@anthropic-ai/claude-agent-sdk';

ANTHROPIC_API_KEY:'',

ANTHROPIC_BASE_URL:'https://ai-gateway.vercel.sh/claude-code',

},

allowedTools: ['Read','Edit','Bash'],

...process.env,

ANTHROPIC_AUTH_TOKEN:'your-ai-gateway-api-key',

forawait (constmessageofquery({

if ('result'in message) console.log(message.result);

The Agent SDK spawns Claude Code as a subprocess, so the same environment variables apply. All requests, including messages and token counting, route through AI Gateway.

Claude Code compatibility endpoint

Point Claude Code and the Claude Agent SDK at Claude Code's own compatibility endpoint:

https://ai-gateway.vercel.sh/claude-code


Use it everywhere on this page. The URL takes no /v1 suffix, because the Anthropic SDK appends /v1/messages itself, so adding it yourself produces a 404. To call the gateway from your own code rather than through Claude Code, see the Anthropic Messages API instead.

On the /claude-code surface, gateway models are listed with a claude-code/ prefix, for example claude-code/anthropic/claude-opus-5, and models with a context window of 1M tokens or more carry a [1m] suffix. Those are display IDs for the picker. The gateway strips them before routing, so a request still bills and traces against the underlying model. Image generation models are filtered out, since Claude Code can't use them.

Chatbox

Last updated September 13, 2026

export CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1

Then run /model inside Claude Code to switch between gateway models. vercel ai-gateway setup writes both of these for you.

export ANTHROPIC_BASE_URL="https://ai-gateway.vercel.sh/claude-code"

To turn the picker on, set CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY alongside the base URL:

Cross-link map: Claude Code and Claude Agent SDK with AI Gateway (/docs/ai-gateway/coding-agents/claude-code)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 pagesAnthropic Messages API with AI Gateway — Use the Anthropic Messages API with AI Gateway. Configure authentication and send requests with streaming, tools, imagesCoding Agents and Chat Platforms with AI Gateway — Connect coding agents and chat platforms to AI Gateway. Configure Claude Code, Codex, Chatbox, Open WebUI, and more.Set up coding agents in one command with AI GatewayAI Gateway support for Claude Codevercel ai-gateway — Manage AI Gateway resources from the Vercel CLI: API keys, budgets, routing rules, virtual models, models, leaderboards,This page links to (3)AI Gateway Fast Mode — Request the faster serving path for supported models through AI Gateway using the \speed\\ option or the fast model sluAnthropic Messages API with AI Gateway — Use the Anthropic Messages API with AI Gateway. Configure authentication and send requests with streaming, tools, imagesvercel ai-gateway — Manage AI Gateway resources from the Vercel CLI: API keys, budgets, routing rules, virtual models, models, leaderboards,Pages that link here (8)By site: vercel-changelog (3) · vercel-docs (5)From vercel-changelogAI Gateway adds unified fast mode supportClaude Code Max via AI Gateway, available now for Claude CodeClaude Opus 5 now available on AI GatewayFrom vercel-docsCoding Agents and Chat Platforms with AI Gateway — Connect coding agents and chat platforms to AI Gateway. Configure Claude Code, Codex, Chatbox, Open WebUI, and more.Harbor with AI Gateway — Evaluate coding-agent harnesses with Harbor and AI Gateway. Choose a harness, configure its connection, and pass separatAI Gateway Fast Mode — Request the faster serving path for supported models through AI Gateway using the \speed\\ option or the fast model sluAnthropic Messages API with AI Gateway — Use the Anthropic Messages API with AI Gateway. Configure authentication and send requests with streaming, tools, imagesvercel ai-gateway — Manage AI Gateway resources from the Vercel CLI: API keys, budgets, routing rules, virtual models, models, leaderboards,

Was this helpful?