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.

**Prerequisites**
  • 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 id returned 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).

The file path is `~/.claude/settings.json`. Create the `.claude` directory first if it doesn't exist:
```bash
mkdir -p ~/.claude
nano ~/.claude/settings.json
```
The file path is `C:\Users\\.claude\settings.json`. Using CMD as an example:
```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.

* Values under `env` are literal — no `~` or `$VAR` expansion. * Optional: add `"CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1"` under `env` to turn off non-essential background telemetry requests.

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:

Write to `~/.zshrc` (zsh is the default shell on macOS). Run:
```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
```
Write to `~/.bashrc` (most distros default to bash). Run:
```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
```
Run the following in PowerShell (permanent for the current user; reopen the terminal afterwards):
```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 the x-api-key header, matching KOPRouter’s Anthropic auth (see the Overview). Recommended.
  • ANTHROPIC_AUTH_TOKEN — sent as the Authorization: Bearer header; 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

Clear the old environment variables first, then reconfigure:
unset ANTHROPIC_AUTH_TOKEN
unset ANTHROPIC_BASE_URL

If the variables are written in ~/.zshrc / ~/.bashrc, remove those lines too and restart the terminal.

`ANTHROPIC_MODEL` (or the value you pass to `/model`) must be an `id` returned by `/v1/models`; anything else returns a 404.
**Can't connect (network restricted)?**

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.