Skip to content

Integrations / Claude Code

Use Claude Code with any model

Run Claude Code on DeepSeek, GLM and Kimi models with one prepaid key. Exact settings.json, model overrides, checks and fixes.

Get an API key

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

  1. Create a key in the console and copy it. It is shown once.

  2. Open your Claude Code settings file, ~/.claude/settings.json (on Windows, %USERPROFILE%\.claude\settings.json). Create it if it doesn’t exist.

  3. Add the env block below. Replace YOUR_YUNSHU_KEY with 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 /v1: Claude Code adds /v1/messages itself.
    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 1 Stops Claude Code sending pre-release request fields that non-Anthropic models reject.
  4. Don’t put the key in a project’s .claude/settings.json. That file is usually committed. Use ~/.claude/settings.json or .claude/settings.local.json (git-ignored) instead.

  5. 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-pro

    PowerShell:

    $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.json set 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

  1. 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 status 200 means the address and key work.

  2. Start claude and run /status. The Anthropic base URL line should show https://api.yunshurouter.com, and the Auth token line should name ANTHROPIC_AUTH_TOKEN.

  3. Send a prompt. Then open Usage in the console: the request appears with its model and cost.

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 /model picker 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_URL points 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_error Key mistyped, revoked, or in the wrong variable Copy the key again. Use ANTHROPIC_AUTH_TOKEN. If you used ANTHROPIC_API_KEY, approve it once under /config → Use custom API key.
Startup warning naming two credential sources A claude.ai login and our key are both set Run /logout, then restart claude.
404 on every request ANTHROPIC_BASE_URL ends in /v1, so requests go to /v1/v1/messages Remove /v1 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_exceeded or insufficient_balance The key’s monthly budget or your balance is used up Raise the budget or top up.
400 naming context_management or Extra inputs are not permitted Claude Code sent beta fields the model rejects Set CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1.
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_AUTH_TOKEN in ~/.claude/settings.json 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 /compact, 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).

Questions

Which models can I use in Claude Code?

Any model in our catalogue. Claude Code sends Anthropic Messages requests and we serve every model on that API. Put the model ID in ANTHROPIC_MODEL or one of the three slot variables.

Will this use my Claude subscription?

No. While ANTHROPIC_AUTH_TOKEN is set, Claude Code sends our key instead of your claude.ai login, and the request is billed per token to your Yunshu Router balance. Unset the variable to go back to your subscription.

Does count_tokens work?

Yes. We serve POST /v1/messages/count_tokens, including tool definitions, tool results and images.

Can I use one key for Claude Code and my other tools?

Yes, but a separate key per tool lets you see usage per tool and give Claude Code its own budget.

How do I see what a session cost?

Open Usage in the console and filter by the Claude Code key. Each request shows its model and cost, and you can export a CSV.