How to set a custom base URL for Claude Code
Claude Code reads two environment variables. Set ANTHROPIC_BASE_URL to https://api.quickrouter.homes - the host on its own, with no /v1 suffix - and set ANTHROPIC_AUTH_TOKEN to a QuickRouter API key. Restart the CLI and every request is routed through the gateway.
Last updated: October 2026What you need before you start
Four things: a working Claude Code install, Node 18 or newer, an active gateway plan and one API key. The key is created once and works for every tool on this site.
- A QuickRouter account with an active plan - Claude Code needs an authenticated endpoint, there is no anonymous tier.
- An API key from the console: open token management, add a token and copy the value once. The full key is only shown at creation time.
- Node.js 18+ and the Claude Code CLI. Install it with npm install -g @anthropic-ai/claude-code.
- A shell you can restart, so the new environment variables are picked up.
Set the two environment variables
Export ANTHROPIC_BASE_URL with the host root and ANTHROPIC_AUTH_TOKEN with your key. Claude Code treats the Anthropic base URL as a host, not as an OpenAI-style path, so adding /v1 produces a 404 instead of a connection.
- 01
Open a terminal and export the variables
Run both lines in the shell you start Claude Code from. Use the host root, without /v1.
export ANTHROPIC_BASE_URL="https://api.quickrouter.homes" export ANTHROPIC_AUTH_TOKEN="sk-qr-your-key" - 02
Optionally pin the model
Without a model variable Claude Code uses its own default model name. Pin the gateway model you want to pay for, so the request cannot silently fall back to a name your key does not cover.
export ANTHROPIC_MODEL="claude-sonnet-4-5" - 03
Make it permanent if it works
Add the same lines to ~/.zshrc or ~/.bashrc after you have verified them. Store the key in your secret manager rather than in a dotfile you sync to a public repo.
- 04
Restart Claude Code
Environment variables are read at process start, so an already-running session keeps the old endpoint until you reopen it.
claude "summarise this repository"
Verify the request reaches the gateway
Send one prompt, then open the usage view in the console. A request that appears there with a token count and a status code came through the gateway; a response that arrives with no console entry came from somewhere else.
- In the console, open the usage view and look for a row with the model name you pinned and a timestamp from seconds ago.
- Run the built-in /status command inside Claude Code to confirm which endpoint and model the session is using.
- If you see the row and the answer, the wiring is done. Roll the key into your other machines the same way.
Errors you are most likely to hit
Nearly every Claude Code connection problem is one of three things: the wrong variable name, a /v1 suffix on the Anthropic base URL, or a model name the gateway does not serve.
| Symptom | Cause | Fix |
|---|---|---|
| 401 invalid x-api-key | ANTHROPIC_AUTH_TOKEN is unset or still holds a previous provider key | Set ANTHROPIC_AUTH_TOKEN to the gateway key and restart the CLI |
| 404 on every request | https://api.quickrouter.homes/v1 was used for ANTHROPIC_BASE_URL | Use the host root https://api.quickrouter.homes instead - Claude Code adds the path itself |
| Model not found | The pinned model name is an OpenAI-style name | Use the Anthropic model name shown in the console, for example claude-sonnet-4-5 |
| Connection reset behind a corporate proxy | The proxy intercepts TLS to the gateway host | Allow-list the gateway host, or set HTTPS_PROXY for the shell |
| Empty response, no console entry | The shell never picked up the exported variables | Re-export them, or add them to the shell profile and open a new terminal |
Which Claude model should Claude Code use?
Sonnet is the usual default for day-to-day coding, Haiku is the cheapest option for sub-agents and small edits, and Opus is reserved for the hardest reasoning steps because its output price is fifteen times Sonnet’s.
Frequently asked questions
Does Claude Code accept an OpenAI-compatible endpoint?+
Claude Code speaks the Anthropic Messages API rather than the OpenAI chat completions shape. QuickRouter exposes both, so you keep the Anthropic variable names and point them at the gateway host.
Should ANTHROPIC_BASE_URL end with /v1?+
No. Claude Code appends the path itself, so the variable holds the host root. Adding /v1 gives you a doubled path and a 404.
Can the same key power Claude Code and Cursor?+
Yes. One key covers every tool on the gateway. Cursor and similar editors take the OpenAI-style base URL with the /v1 suffix, while Claude Code takes the host root.
What does this setup cost?+
Gateway plans start at $19 per month. Model usage is drawn from your balance at the upstream list price of whichever model you call, so verifying a base URL and a key costs a fraction of a cent.
One key covers every model in this guide
Create an account, pick a plan and copy an API key. Gateway plans start at $19 per month and model usage is billed at upstream list prices.