Claude Code Base URL: Setting ANTHROPIC_BASE_URL the Right Way

Wokey Team · 2026-09-24

Short answer: Claude Code's base URL is set with the ANTHROPIC_BASE_URL environment variable. Use the gateway's origin only, without /v1. For Wokey that is https://api.wokey.ai; Claude Code appends /v1/messages itself. Put your key in ANTHROPIC_AUTH_TOKEN, which is sent as Authorization: Bearer. If you set the base URL but no key, Claude Code keeps using your saved claude.ai login.

Minimal setup

export ANTHROPIC_BASE_URL="https://api.wokey.ai"
export ANTHROPIC_AUTH_TOKEN="your Wokey API key"
claude

Inside Claude Code, run /status. Requests are going through Wokey when the Status tab shows:

  • Anthropic base URL set to https://api.wokey.ai
  • an Auth token line naming ANTHROPIC_AUTH_TOKEN

If the Anthropic base URL line is missing, the variable never reached the session.

Why /v1 breaks it

Claude Code treats ANTHROPIC_BASE_URL as a prefix and requests $ANTHROPIC_BASE_URL/v1/messages. Set it to https://api.wokey.ai/v1 and the request goes to /v1/v1/messages, which Wokey answers with:

{"message":"Route POST:/v1/v1/messages not found","error":"Not Found","statusCode":404}

OpenAI-compatible clients such as Cursor or Cherry Studio conventionally take .../v1. Claude Code follows Anthropic's convention instead, and the two don't mix. Don't add /v1/messages or a trailing slash either.

AUTH_TOKEN or API_KEY

Variable Sent as Use when
ANTHROPIC_AUTH_TOKEN Authorization: Bearer <key> The gateway asks for a bearer token, or you're not sure
ANTHROPIC_API_KEY x-api-key: <key> The gateway asks for an x-api-key header

Wokey accepts either header. The difference is on the Claude Code side:

  • ANTHROPIC_AUTH_TOKEN takes effect immediately.
  • ANTHROPIC_API_KEY asks for a one-time approval in interactive mode before it takes over. A key you declined before is silently ignored.

Don't set both to different values. When the two headers carry different keys, Wokey rejects the request:

{"error":{"code":"conflicting_api_key_headers","message":"conflicting_api_key_headers","type":"invalid_request_error"}}

The same key in both headers is fine.

What happens with only the base URL set

A base URL isn't a credential. With only ANTHROPIC_BASE_URL set and no AUTH_TOKEN or API_KEY, Claude Code still sends requests with your saved claude.ai login. Wokey doesn't recognize that as a Wokey key and returns 401.

Once a gateway credential is set, your claude.ai login stays saved but unused; unset the variable to go back to it.

You may see a startup warning ending in auth may not work as expected. Older versions say Auth conflict: Both a token (SOURCE) and an API key (SOURCE) are set instead. Either one means a gateway credential and a saved login are both present. To use only the gateway, run /logout inside Claude Code to clear the saved login.

Make it permanent in settings.json

An export only lasts for the current terminal, and editors launched from the Dock or Start menu don't see it. For everyday use, put the values in the env block of ~/.claude/settings.json:

{
  "env": {
    "ANTHROPIC_BASE_URL": "https://api.wokey.ai",
    "ANTHROPIC_AUTH_TOKEN": "your Wokey API key"
  }
}
  • When the shell and a settings file set the same variable, the settings file wins. If a changed shell variable seems to have no effect, check here first.
  • For a single project, use that project's .claude/settings.local.json, and make sure it's gitignored.
  • Never put the key in a project's .claude/settings.json. That file is committed to the repository.

Choosing models

Wokey uses the same Claude model IDs as Anthropic, such as claude-opus-5, claude-sonnet-5 and claude-haiku-4-5. Switch during a session with /model. To pin which model each of Claude Code's Opus, Sonnet and Haiku tiers uses, add to env:

{
  "env": {
    "ANTHROPIC_DEFAULT_OPUS_MODEL": "claude-opus-5",
    "ANTHROPIC_DEFAULT_SONNET_MODEL": "claude-sonnet-5",
    "ANTHROPIC_DEFAULT_HAIKU_MODEL": "claude-haiku-4-5"
  }
}

ANTHROPIC_DEFAULT_HAIKU_MODEL also sets the model for background tasks such as session titles.

VS Code extension and desktop app

The VS Code extension doesn't use shell variables for its login check. Set them in VS Code's own user settings instead: run Preferences: Open User Settings (JSON) from the command palette and add:

{
  "claudeCode.environmentVariables": [
    { "name": "ANTHROPIC_BASE_URL", "value": "https://api.wokey.ai" },
    { "name": "ANTHROPIC_AUTH_TOKEN", "value": "your Wokey API key" }
  ]
}

Values in ~/.claude/settings.json reach the process the extension starts, but not the extension's own login check. If the extension keeps asking you to sign in, use the setting above.

The Claude desktop app reads neither ANTHROPIC_BASE_URL nor settings.json. To set a gateway:

  1. Open Help → Troubleshooting → Enable Developer Mode.
  2. Open Developer → Configure Third-Party Inference and enter the gateway address.

See the Claude Desktop setup guide for the full steps.

Check with curl first

From the same terminal, test without Claude Code in the loop:

curl -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-5","max_tokens":1,"messages":[{"role":"user","content":"."}]}'

What the response tells you:

  • Starts with {"id":"msg_: the URL and key are fine; the problem is in your Claude Code config.
  • 401 with code invalid_api_key: the key is missing, mistyped or deleted.
  • 404 mentioning /v1/v1/messages: the base URL has an extra /v1.
  • curl works but Claude Code still asks you to sign in: Claude Code has no credential of its own. Check that the variables were set in the same terminal that started claude, or move them into ~/.claude/settings.json.

FAQ

Should ANTHROPIC_BASE_URL include /v1?

No. Claude Code appends /v1/messages to the base URL, so https://api.wokey.ai/v1 requests /v1/v1/messages and gets a 404. For Wokey, use https://api.wokey.ai.

ANTHROPIC_AUTH_TOKEN or ANTHROPIC_API_KEY?

ANTHROPIC_AUTH_TOKEN is sent as Authorization: Bearer and takes effect immediately. ANTHROPIC_API_KEY is sent as x-api-key and needs a one-time approval in interactive mode. Wokey accepts both; ANTHROPIC_AUTH_TOKEN is recommended. Setting both to different values gets a 401 conflicting_api_key_headers.

I only set the base URL. Why is it still using my Claude subscription?

A base URL is not a credential. Without ANTHROPIC_AUTH_TOKEN or ANTHROPIC_API_KEY, Claude Code keeps using your saved claude.ai login. Add the gateway key, and run /logout if you want to clear the saved login.

I changed the environment variable. Why has nothing changed?

The env block in ~/.claude/settings.json wins over shell variables. Check it for an old value, then run /status to see the active base URL and credential source.

How do I set the base URL in the VS Code extension?

Add ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN to claudeCode.environmentVariables in your VS Code user settings JSON. The extension's login check does not read ~/.claude/settings.json.