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

> Source: <https://dev.to/shiro_kuchinashi_851be38b/fixing-the-3-most-common-claude-code-custom-anthropicbaseurl-errors-404-401-400-2fdi>
> Published: 2026-11-29 13:39:40+00:00

**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 the playbook "Running AI in production": <https://wpnews.pro/playbooks/production-ops>

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