Run Claude Code on the Crazyrouter API
One command writes the three environment variables Claude Code needs. Native Anthropic protocol, so streaming, tools, thinking and prompt caching behave exactly as they do against Anthropic — billed per token at Crazyrouter rates.
One-command setup
Claude Code reads ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN at startup. Set them to Crazyrouter and every session, sub-agent and hook call goes through your Crazyrouter key. The scripts below are the same ones published in the GitHub repo; nothing is installed beyond Claude Code itself.
- 1Run the command
Pulls the script from GitHub; nothing else is downloaded.
- 2Paste your Crazyrouter key
Pick a default model when asked; you can change it later.
- 3Tool talks to Crazyrouter
Config or env vars are written; the next launch routes through your key.
curl -fsSL https://raw.githubusercontent.com/xujfcn/crazyrouter-claude-code/main/configure.sh | bash
irm https://raw.githubusercontent.com/xujfcn/crazyrouter-claude-code/main/windows/configure.ps1 | iex
What the script does
- Asks for your Crazyrouter API key and a default model
- Writes ANTHROPIC_BASE_URL / ANTHROPIC_AUTH_TOKEN / ANTHROPIC_MODEL as user-level environment variables
- Also sets OPENAI_API_KEY / OPENAI_BASE_URL so the same key works in OpenAI-compatible tools
- Use setup.sh / setup.ps1 instead on a fresh machine: it installs Node.js and Claude Code first
Scripts are fetched from the public GitHub repo linked below. Read them before piping to a shell if that's your policy; the download-then-run form is in the README.
Manual configuration
macOS / Linux — ~/.zshrc or ~/.bashrc
export ANTHROPIC_BASE_URL="https://api.crazyrouter.com" export ANTHROPIC_AUTH_TOKEN="sk-your-crazyrouter-key" export ANTHROPIC_MODEL="claude-opus-4-8"
Root domain only — Claude Code appends /v1/messages itself. Do not add /v1.
Windows PowerShell (persistent)
[Environment]::SetEnvironmentVariable('ANTHROPIC_BASE_URL', 'https://api.crazyrouter.com', 'User')
[Environment]::SetEnvironmentVariable('ANTHROPIC_AUTH_TOKEN', 'sk-your-crazyrouter-key', 'User')
[Environment]::SetEnvironmentVariable('ANTHROPIC_MODEL', 'claude-opus-4-8', 'User')Or per-project — .claude/settings.json
{
"env": {
"ANTHROPIC_BASE_URL": "https://api.crazyrouter.com",
"ANTHROPIC_AUTH_TOKEN": "sk-your-crazyrouter-key",
"ANTHROPIC_MODEL": "claude-opus-4-8"
}
}https://api.crazyrouter.com — This tool speaks a vendor-native protocol and appends its own path. Use the root domain exactly as shown — no /v1.
Recommended models
Live Crazyrouter prices, refreshed hourly. Any model in the catalogue works; these are the ones we'd start with.
FAQ
Do I need an Anthropic account?
No. Your Crazyrouter key replaces the Anthropic key; Claude Code never contacts api.anthropic.com.
Which base URL do I use?
https://api.crazyrouter.com — the root domain with no path. Claude Code appends /v1/messages itself; adding /v1 causes 404s.
Does /login or OAuth still work?
Skip /login. With ANTHROPIC_AUTH_TOKEN set, Claude Code authenticates with the token and never opens the browser flow.
Can I switch models mid-session?
Yes — /model inside Claude Code, or change ANTHROPIC_MODEL. Any Claude model in the Crazyrouter catalogue works; Opus for hard refactors, Sonnet for daily work, Haiku for cheap sub-agents.
Is prompt caching and extended thinking supported?
Yes. Requests are relayed on the native Messages API, so cache_control breakpoints and thinking budgets pass through unchanged and cached reads are billed at the cache rate.
