Claude Code setup
Use Virouter as the Anthropic-compatible LLM gateway for Claude Code. Claude Code sends Anthropic Messages requests to Virouter, and Virouter routes them through your Billing USD Quota wallet.
ANTHROPIC_BASE_URL=https://api.virouter.com. The OpenAI SDK base URL https://api.virouter.com/v1is for OpenAI-compatible SDKs, not Claude Code. Virouter's Claude surface may route to Anthropic Messages-compatible upstreams today, and to Claude Code CLI-only upstreams after the dedicated bridge is enabled.Paste your Virouter API key into the command below. The installer updates ~/.claude/settings.json, preserves any existing settings, and creates a timestamped backup before writing.
# Windows Command Prompt / PowerShell
powershell -NoProfile -ExecutionPolicy Bypass -Command "iwr https://virouter.com/install/claude-code.ps1 -OutFile $env:TEMP\virouter-claude-code.ps1; & $env:TEMP\virouter-claude-code.ps1 -ApiKey 'vr_sk_xxxxxxxxxxxx'"
# macOS / Linux / Git Bash
curl -fsSL https://virouter.com/install/claude-code.sh | sh -s -- vr_sk_xxxxxxxxxxxx
# Then restart Claude Code
claudeThe script does not print your full key. You can also run it with VIROUTER_API_KEY if you prefer not to put the key in shell history.
export VIROUTER_API_KEY="vr_sk_xxxxxxxxxxxx"
curl -fsSL https://virouter.com/install/claude-code.sh | shRun Claude Code from a terminal where these environment variables are set.
export ANTHROPIC_BASE_URL="https://api.virouter.com"
export ANTHROPIC_AUTH_TOKEN="$VIROUTER_API_KEY"
# Optional: let Claude Code list Claude models exposed by Virouter
export CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1
claudeGenerate a server-side key in the Virouter dashboard and keep it secret.
The installer writes Anthropic gateway settings to ~/.claude/settings.json and creates a timestamped backup if the file already exists.
The installer enables CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1 so Claude Code can list active Virouter Claude models.
Start Claude Code from a new terminal so it reads the updated settings file.
If you prefer Claude Code settings over shell exports, store the same variables in your Claude Code settings. Keep the API key out of git and team-shared dotfiles. You can also download the installer script and inspect it before running.
{
"env": {
"ANTHROPIC_BASE_URL": "https://api.virouter.com",
"ANTHROPIC_AUTH_TOKEN": "vr_sk_xxxxxxxxxxxx",
"CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY": "1"
}
}Claude Code sends Anthropic Messages requests. You can smoke test the same route with cURL before starting Claude Code.
curl https://api.virouter.com/v1/messages \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $VIROUTER_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-d '{
"model": "claude-sonnet-4-6",
"max_tokens": 128,
"messages": [{"role":"user","content":"Say ok"}]
}'Claude Code can discover gateway models from /v1/models when CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1 is set. Virouter returns only active models allowed for your key.
curl https://api.virouter.com/v1/models \
-H "Authorization: Bearer $VIROUTER_API_KEY"Claude Code requests through Virouter charge your Billing USD Quota and appear in the Virouter dashboard usage log. Successful responses include gateway cost and token headers such as x-virouter-cost-usd, x-virouter-remaining-usd, and token breakdown headers.
Your Virouter key is missing, invalid, revoked, or not exported as ANTHROPIC_AUTH_TOKEN.
Use ANTHROPIC_BASE_URL=https://api.virouter.com. Do not include /v1 in this variable for Claude Code.
Your Billing USD Quota is too low for Claude Code's estimated request. Top up or reduce usage.
No healthy Anthropic lane is available for the selected Claude model. Retry or choose another active model.