{"slug": "fixing-the-3-most-common-claude-code-custom-anthropic-base-url-errors-404-401", "title": "Fixing the 3 Most Common Claude Code Custom ANTHROPIC_BASE_URL Errors (404, 401, 400)", "summary": "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.", "body_md": "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.\n\n`/v1/v1/messages`\nClaude Code automatically appends `/v1/messages` to whatever you set in `ANTHROPIC_BASE_URL`.\n\nIf you follow OpenAI SDK conventions and append `/v1` to the base URL, Claude Code sends requests to `/v1/v1/messages` and gets a 404.\n\n`https://your-gateway.example/v1`\n`https://your-gateway.example`\n`curl` succeeds\nThis 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`).\n\nCheck what your shell is actually exporting:\n\n```\nenv | grep ANTHROPIC\n```\n\nKeep **only** `ANTHROPIC_AUTH_TOKEN` for bearer-style gateway keys and unset `ANTHROPIC_API_KEY` in the active shell profile before restarting Claude Code.\n\nOlder 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.\n\nTwo quick fixes:\n\n`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\nOne subtle gotcha: environment variables must be nested inside the `\"env\"` object. Putting them at the top level of `settings.json` is silently ignored.\n\n```\n{\n  \"env\": {\n    \"ANTHROPIC_BASE_URL\": \"https://deepclub.net\",\n    \"ANTHROPIC_AUTH_TOKEN\": \"sk-your-key\",\n    \"ANTHROPIC_MODEL\": \"claude-sonnet-5-5\",\n    \"CLAUDE_CODE_EFFORT_LEVEL\": \"medium\"\n  }\n}\n```\n\nBefore debugging the CLI itself, verify your endpoint and token directly against `/v1/messages`:\n\n```\ncurl -sS https://deepclub.net/v1/messages \\\n  -H \"Authorization: Bearer $ANTHROPIC_AUTH_TOKEN\" \\\n  -H \"anthropic-version: 2023-06-01\" \\\n  -H \"content-type: application/json\" \\\n  -d '{\n    \"model\": \"claude-sonnet-5-5\",\n    \"max_tokens\": 64,\n    \"messages\": [{\"role\": \"user\", \"content\": \"Reply with OK.\"}]\n  }'\n```\n\nIf `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`.", "url": "https://wpnews.pro/news/fixing-the-3-most-common-claude-code-custom-anthropic-base-url-errors-404-401", "canonical_source": "https://dev.to/shiro_kuchinashi_851be38b/fixing-the-3-most-common-claude-code-custom-anthropicbaseurl-errors-404-401-400-2fdi", "published_at": "2026-11-29 13:39:40+00:00", "updated_at": "2026-11-29 13:44:09.780012+00:00", "lang": "en", "topics": ["ai-tools", "developer-tools", "large-language-models", "ai-agents"], "entities": ["Claude Code", "Anthropic", "deepclub.net", "Opus 5.5", "Sonnet 5.5", "Fable 5.2"], "also_reported_by": [], "takeaway": "Set ANTHROPIC_BASE_URL without a trailing /v1 because Claude Code appends /v1/messages itself, keep only ANTHROPIC_AUTH_TOKEN when using bearer-style gateway keys, and nest env vars inside the \"env\" object in ~/.claude/settings.json.", "recommendation": {"advice": "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.", "playbook": "production-ops", "playbook_url": "https://wpnews.pro/playbooks/production-ops"}, "alternates": {"html": "https://wpnews.pro/news/fixing-the-3-most-common-claude-code-custom-anthropic-base-url-errors-404-401", "markdown": "https://wpnews.pro/news/fixing-the-3-most-common-claude-code-custom-anthropic-base-url-errors-404-401.md", "text": "https://wpnews.pro/news/fixing-the-3-most-common-claude-code-custom-anthropic-base-url-errors-404-401.txt", "jsonld": "https://wpnews.pro/news/fixing-the-3-most-common-claude-code-custom-anthropic-base-url-errors-404-401.jsonld"}}