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 real-time usage tracking, per-key spend and rate controls, 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 the Router One dashboard and navigate to the API Keys section. Click Create New 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- and is only shown once, so save it somewhere secure.
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.
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: 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 look at the Usage section. 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 in Real Time
The Router One dashboard shows every Claude Code request in real time — tokens consumed, cost per request, model used, and response latency. 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. Name the key after its project, then use the dashboard's per-key view to compare token usage and cost; Router One does not expose a separate project-level usage dimension.
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 minimal overhead (typically under 10ms). 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 check the Usage section of 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 minimal overhead, typically under 10ms. 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 and rate controls 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 configure per-key spend and rate controls. If you are using other AI tools beyond Claude Code, give each tool its own key and route it through the same gateway.
Sign up or log in at router.one to get started.