How to connect Claude to Cursor with an API key
How to connect Claude to Cursor with your own API key: where the Cursor API key goes, the Cursor base URL, custom models, plus OpenCode and Kimi Code.
· 5 min read

How do you connect Claude to Cursor with your own API key? Cursor lets you replace its built-in key and address, so the chat and the agent run on Claude models. This post shows where the Cursor API key goes, how to set the Cursor base URL and which custom model names to add. It ends with a short look at OpenCode and Kimi Code, and the full OpenCode walkthrough is in OpenCode setup with Claude models.
This post covers three tools people ask about most often: Cursor, OpenCode and Kimi Code. In every example {BASE} is the address from your dashboard and {KEY} is your key. If you do not have them yet, create an account first.
Cursor base URL: with or without /v1
The same Base URL serves two kinds of requests:
| Path | Format | Address in the app |
|---|---|---|
/v1/messages | Claude Messages, the "Anthropic" protocol | Without /v1, the app adds the path |
/v1/chat/completions | OpenAI-compatible | With /v1 |
Getting this one detail wrong is the most common reason for a 404. When an app asks for an "Anthropic" or "Claude" protocol, leave /v1 off. When it asks for an OpenAI Base URL, add it. The API overview in the docs lists all endpoints.

Cursor Claude API key and custom models
Cursor lets you override the address it uses for OpenAI-style models and add your own model names.
- Open Settings, then Models.
- Under API Keys, paste your key into the OpenAI API Key field.
- Turn on Override OpenAI Base URL and enter
{BASE}/v1. - Add custom models with short names:
sonnet-5.5,opus-5.5,haiku-5.5andfable-5.2. - Turn off the models you do not want to see, then pick one of yours in the chat or agent panel.
Keep in mind that tab completion in Cursor always runs on Cursor's built-in models. The chat, the agent and inline edits use the model you pick, and those are the parts that go through your key. The step-by-step guide shows where each field is.
OpenCode
OpenCode is a terminal coding agent that also comes as a desktop app and a web interface. It keeps its configuration in ~/.config/opencode/opencode.json, and all three versions read the same file.
The simplest way is to let one command write the whole file: the address, the key and the four Claude models with their context size. The OpenCode setup page has that command ready to copy for Windows, macOS and Linux.

opencode.json with the address, the key and the four models.A few things worth knowing:
- OpenCode talks to the address in the Claude Messages format, so tool calls, images and long context all work as they do in Claude Code.
- Set the context size to 1,000,000 tokens and the output size to 32,000 tokens. With a smaller context value, OpenCode starts compacting the conversation much earlier than it needs to.
- Switch models with the model picker or the
/modelscommand. Your choice stays for the session.

Kimi Code CLI
Kimi Code CLI reads its address and key only from a config file, ~/.kimi-code/config.toml. There is no environment variable for it, so editing the file is the only way. A minimal file with one model looks like this:
default_model = "claude-sonnet-5-5"
[providers.hummbit]
type = "anthropic"
base_url = "{BASE}"
api_key = "{KEY}"
[models."claude-sonnet-5-5"]
provider = "hummbit"
model = "claude-sonnet-5-5"
max_context_size = 1000000
capabilities = ["thinking", "image_in", "tool_use"]Note three things:
default_modelhas to be at the very top of the file, before any section.- The address goes in without
/v1, becausetype = "anthropic"makes Kimi add the path. - Each model needs its own block, so add the other three the same way.
The Kimi Code CLI setup page writes the full file with all four models in one command.
Inside the CLI, /model switches models and kimi -c continues your last session.

/model in Kimi Code CLI lists the models from config.toml.Kimi Code App
The desktop app has its own settings and does not read the CLI file.
- Click the gear in the bottom left and open Model Providers.
- Add a new provider and choose Custom, not one of the presets.
- Give it a name and set API Protocol to Anthropic.
- Paste your key and the address, again without
/v1. - Use Fetch model list, or add the four models by hand. For each one, set Context to 1000000.
The Kimi Code App setup page shows each of these screens.
Which Claude model to pick in Cursor
For everyday coding in any of these apps, Sonnet 5.5 is a good default. Switch to Opus 5.5 for long agent runs across many files, use Fable 5.2 when a task needs the deepest reasoning, and keep Haiku 5.5 for quick questions and sub-agents. The post on the Claude 5.5 models explains the difference in more detail.
If Claude in Cursor does not work
| What you see | What to check |
|---|---|
| 404 on every request | /v1 in the address against the format the app uses |
| Model not found | A typo or the wrong form of the name. Use the exact names from /v1/models |
| The app keeps compacting the chat | Raise the context size in its settings to 1000000 |
For other editors and agents, from Cline to Zed, see all setup guides.


