How to use the Claude API in Cursor with your own key
Cursor can talk to the Anthropic API using your own key and your own endpoint. Set it up once and every request bills against your key instead of Cursor's pooled quota — which makes the per-token rate the only variable that decides your monthly bill.
https://aicomp.ai/v1).
Create one free →
curl https://aicomp.ai/v1/models \
-H "Authorization: Bearer sk-your-gateway-key"
A JSON list of model IDs means the key is good. Invalid token means it was copied wrong.
What you need before you start
- An API key from the gateway, plus the base URL (
https://aicomp.ai/v1) - Cursor installed (any recent version — the setting lives under Settings → Models)
- Two minutes, and one test message to confirm routing
Step 1 — generate the key
Sign up, open the dashboard, and generate a key. Copy it in full — truncated keys are the single most common cause of a 401 on the first try. Keep the base URL next to it; you need both values in the next step.
Step 2 — add the key in Cursor
Open Cursor Settings → Models. Find the Anthropic section and paste your key into the API key field. In most versions this immediately enables the Claude models in the model picker.
Step 3 — override the base URL
Adding the key alone sends traffic to Anthropic's own endpoint. To route through the gateway instead, set the Anthropic base URL field to:
https://aicomp.ai/v1
Do not add /v1 twice. If your base URL already ends in /v1, the client adds the rest of the path itself, and a doubled segment is what produces a 404 on /v1/v1/messages.
If your version of Cursor does not expose the field in the UI, it is also readable from settings.json. Restart Cursor after editing it directly:
{
"anthropicBaseUrl": "https://aicomp.ai/v1",
"anthropicApiKey": "sk-your-gateway-key"
}
Step 4 — choose a model on purpose
Model choice is where most of the money is decided, and it is a per-task decision rather than a global one:
| Task in Cursor | Recommended class | Why |
|---|---|---|
| Autocomplete, tab completion | Haiku-class | Highest volume of requests, smallest context — cheap model is the right call |
| Normal agent / edit loops | Sonnet-class | Best balance of instruction following and rate |
| Large refactors, hard debugging | Opus-class | A wrong answer costs more engineer time than the token difference |
Step 5 — confirm it actually took effect
Send one short message in a new chat. A normal reply is necessary but not sufficient — Cursor can succeed while still using its own quota. The decisive check is your gateway dashboard: the request should appear in the usage log within a minute. If nothing shows up, you are not routing yet.
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.
Agent mode is the expensive part: every turn resends the accumulated context, so cost grows with conversation length rather than message count. Use /compact or start a fresh chat when a thread gets long, and estimate your own number with the Cursor cost calculator.
Troubleshooting
| Symptom | Cause and fix |
|---|---|
| 401 / invalid API key | Key truncated on copy, or wrong account. Regenerate and paste again without whitespace. |
| 404 on the messages path | Doubled /v1. Remove the suffix from your base URL. |
| Model not found | The gateway may expose the model under a slightly different ID. List available models and copy the exact string. |
| Still on Cursor's quota | Restart Cursor fully. Some versions only re-read the override on a cold start. |
| Requests hang | Usually a proxy or firewall on the base URL host. Test with curl from the same machine. |
FAQ
Can I use the Claude API in Cursor instead of Cursor's own quota?
Yes. Cursor accepts an Anthropic API key and lets you override the base URL. Once both are set, requests bill to your key instead of consuming Cursor's pooled quota.
Which Claude model should I use in Cursor?
Sonnet-class models are the default for agent work because they balance reasoning and cost. Use Haiku-class for autocomplete and cheap edits, and reserve Opus-class for the hardest refactors where a wrong answer costs more than the tokens do.
Why is Cursor still billing me after I added my own key?
Three usual causes: the base URL override was not saved, Cursor needs a full restart to drop the cached key, or the 'use my own key' toggle is off for that model. Check your gateway usage log — if no request appears there, Cursor is still using its own quota.
Does using my own key work with Cursor's agent mode?
Yes, as long as the model you selected is reachable through the endpoint you configured. Agent mode sends more context per turn, so the per-token rate matters more there than in chat.
Is this allowed by Anthropic's terms?
You are using your own credentials to access the API. What matters is that the key is yours and the endpoint is one you chose to route through — the same way you would point any SDK at a different base URL.