Point Claude Code at a third-party
Anthropic-compatible endpoint via settings.json.
Claude Code speaks the Anthropic Messages protocol. The base URL is the
site root with no /v1:
CORRECT: https://apimaster.ai
WRONG: https://apimaster.ai/v1
With /v1 appended, Claude Code builds https://host/v1/v1/messages, gets a
404, and falls back to prompting you for an Anthropic login — which looks like
an auth bug but isn't.
Windows — Win + R → %userprofile%\.claude
macOS / Linux — ~/.claude
Create or edit settings.json:
{
"env": {
"ANTHROPIC_BASE_URL": "https://apimaster.ai",
"ANTHROPIC_AUTH_TOKEN": "YOUR_API_KEY",
"CLAUDE_CODE_ATTRIBUTION_HEADER": "0",
"CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS": "1"
}
}CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS matters: third-party endpoints often
don't implement Anthropic's beta headers, and leaving them on causes requests
to fail in ways the error message doesn't explain.
claude
/model claude-sonnet-4-6| Symptom | Cause | Fix |
|---|---|---|
| Prompts for Anthropic login | /v1 in the base URL |
Use the site root |
401 |
Variable name mismatch | Swap ANTHROPIC_AUTH_TOKEN ↔ ANTHROPIC_API_KEY — which one is read depends on version |
| Unknown model | Id not served here | Check your endpoint's model list |
| Works, then breaks after update | New betas re-enabled | Confirm the two CLAUDE_CODE_* flags survived |
Then Claude Code can't reach it directly. Use claude-code-router as a translation layer, and give it the full endpoint path so it doesn't mis-join:
{
"Providers": [{
"name": "custom",
"api_base_url": "https://apimaster.ai/v1/chat/completions",
"api_key": "YOUR_API_KEY",
"models": ["claude-sonnet-4-6"]
}]
}Then set ANTHROPIC_BASE_URL to your local CCR address.
Check whether you need this at all — run check_endpoint.py below. If the
Anthropic Messages test passes, connect directly and skip CCR entirely.
Before blaming the agent, confirm the endpoint itself works. This repo ships a zero-dependency checker that tests both protocols and prints the exact base_url to paste into each tool:
python check_endpoint.py --url https://apimaster.ai --key YOUR_API_KEYIt reports which protocol the endpoint speaks, TTFT, the advertised model list, and whether your model id is actually on it.
Configs for Claude Code, Kilo Code, OpenCode, Aider, Codex, Cursor, LiteLLM and LangChain: ai-coding-agent-api-configs
Examples use https://apimaster.ai/v1, an OpenAI-compatible endpoint fronting
multiple model providers with one key. Every config here works with any
OpenAI-compatible endpoint — substitute your own, including a self-hosted
new-api or LiteLLM proxy.
MIT