Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

Claude Code — custom API endpoint setup

Point Claude Code at a third-party Anthropic-compatible endpoint via settings.json.

The one thing people get wrong

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.

Configure

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

Run

claude
/model claude-sonnet-4-6

Troubleshooting

Symptom Cause Fix
Prompts for Anthropic login /v1 in the base URL Use the site root
401 Variable name mismatch Swap ANTHROPIC_AUTH_TOKENANTHROPIC_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

If your endpoint only speaks OpenAI protocol

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.


Verify before you debug

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_KEY

It reports which protocol the endpoint speaks, TTFT, the advertised model list, and whether your model id is actually on it.


Other agents

Configs for Claude Code, Kilo Code, OpenCode, Aider, Codex, Cursor, LiteLLM and LangChain: ai-coding-agent-api-configs


Endpoint used in the examples

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.

Get a key · Docs

License

MIT

About

Claude Code custom API key setup — configure ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN in settings.json on Windows and macOS to use a third-party Anthropic-compatible endpoint.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages