Back to blog
GuideAugust 18, 2026

Claude Code on CloseRouter: ANTHROPIC_BASE_URL

Claude Code talks to Anthropic’s API by default. A custom gateway is ANTHROPIC_BASE_URL. That changes the host for the same Messages API. It is not a “any model in the world” switch.

Official: Other LLM gateways. Anthropic does not endorse third-party gateways and does not support running Claude Code against non-Claude models.

What ANTHROPIC_BASE_URL does

The variable is the host. Without it — production Anthropic. With it — your gateway.

A URL alone is not enough. You need a gateway credential. Anthropic’s docs: setting only BASE_URL does not drop a claude.ai login. Traffic may go through the gateway while billing stays on the subscription until a gateway key is present.

Claude Code appends /v1/messages. So BASE_URL usually has no /v1/messages suffix.

How the client sends secrets (why gateways disagree on env):

  • ANTHROPIC_AUTH_TOKENAuthorization: Bearer …
  • ANTHROPIC_API_KEYx-api-key

A gateway that expects Bearer almost always wants TOKEN. A gateway that expects x-api-key wants API_KEY. If both are set, behavior depends on the client and a cached login. Do not paste someone else’s block blindly.

Where to write the config

Use ~/.claude/settings.json (Windows: %USERPROFILE%\.claude\settings.json) so it survives the terminal.

OpenRouter notes that the native installer does not read a project .env. Do not commit the key. $HOME is the right place. A project .claude/settings.json with a gateway URL in git is a bad idea.

If you used to log in to Anthropic: /logout, quit, reopen. On macOS OpenRouter mentions Keychain Claude Code-credentials.

In-session check: /status shows which token and which base URL.

Three working examples

Check slugs in each dashboard. Below is only host + which key goes where.

CloseRouter

{
  "env": {
    "ANTHROPIC_BASE_URL": "https://api.closerouter.dev",
    "ANTHROPIC_API_KEY": "YOUR_API_KEY"
  }
}

Delete ANTHROPIC_AUTH_TOKEN. Host without /v1. Key from closerouter.dev/keys.

Installer: bash <(curl -fsSL https://closerouter.dev/install.sh). It prompts for the key without placing it in shell history, writes those two fields, and removes AUTH_TOKEN. Guide: docs/claude.

OpenRouter

From their cookbook:

export ANTHROPIC_BASE_URL="https://openrouter.ai/api"
export ANTHROPIC_AUTH_TOKEN="$OPENROUTER_API_KEY"
export ANTHROPIC_API_KEY=""

Order matters: TOKEN expands when you source. The key must be set above that in the profile. They only guarantee first-party Anthropic as the priority provider.

Then /logout if you had an old login. /status should show ANTHROPIC_AUTH_TOKEN and https://openrouter.ai/api.

Kie.ai

From their guide:

ANTHROPIC_BASE_URL=https://api.kie.ai/claude

Either ANTHROPIC_API_KEY="Bearer <key>" (the word Bearer and a space) or ANTHROPIC_AUTH_TOKEN=<key> with no prefix. Do not log in with an Anthropic account after installing the CLI. Do not append /v1/messages.

Codex and Cursor are not BASE_URL

Codex speaks OpenAI /v1, not the Anthropic host.

CloseRouter (add model_provider yourself after the installer):

model_provider = "closerouter"

[model_providers.closerouter]
name = "CloseRouter"
base_url = "https://api.closerouter.dev/v1"
wire_api = "responses"
env_key = "CLOSEROUTER_API_KEY"

Export CLOSEROUTER_API_KEY in the environment that launches Codex; the token does not belong in config.toml.

OpenRouter cookbook: model_provider = "openrouter", base_url = https://openrouter.ai/api/v1, key via auth.command, not only env_key.

Cursor: Override OpenAI Base URL + key in the UI. It does not read an env file by itself.

How to pick a gateway for an agent

  1. A live /v1/messages (or their Anthropic-skin host).
  2. Documented header they expect.
  3. Clear billing and a per-key limit.
  4. They do not overwrite the client default model unless you asked.

Direct Anthropic is the reference. OpenRouter is the wide catalog and failover. CloseRouter is one RU/EN dashboard, SBP, the installer, both contracts. LiteLLM if the proxy must be yours. Kie Claude if you already live in their credits for media and want the same wallet for CLI — Kie’s main product is still async Market, not that host.

Common breaks

SymptomCheck
Asks for Anthropic loginNo gateway key; skipped /logout; profile not reloaded
401Wrong header (TOKEN vs API_KEY); Kie missing Bearer
Hits Anthropic, not the gatewayLive ANTHROPIC_API_KEY on an OR setup; BASE_URL not picked up
model not foundWrong slug; OR with a non-empty API_KEY + old login
Works in CLI, not in the IDEIDE cannot see user env; use settings.json or a full restart

claude --debug prints the real URL. Faster than guessing.

FAQ

Can BASE_URL feed GPT into Claude Code?
Anthropic does not support that. A gateway might; the client does not as a supported path.

Why is the subscription still there?
No gateway credential. BASE_URL alone does not drop the subscription.

Does CloseRouter need /v1? No. OpenRouter Claude path is https://openrouter.ai/api. Kie is https://api.kie.ai/claude.

Where is the protocol for my own gateway?
Anthropic’s Gateway protocol: which headers to forward so you do not strip CLI features.

Tags

ANTHROPIC_BASE_URLANTHROPIC_AUTH_TOKENclaude code custom endpoint