Claude Code base_url

Claude Code Base URL (ANTHROPIC_BASE_URL) Setup Guide

Claude Code has no setting literally called base_url — it reads the ANTHROPIC_BASE_URL environment variable. This guide covers what to set it to, which auth variable goes with it, where to put it so it always applies, and the most common mistakes.

Get started · View pricing

ANTHROPIC_BASE_URL

Use the gateway root https://gw-link.com (or the US endpoint https://gw-link.ai) without /v1 — Claude Code appends /v1/messages itself.

ANTHROPIC_AUTH_TOKEN

Your gw-link sk- key, sent as Authorization: Bearer. ANTHROPIC_API_KEY (x-api-key header) is accepted too, but Claude Code asks you to confirm it on first launch.

The env block in settings.json

Values in the env block of ~/.claude/settings.json apply to every terminal and IDE session — more reliable than exporting them in one shell.

Recommended setup

  1. Create an API key in the gw-link console and open Use Key to see the Claude Code configuration.
  2. Put ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN in the env block of ~/.claude/settings.json.
  3. Optionally pin a default model with ANTHROPIC_MODEL, using an ID returned by /v1/models.
  4. Open a new terminal, run claude and confirm you get a reply.

Configuration examples

~/.claude/settings.json

{
  "env": {
    "ANTHROPIC_BASE_URL": "https://gw-link.com",
    "ANTHROPIC_AUTH_TOKEN": "sk-your-gw-link-key",
    "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1"
  }
}

Current shell only

export ANTHROPIC_BASE_URL="https://gw-link.com"
export ANTHROPIC_AUTH_TOKEN="sk-your-gw-link-key"
export CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1
claude

Verify the key and network with curl

A model list means the key works and the endpoint is reachable; a 401 means the key is wrong.

curl https://gw-link.com/v1/models \
  -H "Authorization: Bearer sk-your-gw-link-key"

FAQ

What should Claude Code's base URL be?

Set ANTHROPIC_BASE_URL=https://gw-link.com, or https://gw-link.ai for the US endpoint. Never add a /v1 suffix.

ANTHROPIC_AUTH_TOKEN or ANTHROPIC_API_KEY?

Prefer ANTHROPIC_AUTH_TOKEN (Bearer auth, no confirmation prompt). gw-link also accepts x-api-key, so ANTHROPIC_API_KEY works too — just don't set both to different values.

What does CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC do?

It turns off Claude Code's telemetry and error-reporting calls so all traffic goes to the gateway you configured, avoiding stalls when those services are unreachable.

My change doesn't take effect — why?

An older export in your shell profile can override settings.json. Remove duplicates and open a new terminal or restart the IDE after editing.

中文版

Last updated: