How to connect Claude Code CLI to any Anthropic-compatible API gateway
Developers can redirect Claude Code's CLI to any third-party API gateway that supports the Anthropic Messages protocol using just two environment variables: ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN. The most common configuration mistake is appending /v1 to the base URL, which causes Claude Code to request /v1/v1/messages and receive a 404 error. A recommended two-step curl test — first fetching available model IDs, then sending a minimal Messages request — helps isolate whether a failure stems from the gateway or from Claude Code's own configuration. If curl succeeds but the CLI still fails, developers should check for mismatched shell sessions, wrong token variable names, model alias mismatches, or settings files overriding environment variables. API keys should never be committed to version control and must be rotated immediately if exposed.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in