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.
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
| Symptom | Cause |
|---|---|
| 401 authentication error | Key is wrong, or belongs to a different account. Regenerate it. |
404 on /v1/messages | Path doubling. If your base URL already ends in /v1, do not add it again. |
| Model not found | The gateway may use a slightly different model ID. Check its model list. |
| Still billed by Anthropic | The 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
- Claude Sonnet 5 pricing — the usual default for agent coding
- Claude Opus 5 pricing — for the hardest reasoning
- Do the same in Cursor