Pointing Claude Code at a Custom API Endpoint (ANTHROPIC_BASE_URL)

Claude Code decides where to send requests from two environment variables: ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN. As long as the endpoint speaks Anthropic's Messages API, setting those two is all it takes. No patching, no forked build, no changes to the client itself.

Put it in the config file (recommended)

Drop this into ~/.claude/settings.json:

{
  "env": {
    "ANTHROPIC_AUTH_TOKEN": "<your-key>",
    "ANTHROPIC_BASE_URL": "https://relay.example.com/api/"
  }
}

The advantage over shell variables is that it does not depend on how Claude Code was launched — terminal, editor or scheduled job, the config is there. If the file already exists, merge the env block in rather than overwriting the whole file; there may be other settings in it.

Or use environment variables

export ANTHROPIC_BASE_URL=https://relay.example.com/api/
export ANTHROPIC_AUTH_TOKEN=<your-key>
claude

Convenient for a quick test, but it only applies to the current shell. Add it to ~/.zshrc or ~/.bashrc to make it stick.

Things that trip people up

  • ANTHROPIC_API_KEY and ANTHROPIC_AUTH_TOKEN are not the same thing. The first is for an official subscription or API account; the second is what custom endpoints use. Setting both makes them fight — keep only the one you need.
  • Don't drop the trailing /api/. It is the mount path of the relay endpoint; leaving it off gets you a 404.
  • Restart Claude Code after editing the config. It reads the file once at startup and will not pick up changes while running.
  • A 402 instead of a 401 means authentication went through and you are simply out of credit. Keep the two apart — they point at completely different problems.

Confirming it works

Ask anything after startup; a normal response means the request reached the new endpoint. For something more direct, check whether that request shows up in the relay's usage log — if it does, you are through.

The setup itself is not complicated. Almost every "it didn't work" comes down to one of three things: the wrong variable name, a missing trailing path, or not restarting after the edit.

← Notes

TOKEN//711
Independent relay service. Not affiliated with Anthropic, OpenAI or Google.