Urgent.News

What's breaking now, across hundreds of outlets.

AI

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

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…

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.

1. HTTP 404 Error

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

To fix this, ensure the base URL is configured correctly:

- Incorrect: https://your-gateway.example/v1

- Correct: https://your-gateway.example

2. HTTP 401 Error

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

To resolve this issue:

- Check the currently exported environment variables using: env | grep ANTHROPIC

- Keep only ANTHROPIC_AUTH_TOKEN for bearer-style gateway keys

- Unset ANTHROPIC_API_KEY in the active shell profile

- Restart Claude Code for the changes to take effect

3. HTTP 400 Error

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

To fix this error:

- Upgrade Claude Code to the latest release:

- v2.1.280+ for Opus 5.5

- v2.1.284+ for Sonnet 5.5

- v2.1.321+ for Fable 5.2

- Alternatively, control reasoning depth using the CLAUDE_CODE_EFFORT_LEVEL environment variable instead of manual token budgets

- Clean the ~/.claude/settings.json file template

- Ensure environment variables are nested inside the "env" object, not at the top level. For example:

{

"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 diving into the CLI, perform a quick sanity check using curl against the /v1/messages endpoint:

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

Rewritten by urgent.news; may contain errors — check the original.

Source: dev.to

Read the original at dev.to →

Report a problem with this story

More in AI

Olares One: A Local AI Server with an API Layer

Olares One: a local AI server with an API layer The Olares One is a $4,999 personal AI cloud computer built to run assistants, coding tools, generative models and home-lab applications locally.

  • Olares One AI server priced at $4,999
  • Features 96GB RAM, RTX 5090 GPU, Intel Ultra 9 CPU
  • Includes local API layer for developers

More from Sunday, 29 November 2026 →