How to Add Custom API Keys to Cursor: Complete Guide (2026)
Use your own OpenAI, Anthropic, and Google API keys in Cursor
Start Building with Hypereal
Access Kling, Flux, Sora, Veo & more through a single API. Free credits to start, scale to millions.
No credit card required • 100k+ developers • Enterprise ready
How to Add Custom API Keys to Cursor: Complete Guide (2026)
Cursor is one of the most popular AI-powered code editors, but its built-in AI usage comes with monthly limits. By adding your own API keys, you can bypass these limits, choose your preferred models, and control costs directly. This guide walks you through adding API keys from OpenAI, Anthropic, Google, and other providers to Cursor.
Why Add Custom API Keys?
There are several reasons to bring your own API keys to Cursor:
| Benefit | Default Cursor | Custom API Keys |
|---|---|---|
| Monthly fast requests | 50 (free) / 500 (Pro) | Unlimited (pay per token) |
| Model selection | Cursor's available models | Any model from your provider |
| Cost control | Fixed subscription | Pay only for what you use |
| Rate limits | Shared with all users | Your own API rate limits |
| Privacy | Cursor processes requests | Direct to provider |
If you already have API credits from OpenAI, Anthropic, or Google, using them in Cursor means you do not need a Cursor Pro subscription for AI features.
Step 1: Open Cursor Settings
There are two ways to access the API key settings in Cursor:
Method 1: Settings UI
- Open Cursor.
- Press
Cmd + ,(macOS) orCtrl + ,(Windows/Linux) to open Settings. - Click on "Models" in the left sidebar.
Method 2: Command Palette
- Press
Cmd + Shift + P(macOS) orCtrl + Shift + P(Windows/Linux). - Type "Cursor Settings" and select "Cursor: Open Cursor Settings."
- Navigate to the "Models" section.
You will see a list of AI providers with fields for API keys.
Step 2: Add an OpenAI API Key
Get your OpenAI API key
- Go to platform.openai.com/api-keys.
- Click "Create new secret key."
- Name it something like "Cursor IDE" for easy identification.
- Copy the key (it starts with
sk-).
Add it to Cursor
- In Cursor Settings > Models, find the "OpenAI API Key" field.
- Paste your API key.
- Click "Verify" to test the connection.
Once added, you can use OpenAI models like GPT-4o, GPT-4o-mini, o4-mini, and o3 in Cursor's chat, inline edits, and agent mode.
Recommended OpenAI models for Cursor
| Model | Best For | Cost (per 1M tokens) |
|---|---|---|
| gpt-4o | General coding, complex tasks | $2.50 in / $10 out |
| gpt-4o-mini | Fast completions, simple tasks | $0.15 in / $0.60 out |
| o4-mini | Reasoning, debugging | $1.10 in / $4.40 out |
| o3 | Complex architecture decisions | $2.00 in / $8.00 out |
Step 3: Add an Anthropic API Key
Get your Anthropic API key
- Go to console.anthropic.com.
- Sign in or create an account.
- Navigate to "API Keys" and click "Create Key."
- Copy the key (it starts with
sk-ant-).
Add it to Cursor
- In Cursor Settings > Models, find the "Anthropic API Key" field.
- Paste your API key.
- Click "Verify."
You now have access to Claude models directly through your own API key.
Recommended Anthropic models for Cursor
| Model | Best For | Cost (per 1M tokens) |
|---|---|---|
| claude-sonnet-4-5-20250514 | Best all-around coding | $3.00 in / $15.00 out |
| claude-haiku-3-5-20241022 | Fast completions, light tasks | $0.80 in / $4.00 out |
| claude-opus-4-20250514 | Complex reasoning, architecture | $15.00 in / $75.00 out |
For most coding tasks, Claude Sonnet 4.5 offers the best balance of quality and cost.
Step 4: Add a Google Gemini API Key
Get your Google AI API key
- Go to aistudio.google.com/apikey.
- Click "Create API Key."
- Select or create a Google Cloud project.
- Copy the generated key.
Google offers a generous free tier for Gemini models, making this a cost-effective option.
Add it to Cursor
- In Cursor Settings > Models, find the "Google AI API Key" field.
- Paste your API key.
- Click "Verify."
Recommended Google models for Cursor
| Model | Best For | Cost (per 1M tokens) |
|---|---|---|
| gemini-2.0-flash | Fast, cost-effective coding | Free tier available |
| gemini-2.5-pro | Complex multi-file tasks | $1.25 in / $10.00 out |
| gemini-2.5-flash | Balanced speed and quality | $0.15 in / $0.60 out |
The Gemini 2.0 Flash free tier is particularly useful -- you get substantial free usage before paying anything.
Step 5: Add a Custom OpenAI-Compatible Endpoint
Cursor supports any API that follows the OpenAI API format. This lets you connect to:
- Local models via Ollama
- Together AI
- Groq
- Fireworks AI
- OpenRouter
- Any OpenAI-compatible server
Connect Ollama (local models)
First, install and run Ollama:
# Install Ollama
curl -fsSL https://ollama.ai/install.sh | sh
# Pull a coding model
ollama pull qwen2.5-coder:14b
# Ollama runs on localhost:11434 by default
Then in Cursor:
- Go to Settings > Models.
- Find "OpenAI API Base URL" or "Override OpenAI Base URL."
- Set the base URL to
http://localhost:11434/v1. - Set the API key to
ollama(any non-empty string works). - Add the model name
qwen2.5-coder:14bto your model list.
Connect OpenRouter (access 100+ models)
OpenRouter lets you access hundreds of models through a single API key.
- Go to openrouter.ai and create an account.
- Generate an API key.
- In Cursor, set the OpenAI Base URL to
https://openrouter.ai/api/v1. - Paste your OpenRouter API key in the OpenAI API Key field.
- Use model identifiers like
anthropic/claude-sonnet-4-5,google/gemini-2.5-pro, etc.
Connect Groq (fast inference)
Groq offers extremely fast inference for open-source models.
- Go to console.groq.com and create an account.
- Generate an API key.
- In Cursor, set the OpenAI Base URL to
https://api.groq.com/openai/v1. - Paste your Groq API key.
- Use models like
llama-3.3-70b-versatileormixtral-8x7b-32768.
Step 6: Configure Model Preferences
After adding your API keys, you can configure which model Cursor uses for different tasks.
Set default models
In Cursor Settings > Models, you can assign models to specific features:
- Chat: The model used for Cursor Chat (Cmd+L). Recommended: Claude Sonnet 4.5 or GPT-4o.
- Inline Edit: The model used for inline code edits (Cmd+K). Recommended: Claude Sonnet 4.5 or GPT-4o.
- Agent: The model used for agent mode. Recommended: Claude Sonnet 4.5.
- Tab Completion: The model for autocomplete suggestions. Recommended: A fast model like GPT-4o-mini or Gemini Flash.
Example configuration for cost optimization
Use cheaper models for frequent, simple tasks and premium models for complex work:
| Feature | Model | Why |
|---|---|---|
| Tab completion | gpt-4o-mini | Fast, cheap, high volume |
| Inline edits | claude-sonnet-4-5 | Good quality for targeted changes |
| Chat | claude-sonnet-4-5 | Best for discussions and planning |
| Agent mode | claude-sonnet-4-5 | Strong for multi-step tasks |
Step 7: Verify Everything Works
Test each API key by running a simple task:
- Chat test: Press
Cmd+L, select your custom model, and ask "Write a hello world function in Python." - Inline edit test: Select a block of code, press
Cmd+K, and ask "Add error handling to this function." - Agent test: Start agent mode and ask "Create a new file called test.py with a function that calculates factorial."
If any test fails, check:
- The API key is entered correctly (no extra spaces).
- Your API account has credits or an active payment method.
- The base URL is correct (especially for custom endpoints).
- The model name matches the provider's naming convention.
Troubleshooting Common Issues
| Issue | Cause | Fix |
|---|---|---|
| "Invalid API key" | Wrong key or expired | Regenerate the key from the provider |
| "Model not found" | Wrong model name | Check the provider's docs for exact model IDs |
| "Rate limit exceeded" | Too many requests | Wait and retry, or upgrade your API tier |
| "Connection refused" (Ollama) | Ollama not running | Start Ollama with ollama serve |
| Slow responses | Server location | Choose a provider with servers near you |
| "Insufficient credits" | No balance | Add funds to your API account |
Frequently Asked Questions
Do I still need Cursor Pro if I add my own API keys? No. With your own API keys, you can use AI features without a Cursor Pro subscription. However, some Cursor-specific features like advanced tab completions may still require Pro.
Which API key is the most cost-effective? Google Gemini offers the most generous free tier. For paid usage, GPT-4o-mini and Gemini Flash are the cheapest quality options.
Can I use multiple API keys at the same time? Yes. You can add keys from multiple providers and switch between models as needed. Cursor will use the appropriate key based on which model you select.
Are my API keys stored securely? Cursor stores API keys locally on your machine. They are not uploaded to Cursor's servers when you use your own keys -- requests go directly to the provider.
Does using custom API keys affect Cursor's built-in limits? Yes. When you use your own API key, those requests do not count against Cursor's free or Pro request limits. You are billed directly by the API provider.
Wrapping Up
Adding custom API keys to Cursor gives you full control over your AI coding experience. You can choose models based on task complexity, manage costs precisely, and avoid hitting Cursor's built-in limits. The setup takes less than five minutes per provider.
If you are building applications that need AI-generated media alongside your code, try Hypereal AI free -- 35 credits, no credit card required. The API integrates seamlessly into projects you build in Cursor or any other editor.
Related Articles
Start Building Today
Get 35 free credits on signup. No credit card required. Generate your first image in under 5 minutes.
