Claude Code and Claude Agent SDK
AI Gateway provides Anthropic-compatible API endpoints so you can use Claude Code and the Claude Agent SDK through a unified gateway.
Claude Code is Anthropic's agentic coding tool. You can configure it to use Vercel AI Gateway, enabling you to:
- Monitor traffic and token usage in your AI Gateway Overview
- View detailed traces in Vercel Observability under AI
First, 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
~/.zshrcor~/.bashrc:export ANTHROPIC_BASE_URL="https://ai-gateway.vercel.sh" export ANTHROPIC_AUTH_TOKEN="your-ai-gateway-api-key" export ANTHROPIC_API_KEY=""Run
claudeto start Claude Code with AI Gateway:claudeYour requests will now be routed through Vercel AI Gateway.
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 add-generic-password -a "$USER" -s "ANTHROPIC_AUTH_TOKEN" \ -w "your-ai-gateway-api-key"and edit the
ANTHROPIC_AUTH_TOKENline above to:export ANTHROPIC_AUTH_TOKEN=$( security find-generic-password -a "$USER" -s "ANTHROPIC_AUTH_TOKEN" -w )If you need to update the API key value later, you can do it with:
security add-generic-password -U -a "$USER" -s "ANTHROPIC_AUTH_TOKEN" \ -w "new-ai-gateway-api-key"
If you have a Claude subscription, you can use your subscription through the AI Gateway. This allows you to leverage your existing Claude subscription while still benefiting from the gateway's observability, monitoring, and routing features.
Add the following to your shell configuration file (e.g.,
~/.zshrcor~/.bashrc):export ANTHROPIC_BASE_URL="https://ai-gateway.vercel.sh" export ANTHROPIC_CUSTOM_HEADERS="x-ai-gateway-api-key: Bearer your-ai-gateway-api-key"Replace
your-ai-gateway-api-keywith your actual AI Gateway API key.Start Claude Code:
claudeIf 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.
Your requests will now be routed through Vercel AI Gateway using your Claude subscription. You'll be able to monitor usage and view traces in your Vercel dashboard while using your Anthropic subscription for model access.
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 the same quality, just with a configuration that prioritizes speed.
To use fast mode with AI Gateway on Opus 4.6, set the CLAUDE_CODE_SKIP_FAST_MODE_ORG_CHECK variable. You can either add it to your shell configuration file (e.g., ~/.zshrc or ~/.bashrc):
export CLAUDE_CODE_SKIP_FAST_MODE_ORG_CHECK=1Or add it to ~/.claude/settings.json:
{
"env": {
"CLAUDE_CODE_SKIP_FAST_MODE_ORG_CHECK": "1"
}
}For Opus 4.7, also set CLAUDE_CODE_ENABLE_OPUS_4_7_FAST_MODE:
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 as extra usage at $30/$150 per million input/output tokens, even if you have remaining usage on your plan. When you hit the fast mode rate limit, Claude Code automatically falls back to standard Opus speed and pricing.
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:
import { query } from '@anthropic-ai/claude-agent-sdk';
for await (const message of query({
prompt: 'Find and fix the bug in auth.py',
options: {
model: 'anthropic/claude-sonnet-4.6',
allowedTools: ['Read', 'Edit', 'Bash'],
env: {
...process.env,
ANTHROPIC_BASE_URL: 'https://ai-gateway.vercel.sh',
ANTHROPIC_AUTH_TOKEN: 'your-ai-gateway-api-key',
ANTHROPIC_API_KEY: '',
},
},
})) {
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.
Was this helpful?