Claude Code
Claude Code is Anthropic's terminal coding agent. It reads its endpoint and credential from environment variables, so pointing it at the Cequence AI Gateway is a matter of exporting the right values before you start it — no config file to edit.
Setup
Claude Code speaks Anthropic's native API shape. Pick the mode your LLM Registry entry runs in.
- Anthropic
- Direct — gateway-managed key
- Passthrough — your own Anthropic key
The gateway stores the Anthropic credential on the entry, so Claude Code sends only its Agent Access Key.
export ANTHROPIC_BASE_URL="https://<gateway-host>/llm/<url-prefix>"
export ANTHROPIC_API_KEY="<your-agent-access-key>"
export ANTHROPIC_MODEL="<model-id>"
Then restart Claude Code, or open a new terminal, so it picks up the new environment.
What each line does:
ANTHROPIC_BASE_URLpoints Claude Code at the gateway instead of Anthropic's API directly.ANTHROPIC_API_KEYcarries your Agent Access Key. Claude Code sends this value as thex-api-keyheader, which the gateway accepts as the caller's credential. The gateway then attaches the stored Anthropic credential on the outbound side.ANTHROPIC_MODELsets which model Claude Code requests. Use an identifier from the entry's Allowed Models list. Leave it out to keep Claude Code's own default — but if the entry restricts models, its default may not be one the entry permits.
The gateway holds no Anthropic credential on this entry, so the ANTHROPIC_API_KEY slot belongs to your own Anthropic key. The Agent Access Key travels in a custom header instead.
export ANTHROPIC_BASE_URL="https://<gateway-host>/llm/<url-prefix>"
export ANTHROPIC_API_KEY="<your-anthropic-api-key>"
export ANTHROPIC_CUSTOM_HEADERS="X-Agent-Key: <your-agent-access-key>"
export ANTHROPIC_MODEL="<model-id>"
Then restart Claude Code, or open a new terminal, so it picks up the new environment.
What each line does:
ANTHROPIC_BASE_URLpoints Claude Code at the gateway instead of Anthropic's API directly.ANTHROPIC_API_KEYcarries your own Anthropic key, which the gateway forwards to Anthropic unchanged.ANTHROPIC_CUSTOM_HEADERScarries the Agent Access Key onX-Agent-Key. This is what identifies you to the gateway for enforcement and audit — without it the call is rejected, even though your Anthropic key is valid.ANTHROPIC_MODELsets which model Claude Code requests. Use an identifier from the entry's Allowed Models list.
The two credentials do different jobs and are not interchangeable. Your Anthropic key authenticates you to Anthropic; the Agent Access Key authenticates you to the gateway. In this mode both are needed, in the two separate variables above.
Where to find each value
| Placeholder | Where to find it |
|---|---|
<gateway-host> | Host from the LLM Registry entry's Overview tab (e.g., gw.aigateway.example.com) |
<url-prefix> | The URL prefix field on the entry's Overview tab |
<model-id> | A model identifier from the entry's Allowed Models list |
<your-agent-access-key> | Generate from the LLM Registry entry's Agent Access Keys step; plaintext is shown once |
<your-anthropic-api-key> | Your own Anthropic API key — only needed in passthrough mode |
The entry's Connect flow assembles all of this for you with the real values filled in, ready to copy.
Tips
ANTHROPIC_API_KEYmust always be set. If Claude Code finds it empty, it falls back to its own sign-in flow and never reaches the gateway — which looks like the gateway ignoring you, when in fact Claude Code never sent it a request.- Restart after any change. Claude Code reads these variables at startup only, so
exportthem and then start a fresh session. - Check the endpoint before the credential. If Claude Code reports a generic authentication error, compare
ANTHROPIC_BASE_URLagainst the URL shown in the entry's Connect flow first — a wrong URL prefix produces the same error message as a bad key. - Unset when finished. If you set these only to try the gateway out, run
unset ANTHROPIC_BASE_URL ANTHROPIC_API_KEY ANTHROPIC_CUSTOM_HEADERS ANTHROPIC_MODELto return Claude Code to its normal behavior — otherwise every later session keeps routing through the gateway.
Cequence AI Gateway