LLM API Guide

Claude Code ANTHROPIC_BASE_URL Not Working: How to Fix It

Setting ANTHROPIC_BASE_URL alone doesn't replace a saved claude.ai login. Also set ANTHROPIC_AUTH_TOKEN (or ANTHROPIC_API_KEY), then confirm with /status.

Editorial illustration: Claude Code ANTHROPIC_BASE_URL Not Working: How to Fix It
Photo-style image, AI-generated

Summary

  1. ANTHROPIC_BASE_URL only routes traffic. Claude Code also needs ANTHROPIC_AUTH_TOKEN, ANTHROPIC_API_KEY or an apiKeyHelper.
  2. Run /status: an 'Anthropic base URL' line plus an 'Auth token' or 'API key' line means the gateway is active.
  3. A settings.json env value beats a shell export, and a project settings env block is read only after the trust prompt.
  4. The VS Code extension and the desktop app ignore shell exports and have their own settings.
On this page

Run /status first

Start claude, run /status and stay on the Status tab. Two lines tell you what is wrong, according to Anthropic's page on connecting Claude Code to a gateway:

  • Anthropic base URL appears only when a gateway address is set. If the line is missing, the variable never reached this session. Skip to the sections on settings files and editors below.
  • Auth token or API key names the credential in use. A Login method line naming a claude.ai account means no gateway credential is active.

If the base URL line is there but the login line shows your claude.ai account, you have the most common problem, covered next.

You set the base URL but not a credential

ANTHROPIC_BASE_URL only points Claude Code at an address. Anthropic's gateway overview says that setting it without a gateway credential doesn't replace the subscription: requests go through the gateway, but your saved claude.ai login stays the active credential.

Pick the credential variable by how the gateway expects the key:

Variable Sent as Use when the gateway says
ANTHROPIC_AUTH_TOKEN Authorization: Bearer "bearer token" or "Authorization header"
ANTHROPIC_API_KEY x-api-key "API key" or "x-api-key"
apiKeyHelper both headers the key rotates or comes from a vault

If you don't know which, start with ANTHROPIC_AUTH_TOKEN. Set both variables in the same shell:

bash
export ANTHROPIC_BASE_URL=https://llm-gateway.example.com
export ANTHROPIC_AUTH_TOKEN=sk-gateway-key

On PowerShell:

powershell
$env:ANTHROPIC_BASE_URL = "https://llm-gateway.example.com"
$env:ANTHROPIC_AUTH_TOKEN = "sk-gateway-key"

Give the base URL without /v1. Claude Code adds /v1/messages itself. This differs from OpenAI-format clients, where the base URL usually ends in /v1 (see the OpenAI Python SDK base URL guide).

Restart claude from that shell and check /status again. You want the gateway address on the base URL line and your variable's name on the Auth token or API key line.

Test the gateway with curl

Before blaming Claude Code, send a one-token request with the same variables from your shell:

bash
curl -sS -w '\n%{http_code}\n' -X POST "$ANTHROPIC_BASE_URL/v1/messages" \
  -H "Authorization: Bearer $ANTHROPIC_AUTH_TOKEN" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{"model": "claude-sonnet-4-6", "max_tokens": 1, "messages": [{"role": "user", "content": "."}]}'

A body starting with {"id":"msg_ and a content field means the URL and key work. An error about an unknown model also proves both work, because the gateway authenticated you before rejecting the model name. A 401 means the key is in a header the gateway doesn't read: for an x-api-key gateway, swap the Authorization header for x-api-key: $ANTHROPIC_API_KEY.

Any gateway that speaks the Anthropic Messages format can take this test. SeedRouter, the gateway we run, is one example: its homepage gives https://seedrouter.net as the Claude Code base URL, again without /v1.

Auth-conflict warning at startup

A warning that names two credential sources and ends in auth may not work as expected (older versions print Auth conflict: Both a token (SOURCE) and an API key (SOURCE) are set) means a gateway variable and a saved login are both active. Requests use the variable. Either unset the variable to go back to the saved login, or run /logout so only the gateway credential remains.

With ANTHROPIC_API_KEY, Claude Code asks once to approve the key. If you declined it earlier, the key is ignored silently. Re-enable it in /config with the Use custom API key option.

A settings.json value overrides your export

If a shell export and an env block in a settings file set the same variable, the settings file wins. You can export a new URL all day and still see the old one in /status. Check ~/.claude/settings.json (on Windows %USERPROFILE%\.claude\settings.json) and .claude/settings.local.json:

json
{
  "env": {
    "ANTHROPIC_BASE_URL": "https://llm-gateway.example.com",
    "ANTHROPIC_AUTH_TOKEN": "sk-gateway-key"
  }
}

Keep the credential out of a project's .claude/settings.json, because that file is committed and shared.

Claude asks you to log in even though curl works

A reachable URL is not a credential. In an interactive session, an env block in a project's .claude/settings.json or .claude/settings.local.json applies only after the first-run wizard and the trust prompt, so the login screen appears first. Put ANTHROPIC_AUTH_TOKEN somewhere Claude Code reads earlier: a shell export, the env block of ~/.claude/settings.json, or managed settings.

Your editor can't see the export

Shell exports reach only that terminal and programs started from it. An editor launched from the dock or Start menu doesn't inherit them. Either start the editor from the terminal, or put the lines in your shell profile (~/.zshrc, ~/.bashrc or PowerShell's $PROFILE) and relaunch. A settings-file env block avoids the problem, and Anthropic recommends it for background agents.

VS Code and the desktop app use different settings

The CLI reads environment variables and settings files. The other surfaces don't all do the same.

The VS Code extension checks credentials from claudeCode.environmentVariables in VS Code's own user settings (open them with Preferences: Open User Settings (JSON)) before it launches. Values in ~/.claude/settings.json reach the spawned process but not the extension's login check.

json
{
  "claudeCode.environmentVariables": [
    { "name": "ANTHROPIC_BASE_URL", "value": "https://llm-gateway.example.com" },
    { "name": "ANTHROPIC_AUTH_TOKEN", "value": "sk-gateway-key" }
  ]
}

The desktop app ignores ANTHROPIC_BASE_URL and settings.json. It reads its third-party inference configuration, either distributed by an administrator or entered locally: Help → Troubleshooting → Enable Developer Mode, then Developer → Configure Third-Party Inference. If it shows Gateway was unreachable, run the curl test above.

When the gateway answers but requests fail

Once /status and curl both look right, the problem sits in the gateway's handling of what Claude Code sends. A 400 naming Extra inputs are not permitted or context_management is covered in Claude Code API Error 400 messages, and all target providers failed in the Claude Code Router guide. If you would rather set these variables through a form than by hand, see the GUI config guide for Codex and Claude Code.

Sources and checks

  1. Connect Claude Code to an LLM gatewayChecked
  2. Other LLM gatewaysChecked