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.

In short: Cursor accepts an Anthropic API key and a custom base URL. Set both under Settings → Models and requests bill to your own key instead of Cursor's pooled quota. The setting only takes effect after a full restart, and the way to confirm it worked is that the request appears in your gateway usage log.
You need a key before the code below runs. Create an account, generate a key, and copy the base URL (https://aicomp.ai/v1). Create one free →
Check current rates → Free to sign up · $1 minimum top-up · No prepayment
Confirm the key works first. One command, no SDK, costs nothing:
Don't have an account yet? You need an API key from the gateway before the steps below will work — how the discount works and what you take on. Create one free → (no prepay, $1 minimum top-up)
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

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

The trailing /v1 is not a typo. Cursor labels this as an Anthropic override, but what it actually sends is an OpenAI-shaped request, so it needs the versioned base. This is the one place where the usual rule inverts: the Anthropic SDK appends /v1/messages itself and therefore takes a base with no /v1, while Cursor sends /chat/completions and takes a base that includes it. Dropping the /v1 here is the most common cause of a blank model list after saving.

Recent Cursor versions expose a single Override OpenAI Base URL setting instead of a separate Anthropic field. If yours is one of them, put the same value there (the label changed, the value did not). Either way 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 CursorRecommended classWhy
Autocomplete, tab completionHaiku-classHighest volume of requests, smallest context — cheap model is the right call
Normal agent / edit loopsSonnet-classBest balance of instruction following and rate
Large refactors, hard debuggingOpus-classA 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

Current gateway rate vs official list for the Claude models used in Cursor
ModelGateway rate
in / out per 1M tokens
Official list
in / out per 1M tokens
Diff
claude-haiku-4-5$0.5 / $2.5$1 / $550%
claude-sonnet-5$1 / $5$2 / $1050%
claude-opus-5$2.5 / $12.5$5 / $2550%

Rates checked 2026-11-01. 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

SymptomCause and fix
401 / invalid API keyKey truncated on copy, or wrong account. Regenerate and paste again without whitespace.
404 on the messages pathDoubled /v1. Remove the suffix from your base URL.
Model not foundThe gateway may expose the model under a slightly different ID. List available models and copy the exact string.
Still on Cursor's quotaRestart Cursor fully. Some versions only re-read the override on a cold start.
Requests hangUsually a proxy or firewall on the base URL host. Test with curl from the same machine.

Where the money actually goes, ranked

Cost advice tends to be a list of tricks with no ordering. These five are ordered by how much they typically move a real bill, and each one names the number that tells you whether it worked.

LeverWhy it worksWhat to measure to know it worked
Switch to a cheaper modelUnit price drops across every token you send.Output quality on your actual task, not on a benchmark.
Cut context per requestInput is re-sent every turn on agent workloads; trimming it compounds.Tokens per task, before and after.
Cache the stable prefixA cached prefix is billed below the uncached rate where the provider supports it.Cache-hit rate in the usage response.
Move non-urgent work to batchBatch tiers trade latency for a lower rate; the work is identical.Nothing changes in quality (only in when it finishes).
Cap output lengthOnly helps when output genuinely dominates, which it does on generation tasks.Whether output is actually the larger half of your bill.

Concretely: one day at 1200k input / 16k output costs $3.20 on claude-opus-5 and $1.28 on claude-sonnet-5, a difference of $1.92 per day, or $38.40 over a 20-day month.

The ordering is not universal It depends on your token shape. On agent loops, context size outranks model choice; on bulk generation, model choice wins because there is no context to trim. Work out which half of the sum your workload sits on before spending effort on the wrong lever. Our output vs input pricing breakdown covers how to tell.

Where this breaks in practice

SymptomWhat is actually happeningHow to confirmFix
Cursor replies but the gateway log is emptyThe override did not take effect, Cursor is still on its own quota.Send one message in a fresh chat, then check the usage log for today's date.Fully quit and restart Cursor. Some versions only re-read the override on a cold start.
404 on /v1/v1/messagesYou are on a client that speaks the native Anthropic protocol (Claude Code, the Anthropic SDK, or ChatAnthropic) and its base still ends in /v1. Cursor is not one of them: it sends an OpenAI-shaped request and needs the /v1.Look at the failing path in the error message, a doubled segment is visible in it.Drop the /v1 suffix from that client's base and leave it to the SDK. Leave Cursor's override as it is.
Autocomplete suddenly costs noticeably moreAutocomplete fires far more requests than chat, and each one now bills per token.Compare request count in the usage log before and after the change.Point tab completion at a Haiku-class model and keep Sonnet for the agent.
A long thread gets expensive fastEvery turn resends the accumulated context; cost tracks context length, not message count.Watch input tokens per request climb as the thread grows.Use /compact or start a fresh chat once a thread passes a few dozen turns.
401 after pasting a fresh keyA trailing space or a truncated paste, or the key belongs to a different account.Re-paste with no surrounding whitespace and retry a plain curl call.Regenerate the key and paste it directly from the dashboard.

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.

Related

Get API access

Rate cards: Claude and GPT