{
  "id": 22588089,
  "title": "Fixing the 3 Most Common Claude Code Custom ANTHROPIC_BASE_URL Errors (404, 401, 400)",
  "url": "https://urgent.news/2026/11/29/fixing-the-3-most-common-claude-code-custom-anthropic-base-url-errors",
  "topic": "ai",
  "section": "AI",
  "published": "2026-11-29T13:39:40.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/shiro_kuchinashi_851be38b/fixing-the-3-most-common-claude-code-custom-anthropicbaseurl-errors-404-401-400-2fdi"
  },
  "original_language": null,
  "account": "When setting up Claude Code to route through a custom Anthropic-compatible gateway, three common errors often arise: HTTP 404, 401, and 400. Here is a step-by-step checklist to troubleshoot and resolve these issues.\n\n1. HTTP 404 Error\nThe most frequent cause of a 404 error is the incorrect base URL configuration. Claude Code automatically appends \"/v1/messages\" to the base URL. If the base URL is set using the OpenAI SDK convention of appending \"/v1,\" Claude Code will send requests to \"/v1/v1/messages,\" resulting in a 404 error.\n\nTo fix this, ensure the base URL is configured correctly:\n- Incorrect: https://your-gateway.example/v1\n- Correct: https://your-gateway.example\n\n2. HTTP 401 Error\nDespite successful curl commands, an HTTP 401 error may occur when both ANTHROPIC_API_KEY and ANTHROPIC_AUTH_TOKEN are present in the shell or configuration simultaneously. This can happen if an old API key is exported in ~/.zshrc and conflicts with a new token in ~/.claude/settings.json.\n\nTo resolve this issue:\n- Check the currently exported environment variables using: env | grep ANTHROPIC\n- Keep only ANTHROPIC_AUTH_TOKEN for bearer-style gateway keys\n- Unset ANTHROPIC_API_KEY in the active shell profile\n- Restart Claude Code for the changes to take effect\n\n3. HTTP 400 Error\nOlder versions of Claude Code (5.5 and Fable 5.2) may emit legacy payloads or custom sampling fields such as temperature and top_p, which newer endpoints reject, resulting in an HTTP 400 error.\n\nTo fix this error:\n- Upgrade Claude Code to the latest release:\n- v2.1.280+ for Opus 5.5\n- v2.1.284+ for Sonnet 5.5\n- v2.1.321+ for Fable 5.2\n- Alternatively, control reasoning depth using the CLAUDE_CODE_EFFORT_LEVEL environment variable instead of manual token budgets\n- Clean the ~/.claude/settings.json file template\n- Ensure environment variables are nested inside the \"env\" object, not at the top level. For example:\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\nBefore diving into the CLI, perform a quick sanity check using curl against the /v1/messages endpoint:\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 '{\"model\": \"claude-sonnet-5-5\", \"max_tokens\": 64, \"messages\": [{\"role\": \"user\", \"content\": \"Reply with OK.\"}]}'\n\nIf the curl command returns valid JSON, but Claude Code still fails, the root cause is likely a duplicate shell environment variable or a misplaced key in ~/.claude/settings.json outside the \"env\" object.",
  "summary": "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. 1. HTTP 404 on /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…",
  "summary_source": "publisher",
  "key_points": [
    "Incorrect base URL causes 404 errors; ensure correct format",
    "Remove duplicate ANTHROPICAPIKEY and ANTHROPICAUTHTOKEN",
    "Upgrade Claude Code to latest version to resolve 400 errors"
  ],
  "editors_take": null,
  "opinion": false,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "machine_translated": false,
  "ai_generated": true,
  "disclaimer": "Accounts, briefs, key points, the editor’s take and translations are written by software from other outlets’ reporting and may contain errors. A summary whose summary_source is \"publisher\" is the outlet’s own feed text. Always check the linked original."
}