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.
What it costs
| Model | Gateway rate in / out per 1M tokens | Official list in / out per 1M tokens | Diff |
|---|---|---|---|
| claude-haiku-4-5 | $0.5 / $2.5 | $1 / $5 | 50% |
| claude-sonnet-5 | $1 / $5 | $2 / $10 | 50% |
| claude-opus-5 | $2.5 / $12.5 | $5 / $25 | 50% |
Rates checked 2026-09-16. Gateway rates move with upstream promotions — verify the current number in your dashboard before committing to a budget.
Model choice matters more here than anywhere else, because agent loops resend context on every turn. The full breakdown is in what Claude Code costs per month.
FAQ
Does Claude Code really work with a custom endpoint?
Yes. Claude Code reads ANTHROPIC_BASE_URL and ANTHROPIC_API_KEY from the environment, so setting those two variables routes every session through the endpoint you choose — no change to how you use the tool.
Which model should I point Claude Code at?
Sonnet-class is the default choice for agent work; Haiku-class is worth it for mechanical edits, and Opus-class for the hardest debugging. The spread between them is large enough to change your monthly bill by a factor of several — see the table above.
How much does it cost per month?
It is pure token spend, driven mostly by how much context each turn resends rather than by message count. See the dedicated breakdown in what Claude Code costs per month, or use the Claude Code cost calculator with your real session length.
Why am I still being billed by Anthropic?
The variables are not reaching the process. Export them from your shell profile and restart the terminal completely — a reloaded profile in an already-running shell is the usual cause.
Can I switch back?
Yes. Unset the two variables, or keep them in a separate profile file you source only when you want the alternate route. Nothing about your project changes.
Next
- Claude Sonnet 5 pricing — the usual default for agent coding
- Claude Opus 5 pricing — for the hardest reasoning
- Do the same in Cursor
- Eight ways to cut the bill