In Mainland China? Start from Claude Code in China (no VPN, card or Alipay top-up) and the China setup tutorial for 429/DNS fixes. This guide is the region-agnostic setup.
Claude Code is Anthropic's official CLI tool for working with Claude directly in your terminal. By default, it connects straight to the Anthropic API — which works, but gives you no visibility into spending, no budget controls, and no fallback if the API goes down.
Connecting Claude Code through Router One takes about two minutes and gives you per-request usage tracking, per-key spend caps, and the request-level observability layer that comes with the platform. Here is exactly how to set it up.
Prerequisites
Before you start, make sure you have:
- Claude Code installed — follow the official installation guide if you have not already
- A Router One account — sign up at router.one if you need one
That is it. No additional dependencies or tools required.
Step 1: Get Your Router One API Key
Log in to Router One and open Dashboard → API Keys. Click Create Key and give it a descriptive name like "claude-code-personal" or "claude-code-work".
Copy the generated API key. You will need it in the next step. The key starts with sk-; keep it secret. If you lose track of it, you can reveal it again later from the key list with Reveal Key (the eye icon next to the masked key).
While you are in the dashboard, note your available balance. Router One uses a prepaid credit model, so make sure you have sufficient funds loaded for your expected usage.
One command does Steps 2 and 3 for you and verifies the key: curl -fsSL https://router.one/install/claude-code.sh | bash -s -- sk-your-router-one-key — see the CLI setup guide for Windows and the manual version.
Step 2: Point Claude Code at Router One
Claude Code reads the Anthropic-compatible endpoint and credential from your shell environment. This keeps the setup simple and aligns with the official CLI workflow.
Export these two variables in your current shell:
export ANTHROPIC_BASE_URL=https://api.router.one
export ANTHROPIC_AUTH_TOKEN=sk-your-router-one-api-key
unset ANTHROPIC_API_KEY
Replace sk-your-router-one-api-key with the actual API key you copied in Step 1.
What each variable does:
ANTHROPIC_BASE_URL— Tells Claude Code to send requests to Router One's Anthropic-compatible gateway instead of directly to Anthropic.ANTHROPIC_AUTH_TOKEN— The credential Claude Code sends to a third-party gateway as theAuthorization: Bearerheader. Set it to your Router One key.ANTHROPIC_API_KEY— Not required. On current builds, setting it triggers an extra approval prompt at launch, so leave it unset (andunsetit in the same shell if you exported it earlier, plus remove it from~/.zshrcor~/.bashrc).
Step 3: Persist the Setup
If you want this setup to survive new terminal sessions, add the same two export lines to your shell profile (~/.zshrc or ~/.bashrc) — and while you are in there, delete any leftover ANTHROPIC_API_KEY line.
Step 4: Pin the Model Aliases
Claude Code 2.1.284 (September 28, 2026) points the sonnet alias at Claude Sonnet 5.5 and sends claude-sonnet-5-5, per the Claude Code changelog and model configuration docs (checked 2026-09-29). Router One lists claude-sonnet-5-5 from 2026-09-29, but no Pro, Max or Ultra tier lists it in the 2026-09-29 plan response, so on a plan everything that goes through the sonnet alias — /model sonnet, subagents defined with model: sonnet, /statusline and the execution phase of opusplan — bills per token to the wallet. Pin these aliases; the Sonnet line keeps those requests on Claude Sonnet 5, which is in the Mid-tier models tier of all three plans:
export ANTHROPIC_DEFAULT_SONNET_MODEL=claude-sonnet-5
export ANTHROPIC_DEFAULT_HAIKU_MODEL=claude-haiku-4-5
The Haiku line is optional: it runs background tasks on Claude Haiku 4.5 rather than the main model. Per Claude Code's changelog, model configuration and subagents docs (Claude Code 2.1.300, checked 2026-10-15), from 2.1.293 the haiku alias resolves to Claude Haiku 5.5 (claude-haiku-5-5), which Router One lists as of the 2026-10-10 catalog but no plan tier lists in the 2026-10-10 plan response. Without the line, /model haiku, subagents defined with model: haiku and the built-in claude-code-guide subagent (which the subagents docs list as running on Haiku) therefore bill per token to the wallet; with it they run on Claude Haiku 4.5, which is in the Standard models tier of all three plans. The fable alias needs no pin: per Claude Code's model configuration docs (Claude Code 2.1.300, checked 2026-10-15), it resolves to Claude Fable 5.1 (claude-fable-5-1), which Router One lists again as of the 2026-10-15 catalog and which, like Claude Fable 5, is in no plan tier as of the 2026-10-15 plan response, so it bills to the wallet. If you added ANTHROPIC_DEFAULT_FABLE_MODEL=claude-fable-5 earlier, the alias stays on Claude Fable 5 until you remove that line. On the wallet, drop the Sonnet line if you want the sonnet alias on Claude Sonnet 5.5.
Plan holders: Claude Code 2.1.280 and later sends claude-opus-5-5 unless a model is pinned, and as of the 2026-09-29 plan response no Pro, Max or Ultra tier lists Claude Opus 5.5, so those calls bill per token to your wallet. To keep drawing plan quota, also pin Claude Opus 5, which the plans' Premium models tier covers:
export ANTHROPIC_MODEL=claude-opus-5
export ANTHROPIC_DEFAULT_OPUS_MODEL=claude-opus-5
ANTHROPIC_MODEL sets the session model; ANTHROPIC_DEFAULT_OPUS_MODEL points the opus alias at Opus 5 as well, so /model opus and subagents defined with model: opus stay on the plan too. Claude Sonnet 5 sits in the Mid-tier models tier and Claude Haiku 4.5 in the Standard models tier of all three plans; Claude Fable 5.1 and Claude Fable 5 are in no tier as of the 2026-10-15 plan response and bill to the wallet. If you used the one-click installer, put these keys in the env block of ~/.claude/settings.json instead — a value there overrides the shell export. Claude Code on Opus 5.5 covers the details.
Step 5: Verify It Works
Open a new terminal window and launch Claude Code:
claude
Send a simple message to confirm the connection is working:
> Hello, can you confirm this is working?
If you get a normal response, your setup is complete. All requests are now flowing through Router One.
To double-check, go back to the Router One dashboard and open Dashboard → Logs. You should see the request you just made, including the model used, tokens consumed, and cost.
Tips for Getting the Most Out of This Setup
Monitor Your Usage per Request
Dashboard → Logs records every Claude Code request — tokens consumed, cost per request, model used and response latency; reload the page (or return to its tab) to see the newest rows. This is especially useful if you use Claude Code heavily for development work, where token usage can add up quickly during long coding sessions.
Bookmark your dashboard and check it periodically to understand your usage patterns.
Set a Per-Key Spend Cap
Open Dashboard → API Keys and set maxSpend on the key used by Claude Code. The key stops spending when it reaches that cap. If several developers or projects share one wallet, give each one a separate key so its usage and exposure stay isolated.
Use a Separate API Key per Project
If you work across multiple projects, create a separate API key for each one and set its spending cap. Dashboard → Logs filters by model, API key, status and date range, and Dashboard → Usage ranks your API keys by spend, tokens and requests, so a key per project gives you per-project cost directly. For attribution below the key (per task or per run), save your own label with request IDs in your client or application logs.
Check Your Balance Before Long Sessions
Claude Code sessions for complex refactoring or large codebases can consume significant tokens. A quick glance at your Router One balance before starting a major session helps you avoid interruptions mid-task.
Secure Your API Key
For production or shared machines, keep the Router One key in your shell profile rather than retyping it in every terminal:
export ANTHROPIC_BASE_URL=https://api.router.one
export ANTHROPIC_AUTH_TOKEN="sk-your-router-one-api-key"
Troubleshooting
"Authentication failed" error — Double-check that your API key is correct and that your Router One account has a positive balance. Keys are case-sensitive. Also confirm ANTHROPIC_API_KEY is not exported in this shell: Claude Code authenticates against a third-party gateway with ANTHROPIC_AUTH_TOKEN, and a leftover ANTHROPIC_API_KEY only adds an approval prompt. The Claude Code 403 checklist covers the rest.
"Connection refused" error — Verify ANTHROPIC_BASE_URL is exactly https://api.router.one with no trailing slash or extra path segments.
Slow responses — Router One adds little overhead of its own; measured end-to-end latency from mainland China is on the China latency benchmark. If responses feel slow, check the Router One dashboard for latency metrics. The issue is more likely upstream provider latency than the gateway itself.
Settings not taking effect — Open a new terminal window after exporting the variables, or run the export commands again in your current shell before launching claude.
FAQ
How do I connect Claude Code to Router One?
Export ANTHROPIC_BASE_URL=https://api.router.one and set ANTHROPIC_AUTH_TOKEN to your Router One API key, then add the same exports to your shell profile (~/.zshrc or ~/.bashrc). The whole setup takes about two minutes.
Do I need to set ANTHROPIC_API_KEY when using Router One?
No. ANTHROPIC_API_KEY is not required — on current builds, setting it triggers an extra approval prompt at launch. Claude Code sends ANTHROPIC_AUTH_TOKEN as the Authorization: Bearer header to a third-party gateway, so leave ANTHROPIC_API_KEY unset and delete any leftover line from ~/.zshrc or ~/.bashrc.
How do I verify that Claude Code requests are going through Router One?
Open a new terminal, run claude, and send a test message. Then open Dashboard → Logs in the Router One dashboard — you should see the request you just made, including the model used, tokens consumed, and cost.
Why does Claude Code show an "Authentication failed" error with Router One?
Double-check that your API key is correct and that your Router One account has a positive balance — keys are case-sensitive. Also confirm ANTHROPIC_API_KEY is not exported in this shell; the Claude Code 403 checklist covers the rest.
Does routing Claude Code through Router One slow down responses? Router One adds little overhead of its own; measured end-to-end latency from mainland China is on the China latency benchmark. If responses feel slow, check the Router One dashboard for latency metrics — the issue is more likely upstream provider latency than the gateway itself.
What Happens Next
With Claude Code connected through Router One, every request is tracked and metered, while the key's maxSpend cap and default rate limits bound that workload. You get the same Claude experience with visibility into what you are spending and how you are using it.
Explore the Router One dashboard to see request analytics and set a spend cap on each key (rate limits apply at platform defaults and can be raised on request). If you are using other AI tools beyond Claude Code, give each tool its own key and route it through the same gateway. The same /v1/messages endpoint also carries Claude's server-side web_search and code_execution tools for your own API calls — see Claude web search and code execution through the API.
Sign up or log in at router.one to get started.