Use Claude Code with a custom API endpoint

Claude Code reads its endpoint from two environment variables. Set them once and every session routes through your own key — billed at whatever rate your provider charges.

Don't have an account yet? You need an API key from the gateway before the steps below will work. Create one free → (no prepay, $1 minimum top-up)
Check current rates → Free to sign up · $1 minimum top-up · No prepayment
Quick self-check. Before wiring anything into your app, confirm the key works. This lists every model your account can call — it costs nothing and works from any machine:
curl https://aicomp.ai/v1/models \
  -H "Authorization: Bearer sk-your-gateway-key"

You should get back a JSON list of model IDs. If you see Invalid token, the key is wrong or was not copied in full.

Step 1 — get your key and base URL

After signing up, open the dashboard and generate an API key. The dashboard also shows your API base URL. It looks like https://aicomp.ai/v1. You need both values.

Step 2 — set the environment variables

Add these to ~/.zshrc or ~/.bashrc:

export ANTHROPIC_BASE_URL="https://aicomp.ai/v1"
export ANTHROPIC_API_KEY="sk-your-gateway-key"

Then reload your shell:

source ~/.zshrc

If you would rather not touch your profile permanently, prefix a single session instead:

ANTHROPIC_BASE_URL="https://aicomp.ai/v1" \
ANTHROPIC_API_KEY="sk-your-gateway-key" \
claude

Step 3 — verify it actually works

Before you trust it with real work, confirm the endpoint responds:

curl https://aicomp.ai/v1/messages \
  -H "x-api-key: $ANTHROPIC_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{"model":"claude-sonnet-5","max_tokens":64,
       "messages":[{"role":"user","content":"say OK"}]}'

A normal completion response means you are routing correctly.

Troubleshooting

SymptomCause
401 authentication errorKey is wrong, or belongs to a different account. Regenerate it.
404 on /v1/messagesPath doubling. If your base URL already ends in /v1, do not add it again.
Model not foundThe gateway may use a slightly different model ID. Check its model list.
Still billed by AnthropicThe variable is not in the environment Claude Code actually reads. Restart the terminal completely.

Why bother

Claude Code is the single heaviest token consumer most developers run, because it resends accumulated context on every turn. Whatever your monthly bill is today, the per-token rate is the only lever that scales with it. See the Claude Code cost calculator for your own number.

Next

Get API access