cd /news/ai-tools/fixing-the-3-most-common-claude-code… · home › topics › ai-tools › article
[ARTICLE · art-178133] src=dev.to ↗ pub= topic=ai-tools verified=true sentiment=· neutral

Fixing the 3 Most Common Claude Code Custom ANTHROPIC_BASE_URL Errors (404, 401, 400)

A developer published a diagnostic checklist for the three most common errors (404, 401, 400) encountered when routing Claude Code through a custom Anthropic-compatible gateway via ANTHROPIC_BASE_URL. The guide traces the 404 to Claude Code auto-appending /v1/messages to a base URL that already ends in /v1, the 401 to conflicting ANTHROPIC_API_KEY and ANTHROPIC_AUTH_TOKEN environment variables, and the 400 to outdated binaries sending legacy thinking.budget_tokens or sampling fields rejected by newer endpoints. It recommends verifying the endpoint with a direct curl request to /v1/messages and nesting environment variables inside the "env" object in ~/.claude/settings.json, since top-level keys are silently ignored.

recommendation

When Claude Code fails against a custom gateway, curl /v1/messages directly first, then check for a duplicated /v1 in the base URL, conflicting ANTHROPIC_API_KEY and ANTHROPIC_AUTH_TOKEN vars, or env keys placed outside "env" in settings.json.

more in playbook: Running AI in production
by read2 min views11 publishedNov 29, 2026

When routing Claude Code through a custom Anthropic-compatible gateway, most broken setups come down to three specific errors. Here is the exact diagnostic checklist I keep handy whenever a fresh machine refuses to connect.

/v1/v1/messages Claude Code automatically appends /v1/messages to whatever you set in ANTHROPIC_BASE_URL.

If you follow OpenAI SDK conventions and append /v1 to the base URL, Claude Code sends requests to /v1/v1/messages and gets a 404.

https://your-gateway.example/v1 https://your-gateway.example curl succeeds This usually happens when both ANTHROPIC_API_KEY and ANTHROPIC_AUTH_TOKEN are present in your shell or config at the same time (for example, an old key exported in ~/.zshrc colliding with a new token in ~/.claude/settings.json).

Check what your shell is actually exporting:

env | grep ANTHROPIC

Keep only ANTHROPIC_AUTH_TOKEN for bearer-style gateway keys and unset ANTHROPIC_API_KEY in the active shell profile before restarting Claude Code.

Older Claude Code binaries still emit legacy thinking.budget_tokens payloads or custom sampling fields (temperature / top_p) that newer Claude 5.5 and Fable 5.2 endpoints reject with HTTP 400.

Two quick fixes:

v2.1.280+ for Opus 5.5, v2.1.284+ for Sonnet 5.5, v2.1.321+ for Fable 5.2).CLAUDE_CODE_EFFORT_LEVEL instead of manual thinking token budgets.~/.claude/settings.json template One subtle gotcha: environment variables must be nested inside the "env" object. Putting them at the top level of settings.json is silently ignored.

{
  "env": {
    "ANTHROPIC_BASE_URL": "https://deepclub.net",
    "ANTHROPIC_AUTH_TOKEN": "sk-your-key",
    "ANTHROPIC_MODEL": "claude-sonnet-5-5",
    "CLAUDE_CODE_EFFORT_LEVEL": "medium"
  }
}

Before debugging the CLI itself, verify your endpoint and token directly against /v1/messages:

curl -sS https://deepclub.net/v1/messages \
  -H "Authorization: Bearer $ANTHROPIC_AUTH_TOKEN" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{
    "model": "claude-sonnet-5-5",
    "max_tokens": 64,
    "messages": [{"role": "user", "content": "Reply with OK."}]
  }'

If curl returns a valid JSON message but Claude Code still fails, the cause is almost always a duplicate shell env var or a misplaced key outside "env" in ~/.claude/settings.json.

── more in #ai-tools 4 stories · sorted by recency
── more on @claude code 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/fixing-the-3-most-co…] indexed:0 read:2min 2026-11-29 · —