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 ~/.bashrcMethod 2: Per-Session
Set variables before running Claude Code:
bash
ANTHROPIC_BASE_URL="https://toprouter.cc" \
ANTHROPIC_API_KEY="sk-your-toprouter-key" \
claudeMethod 3: VS Code Settings
For the VS Code Claude Code extension:
- Open VS Code Settings (
Cmd+,/Ctrl+,) - Search for "Claude"
- Set the API Base URL to
https://toprouter.cc - 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.
Recommended Models
| Model | Use Case |
|---|---|
anthropic/claude-4.8-opus | Complex analysis, large codebases |
anthropic/claude-4.6-sonnet | Daily coding, balanced performance |
Troubleshooting
"API key invalid" error
- Verify the key is correct and active on the API Keys page
- Ensure
ANTHROPIC_API_KEYis set (notOPENAI_API_KEY)
"Connection refused" error
- Check that
ANTHROPIC_BASE_URLis set tohttps://toprouter.cc(no/v1) - Verify your network connection
Model not found
- Use supported Claude model names like
anthropic/claude-4.8-opusoranthropic/claude-4.6-sonnet
