Claude Code Integration
Claude Code connects to KOPRouter over the Anthropic Messages API. Configure the Base URL, API key, and model, then keep using your existing workflow.
KOPRouter natively supports the Anthropic Messages API, and the SDK appends /v1/messages automatically. Point the Base URL at the root address — do not include /v1.
- Node.js 18 or newer (the Claude Code runtime)
- Windows users need Git for Windows installed first
Install Claude Code
Run the following in a terminal to install:
npm install -g @anthropic-ai/claude-code
Then run claude --version — seeing a version number means it installed successfully.
Core configuration
Connecting to KOPRouter needs three values:
- Base URL:
https://koprouter.kopglobal.com(the root address, without/v1) - API Key: your KOPRouter API key (prefixed with
sk-) - Model: a model ID in KOPRouter, taken from the
idreturned by/v1/models
Option 1: Write to settings.json (recommended)
Claude Code reads the user-level config file ~/.claude/settings.json. Put all three values there at once — it works for every launch method (including the VS Code / JetBrains extensions).
```bash
mkdir -p ~/.claude
nano ~/.claude/settings.json
```
```bat
if not exist "%USERPROFILE%\.claude" mkdir "%USERPROFILE%\.claude"
notepad "%USERPROFILE%\.claude\settings.json"
```
Write the following into the file (if the file already has an env, append inside it rather than adding a second "env": {}):
{
"env": {
"ANTHROPIC_BASE_URL": "https://koprouter.kopglobal.com",
"ANTHROPIC_API_KEY": "sk-...",
"ANTHROPIC_MODEL": "MODEL_ID"
}
}
Replace MODEL_ID with a model ID returned by /v1/models. Restart Claude Code for the change to take effect.
Option 2: Environment variables
If you prefer environment variables, you can export them in a terminal (current window only), or persist them in your shell startup file. Choose your operating system:
```bash
echo 'export ANTHROPIC_BASE_URL="https://koprouter.kopglobal.com"' >> ~/.zshrc
echo 'export ANTHROPIC_API_KEY="sk-..."' >> ~/.zshrc
echo 'export ANTHROPIC_MODEL="MODEL_ID"' >> ~/.zshrc
source ~/.zshrc
```
```bash
echo 'export ANTHROPIC_BASE_URL="https://koprouter.kopglobal.com"' >> ~/.bashrc
echo 'export ANTHROPIC_API_KEY="sk-..."' >> ~/.bashrc
echo 'export ANTHROPIC_MODEL="MODEL_ID"' >> ~/.bashrc
source ~/.bashrc
```
```powershell
setx ANTHROPIC_BASE_URL "https://koprouter.kopglobal.com"
setx ANTHROPIC_API_KEY "sk-..."
setx ANTHROPIC_MODEL "MODEL_ID"
```
Select and switch models
- At launch:
claude --model <MODEL_ID> - During a session: type
/model, or/model <MODEL_ID>to switch directly
Model IDs always come from the id returned by /v1/models. If you don’t set one, Claude Code uses its built-in default model name, which will fail with “model not found” if KOPRouter has no matching model.
Credential variables
Claude Code has two credential variables — set only one:
ANTHROPIC_API_KEY— sent as thex-api-keyheader, matching KOPRouter’s Anthropic auth (see the Overview). Recommended.ANTHROPIC_AUTH_TOKEN— sent as theAuthorization: Bearerheader; KOPRouter also accepts it.
Do not set both at once, or Claude Code will warn that authentication may not work as expected.
Verify
claude --version
Once configured, cd into a project and run claude to start a session. Type /status to confirm that the “Anthropic base URL” points at KOPRouter.
Troubleshooting
unset ANTHROPIC_AUTH_TOKEN
unset ANTHROPIC_BASE_URL
If the variables are written in ~/.zshrc / ~/.bashrc, remove those lines too and restart the terminal.
If your network cannot reach KOPRouter directly (e.g. mainland China), add the proxy to the same settings.json env block:
{
"env": {
"ANTHROPIC_BASE_URL": "https://koprouter.kopglobal.com",
"ANTHROPIC_API_KEY": "sk-...",
"HTTPS_PROXY": "http://127.0.0.1:7890",
"HTTP_PROXY": "http://127.0.0.1:7890"
}
}
7890 is only an example — replace it with your own proxy client’s actual port. See Network & Proxy for details.