Skip to content

Claude Code Setup ​

Use TopRouter as the API provider for Claude Code CLI and the VS Code Claude Code extension.

Environment Variables ​

Set the following environment variables to route Claude Code through TopRouter:

bash
export ANTHROPIC_BASE_URL="https://toprouter.cc"
export ANTHROPIC_API_KEY="sk-your-toprouter-key"

Important

Do not add /v1 to the base URL for Claude Code. The client automatically appends the correct path.

Setup Methods ​

Method 1: Shell Profile (Persistent) ​

Add to your ~/.bashrc, ~/.zshrc, or ~/.profile:

bash
# TopRouter for Claude Code
export ANTHROPIC_BASE_URL="https://toprouter.cc"
export ANTHROPIC_API_KEY="sk-your-toprouter-key"

Then reload your shell:

bash
source ~/.zshrc  # or ~/.bashrc

Method 2: Per-Session ​

Set variables before running Claude Code:

bash
ANTHROPIC_BASE_URL="https://toprouter.cc" \
ANTHROPIC_API_KEY="sk-your-toprouter-key" \
claude

Method 3: VS Code Settings ​

For the VS Code Claude Code extension:

  1. Open VS Code Settings (Cmd+, / Ctrl+,)
  2. Search for "Claude"
  3. Set the API Base URL to https://toprouter.cc
  4. Set your API Key

Or add to settings.json:

json
{
  "claude-code.apiBaseUrl": "https://toprouter.cc",
  "claude-code.apiKey": "sk-your-toprouter-key"
}

Verify Connection ​

After setup, test the connection:

bash
claude "Hello, what model are you?"

You should see a response from the configured model.

ModelUse Case
anthropic/claude-4.8-opusComplex analysis, large codebases
anthropic/claude-4.6-sonnetDaily coding, balanced performance

Troubleshooting ​

"API key invalid" error ​

  • Verify the key is correct and active on the API Keys page
  • Ensure ANTHROPIC_API_KEY is set (not OPENAI_API_KEY)

"Connection refused" error ​

  • Check that ANTHROPIC_BASE_URL is set to https://toprouter.cc (no /v1)
  • Verify your network connection

Model not found ​

  • Use supported Claude model names like anthropic/claude-4.8-opus or anthropic/claude-4.6-sonnet

TIP

Need help? Join our Telegram or Discord for support.

Unified AI API Gateway — Access 200+ models through one endpoint.