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. 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 .