Claude Code Custom Base URL Troubleshooting: 404, 401 & 400 Fixes
Resolve the top 5 Claude Code LLM gateway failures in minutes: remove trailing /v1 from ANTHROPIC_BASE_URL, use ANTHROPIC_AUTH_TOKEN alone, pin exact Claude 5.x model IDs, and verify minimum CLI versions.
1. One-Minute Claude Code Gateway Error Matrix
When routing Claude Code through a custom gateway like DeepClub (see Claude Code Custom Base URL Setup), almost every startup or runtime error maps to one of five root causes:
| Symptom / HTTP Code | Most Likely Root Cause | Immediate Fix |
|---|---|---|
HTTP 404 Not Found (/v1/v1/messages) |
ANTHROPIC_BASE_URL ends with /v1 |
Set ANTHROPIC_BASE_URL="https://deepclub.net" with no trailing /v1 |
| HTTP 401 Unauthorized | Both ANTHROPIC_API_KEY and ANTHROPIC_AUTH_TOKEN are set, or token has whitespace / expired / disabled |
Unset ANTHROPIC_API_KEY, keep only ANTHROPIC_AUTH_TOKEN, and check key status in console |
| HTTP 400 Bad Request on Claude 5.5 / Fable 5.2 | Outdated Claude Code sending legacy thinking.budget_tokens or custom sampling params (temperature / top_p) |
Upgrade Claude Code to v2.1.280+ (Opus 5.5), v2.1.284+ (Sonnet 5.5), or v2.1.321+ (Fable 5.2) |
| Model Not Found / 404 | Floating alias or vendor prefix like anthropic/claude-opus-5-5 or retired model name |
Pin an exact canonical ID from Live Pricing: claude-sonnet-5-5, claude-opus-5-5, claude-fable-5-2 |
~/.claude/settings.json Ignored |
Shell environment variables override JSON, or invalid JSON syntax / missing "env" wrapper |
Inspect `env |
2. Clean Shell & ~/.claude/settings.json Diagnostic Checklist
Run these three commands first to clear conflicting variables and verify the exact gateway endpoint active in your shell:
# 1) Check for conflicting env vars (stale ANTHROPIC_API_KEY is the #1 hidden 401 cause)
env | grep -E 'ANTHROPIC_|CLAUDE_CODE_'
# 2) Clear conflicting key and test with a clean gateway configuration
unset ANTHROPIC_API_KEY
export ANTHROPIC_BASE_URL="https://deepclub.net"
export ANTHROPIC_AUTH_TOKEN="sk-your-deepclub-key"
export ANTHROPIC_MODEL="claude-sonnet-5-5"
# 3) Confirm CLI version meets Claude 5.x minimum requirements
claude --version
Then run a direct curl probe against POST /v1/messages outside Claude Code. If curl returns 200 while Claude Code fails, the issue is strictly local CLI config or version:
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"}]}'
3. Correct ~/.claude/settings.json Structure
A common mistake is placing ANTHROPIC_BASE_URL at the JSON root instead of inside "env":
{
"env": {
"ANTHROPIC_BASE_URL": "https://deepclub.net",
"ANTHROPIC_AUTH_TOKEN": "sk-your-deepclub-key",
"ANTHROPIC_MODEL": "claude-sonnet-5-5",
"CLAUDE_CODE_EFFORT_LEVEL": "medium"
}
}
Inside Claude Code, run /status to verify https://deepclub.net and the pinned model ID are loaded. After your first prompt, open DeepClub Usage Logs to confirm the request landed cleanly.
Related Guides
- Claude Code Custom ANTHROPIC_BASE_URL Setup · Claude Code Prompt Caching & Effort Cost Guide
- Claude Code vs Codex CLI vs Cursor (2026 BYOK) · Global LLM API 401/404/400/429 Troubleshooting
Frequently Asked Questions
- Why does Claude Code fail with 404 when ANTHROPIC_BASE_URL has /v1?
- Claude Code appends /v1/messages to ANTHROPIC_BASE_URL automatically. Setting https://deepclub.net/v1 produces https://deepclub.net/v1/v1/messages and returns HTTP 404. Use https://deepclub.net instead.
- Why do I get 401 even though my DeepClub key works in curl?
- Check whether both ANTHROPIC_API_KEY and ANTHROPIC_AUTH_TOKEN are exported in your shell or settings.json. Remove ANTHROPIC_API_KEY so only ANTHROPIC_AUTH_TOKEN is sent, and verify your sub-key is enabled with remaining quota.
- Why does Claude Opus 5.5 or Fable 5.2 return 400 in older Claude Code versions?
- Claude Opus 5.5, Sonnet 5.5, and Fable 5.2 reject legacy thinking.budget_tokens and custom temperature/top_p overrides on native /v1/messages. Upgrade Claude Code to v2.1.280+ (Opus 5.5), v2.1.284+ (Sonnet 5.5), or v2.1.321+ (Fable 5.2).
Updated