Checked 2026-10-26

Claude Code on one key

Two environment variables point Claude Code at RelaySwitch. Same models, same tool, billed per token to a prepaid balance you top up by card or crypto.

Claude Code speaks Anthropic's Messages format and reads its endpoint from ANTHROPIC_BASE_URL. Set that to https://api.relayswitch.io/v1, put your key in ANTHROPIC_AUTH_TOKEN, and every turn bills to your balance at the rates on the model pages: Claude Sonnet 5.5 is $1.20 in and $3.00 out per million tokens today. The 11 Claude ids that answer the Anthropic format are listed under Picking a model.

01What you need

  • Claude Code installed (claude on your PATH).
  • A RelaySwitch key from the console, with a balance loaded.

02Two variables

ANTHROPIC_API_KEY works in place of ANTHROPIC_AUTH_TOKEN. Set one, not both.

bash
1export ANTHROPIC_BASE_URL="https://api.relayswitch.io/v1"
2export ANTHROPIC_AUTH_TOKEN="YOUR_RELAYSWITCH_KEY"
3claude
  • ANTHROPIC_BASE_URL points Claude Code at RelaySwitch. Paste it with the /v1; the gateway accepts the path Claude Code builds from it.
  • ANTHROPIC_AUTH_TOKEN sends the key as Authorization: Bearer. ANTHROPIC_API_KEY sends it as x-api-key. The gateway reads either header. A request that carries two different keys is refused with a 400.
  • The base URL alone is not enough. Without one of the key variables, Claude Code keeps using a saved claude.ai login.

03Make it stick

Add them to ~/.claude/settings.json under env. The model variables take any Claude id from the Models page that answers the Anthropic format.

json
1{
2 "env": {
3 "ANTHROPIC_BASE_URL": "https://api.relayswitch.io/v1",
4 "ANTHROPIC_AUTH_TOKEN": "YOUR_RELAYSWITCH_KEY",
5 "ANTHROPIC_DEFAULT_OPUS_MODEL": "claude-opus-5-5",
6 "ANTHROPIC_DEFAULT_SONNET_MODEL": "claude-sonnet-5-5",
7 "ANTHROPIC_DEFAULT_HAIKU_MODEL": "claude-haiku-5-5"
8 }
9}
  • ~/.claude/settings.json applies to every project. .claude/settings.local.json applies to one project. Keep the key out of a project's .claude/settings.json; that file is meant to be committed and shared.
  • When a shell export and a settings file set the same variable, the settings file wins.

The VS Code extension reads credentials from its own setting, claudeCode.environmentVariables, in VS Code's user settings:

json
1{
2 "claudeCode.environmentVariables": [
3 { "name": "ANTHROPIC_BASE_URL", "value": "https://api.relayswitch.io/v1" },
4 { "name": "ANTHROPIC_AUTH_TOKEN", "value": "YOUR_RELAYSWITCH_KEY" }
5 ]
6}

04Picking a model

The opus, sonnet and haiku aliases resolve to whatever the three ANTHROPIC_DEFAULT_*_MODEL variables name. Switch in a session with /model, at start with claude --model claude-opus-5-5, or for one session with ANTHROPIC_MODEL.

Use Claude ids only. A GPT, Gemini or DeepSeek id returns a 400 that says the model is served in the openai format, not anthropic; for those models use an OpenAI-compatible tool such as Cursor. The Claude ids on the key that answer the Anthropic format today:

  • claude-fable-5
  • claude-fable-5.1
  • claude-haiku-4-5
  • claude-haiku-4-5-20251001
  • claude-haiku-5-5
  • claude-opus-4-6
  • claude-opus-4-7
  • claude-opus-5
  • claude-opus-5-5
  • claude-sonnet-5
  • claude-sonnet-5-5
Per million tokens, live
Opus $2.80 in / $10.00 out · Sonnet $1.20 / $3.00 · Haiku $0.06 / $0.15. Cached input is cheaper on each; see the model pages.

05Check it

List the models your key can call:

bash
1curl https://api.relayswitch.io/v1/models -H "x-api-key: $ANTHROPIC_AUTH_TOKEN"

Send one small message. -i prints the headers, which include the request id and, on a non-streamed answer, the charge in USD.

bash
1curl -i https://api.relayswitch.io/v1/messages \
2 -H "Authorization: Bearer $ANTHROPIC_AUTH_TOKEN" \
3 -H "anthropic-version: 2023-06-01" \
4 -H "content-type: application/json" \
5 -d '{"model": "claude-haiku-5-5", "max_tokens": 16, "messages": [{"role": "user", "content": "Say ok."}]}'

Then run claude. The request shows in the console within seconds. Inside Claude Code, /status shows an Anthropic base URL line with the RelaySwitch address and an Auth token or API key line naming the variable you set. If the base URL line is missing, the variable did not reach the session.

06Caching and billing

Claude Code sends the whole conversation on every turn and marks it for the prompt cache. Tokens read from the cache bill at the cached rate on each model page, a fraction of the input rate. The cache lasts five minutes by default, so a turn after a longer break pays the input rate for the whole context once.

The cost Claude Code shows is its own estimate at Anthropic's list price. What you paid is on the console's Usage page. For one request, look it up by its id; it lands in the log within about a minute:

bash
1curl https://api.relayswitch.io/v1/requests/REQUEST_ID \
2 -H "Authorization: Bearer $ANTHROPIC_AUTH_TOKEN"

The answer lists input_tokens, cache_read_tokens, output_tokens and charge_usd. A cache_read_tokens above zero means caching worked.

07Errors and fixes

  • invalid_api_key (401): the key is wrong or revoked, or it is in a variable Claude Code did not read. Check /status.
  • insufficient_balance (402): top up in the console. monthly_limit_reached (402) means the key hit the monthly spend limit set on it.
  • model_not_found (404): the id is not on the Models page. Check the model variables for typos.
  • Claude Code asks you to log in although the curl test works: set the key in a shell export or in ~/.claude/settings.json. A project settings file applies only after the first-run setup and the trust prompt.
  • A startup warning naming two credential sources: a saved login and the variable are both active. Run /logout to keep only the key.
  • ANTHROPIC_API_KEY set but ignored: it needs a one-time approval. Turn on Use custom API key under /config, or use ANTHROPIC_AUTH_TOKEN.

Run Claude Code on a prepaid balance

Card or crypto, no KYC, no subscription.