Claude Code is Anthropic’s coding agent for the terminal and VS Code. It talks to the Anthropic Messages API, which Yunshu Router serves. Set two environment variables and Claude Code sends its requests to us, on the model you choose, billed per token to your prepaid balance.
What you need
- Claude Code installed (Anthropic’s install guide).
- A Yunshu Router account with credit on the balance.
- An API key from the console (API keys → Create key). Use a separate key for Claude Code.
Set it up
-
Create a key in the console and copy it. It is shown once.
-
Open your Claude Code settings file,
~/.claude/settings.json(on Windows,%USERPROFILE%\.claude\settings.json). Create it if it doesn’t exist. -
Add the
envblock below. ReplaceYOUR_YUNSHU_KEYwith your key.{ "env": { "ANTHROPIC_BASE_URL": "https://api.yunshurouter.com", "ANTHROPIC_AUTH_TOKEN": "YOUR_YUNSHU_KEY", "ANTHROPIC_MODEL": "deepseek-v4-pro", "ANTHROPIC_DEFAULT_OPUS_MODEL": "kimi-k3", "ANTHROPIC_DEFAULT_SONNET_MODEL": "deepseek-v4-pro", "ANTHROPIC_DEFAULT_HAIKU_MODEL": "glm-5.3", "CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS": "1" } }What each line does:
Variable Value Why ANTHROPIC_BASE_ URL https:// api.yunshurouter.com Our address. No /: Claude Code addsv1 /itself.v1/ messages ANTHROPIC_AUTH_ TOKEN your key Sent as Authorization: Bearer, which we accept. Takes over from a saved claude.ai login without a prompt.ANTHROPIC_MODEL a model ID The model a new session starts on. ANTHROPIC_DEFAULT_ OPUS_ MODEL a model ID Used when you pick the Opus slot in /.model ANTHROPIC_DEFAULT_ SONNET_ MODEL a model ID Used when you pick the Sonnet slot. ANTHROPIC_DEFAULT_ HAIKU_ MODEL a model ID Used for the Haiku slot and for background tasks such as session titles. Pick a cheap model. CLAUDE_CODE_ DISABLE_ EXPERIMENTAL_ BETAS 1Stops Claude Code sending pre-release request fields that non-Anthropic models reject. -
Don’t put the key in a project’s
.claude/settings.json. That file is usually committed. Use~/.claude/settings.jsonor.claude/settings.local.json(git-ignored) instead. -
Optional: shell only. To try it in one terminal first, export the same variables:
export ANTHROPIC_BASE_URL=https://api.yunshurouter.com export ANTHROPIC_AUTH_TOKEN=YOUR_YUNSHU_KEY export ANTHROPIC_MODEL=deepseek-v4-proPowerShell:
$env:ANTHROPIC_BASE_URL = "https://api.yunshurouter.com" $env:ANTHROPIC_AUTH_TOKEN = "YOUR_YUNSHU_KEY" $env:ANTHROPIC_MODEL = "deepseek-v4-pro"If both the shell and
settings.jsonset a variable, the settings file usually wins.
VS Code extension
The Claude Code extension checks credentials from VS Code’s own settings. Open Preferences: Open User Settings (JSON) and add:
{
"claudeCode.environmentVariables": [
{ "name": "ANTHROPIC_BASE_URL", "value": "https://api.yunshurouter.com" },
{ "name": "ANTHROPIC_AUTH_TOKEN", "value": "YOUR_YUNSHU_KEY" },
{ "name": "ANTHROPIC_MODEL", "value": "deepseek-v4-pro" },
{ "name": "CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS", "value": "1" }
]
}
Check it works
-
Test the key with curl before you open Claude Code (same shell as the exports):
curl -sS -w '\n%{http_code}\n' "$ANTHROPIC_BASE_URL/v1/messages" \ -H "Authorization: Bearer $ANTHROPIC_AUTH_TOKEN" \ -H "anthropic-version: 2023-06-01" \ -H "content-type: application/json" \ -d '{"model": "deepseek-v4-pro", "max_tokens": 16, "messages": [{"role": "user", "content": "Say hi"}]}'A JSON reply with
"content"and status200means the address and key work. -
Start
claudeand run/status. The Anthropic base URL line should showhttps://api.yunshurouter.com, and the Auth token line should nameANTHROPIC_AUTH_TOKEN. -
Send a prompt. Then open Usage in the console: the request appears with its model and cost.
Recommended models
| Model ID | Use it for |
|---|---|
deepseek-v4-pro |
Main model for everyday work |
glm-5.3 |
Haiku slot and quick edits |
kimi-k3 |
Opus slot, long tasks with many tool calls |
Set a budget on the key
Claude Code can run for a long time without you watching. In the console, open API keys, pick the Claude Code key and set:
- a monthly budget: requests that would take the key past it are refused with
402 budget_exceeded, and Claude Code stops with an error instead of spending more; - a model allow-list with only the models you put in
settings.json; - an alert by email or webhook when the key nears its budget.
Your balance is prepaid, so even several Claude Code sessions at once cannot spend more than it.
Known limitations
- Anthropic does not support Claude Code on other makers’ models.
- The
/modelpicker shows Anthropic’s names. Your models sit behind the Opus, Sonnet and Haiku slots. - Remote Control, voice dictation and Claude Code on the web need a claude.ai login and don’t
run through a gateway key. Remote Control is also off while
ANTHROPIC_BASE_URLpoints at a host other than Anthropic’s. - Fast mode (
/fast) checks availability with Anthropic, so it is usually off through a gateway, and it has no effect on non-Claude models. - Exact repeats of a request are answered from cache and not charged; agent sessions rarely repeat exactly, so expect few cache hits.
Troubleshooting
| What you see | Likely cause | Fix |
|---|---|---|
401 / authentication_ |
Key mistyped, revoked, or in the wrong variable | Copy the key again. Use ANTHROPIC_. If you used ANTHROPIC_, approve it once under / → Use custom API key. |
| Startup warning naming two credential sources | A claude.ai login and our key are both set | Run /, then restart claude. |
404 on every request |
ANTHROPIC_ ends in /, so requests go to / |
Remove / from the base URL. |
404 naming the model |
Model ID typo, or a model not in the catalogue | Check the ID on the models page. IDs are lowercase with dots, e.g. glm-5.3. |
403 naming the model |
The model is not on this key’s allow-list | Add it to the key in the console, or pick an allowed model. |
402 budget_ or insufficient_ |
The key’s monthly budget or your balance is used up | Raise the budget or top up. |
400 naming context_ or Extra inputs are not permitted |
Claude Code sent beta fields the model rejects | Set CLAUDE_. |
400 naming thinking or adaptive |
The model doesn’t accept Claude’s adaptive thinking request | — |
| Claude Code still asks you to log in | The key is only in a project settings file, read after the first-run screen | Put ANTHROPIC_ in ~/ or export it in the shell. |
| A long session stops with a context error | The model’s context window is smaller than the conversation | Run /, or use a model with a larger window (see its model page). |
| Answer stops mid-stream with an error | The upstream failed after the stream started; we send an error event instead of a cut answer | Retry. If it repeats, name a fallback model (see Fallbacks and combos). |