How to use GPT-5.1 Codex in Cursor
Cursor is one of the best AI-native editors for shipping real code, and GPT-5.1 Codex is one of the strongest models for agentic coding, refactors, and long multi-file edits. The problem is connecting them on your terms: managing keys, juggling provider accounts, and not getting locked into a single vendor. This guide shows you how to use GPT-5.1 Codex in Cursor through a single OpenAI-compatible endpoint, so you can switch models later by changing one string.
Why route Cursor through AnyModel
Cursor supports custom OpenAI-compatible models. AnyModel is exactly that: one base URL, one API key that reaches GPT, Claude, Gemini, DeepSeek, GLM, Kimi, Qwen, and Grok. You point Cursor at it once and get every model behind a single billing relationship.
- One key, every model. Switching from GPT-5.1 Codex to Claude or Gemini means changing the
modelid — nothing else. - Free to start. You get 1,000,000 tokens on signup, and a total of 6,000,000 if you link Telegram. No credit card required.
- Pay-per-token after that. No subscription, no minimums — you pay for what you use.
If you want to see the full lineup before committing, the models page lists what is available, and the compare page helps you weigh Codex against alternatives for your workload.
Step 1: Get your API key
Create an account and grab a key from your dashboard. Keep it somewhere safe — Cursor will store it in its settings.
The endpoint you will use everywhere is:
https://anymodel.org/v1
Step 2: Add the custom model in Cursor
Cursor does not have a one-line installer (that shortcut only exists for codex, claude, opencode, and hermes). For Cursor you use the manual OpenAI-compatible setup, which takes about a minute:
- Open Cursor Settings → Models (or Cursor Settings → Models → API Keys).
- Find the OpenAI API Key section and click to configure a custom base URL.
- Set Override OpenAI Base URL to
https://anymodel.org/v1. - Paste your AnyModel API key into the OpenAI key field.
- Under Add model, add the GPT-5.1 Codex model id (for example
gpt-5.1-codex), then enable it. - Save and verify the connection.
Once verified, select the model from Cursor's model picker in Chat or the Composer/Agent panel and start coding.
Step 3: Confirm it works with curl (optional)
Before debugging inside the editor, it helps to prove the endpoint and key work from the terminal. This is the same request shape Cursor sends:
curl https://anymodel.org/v1/chat/completions \
-H "Authorization: Bearer $YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5.1-codex",
"messages": [{"role": "user", "content": "Write a Python function that reverses a linked list."}]
}'
If you get a completion back, Cursor will work too. A 401 means the key or base URL is wrong; a model error means the model id needs adjusting.
Switching models without touching your setup
This is the real payoff. Because every model lives behind the same endpoint, comparing GPT-5.1 Codex against, say, Claude or Gemini on the same task is just a matter of adding another model id in Cursor's model list and picking it from the dropdown. No new keys, no new base URLs, no separate accounts.
| What you change | What stays the same |
|---|---|
The model id (e.g. gpt-5.1-codex → another model) |
Base URL https://anymodel.org/v1 |
| The model selected in Cursor's picker | Your API key and billing |
A note on privacy
By default, requests pass through to the model provider as normal. If you want stronger handling on our side, Ghost Mode gives you opt-in zero-retention keys: we do not store prompts or responses, only a token counter. To be clear, this is not "100% privacy" — the model provider still receives your prompt — but it removes our copy from the equation.
Troubleshooting
- Model not appearing: make sure you added it manually under Add model and toggled it on.
- 401 / unauthorized: re-check the base URL ends in
/v1and the key is pasted without trailing spaces. - Other editors: the same manual setup works for Windsurf, Zed, Cline, Aider, Continue, and Gemini CLI.
Want more setup walkthroughs and model comparisons? Browse the blog for guides on other tools and workflows.
Ready to code with GPT-5.1 Codex in Cursor? Create your free account and get a million tokens to start — no credit card needed.
AnyModel