How to Use Gemini 3.1 Pro API with Cursor IDE (2026)
Gemini 3.1 Pro is quietly becoming the default choice for developers who care about their API bill. At $2 per million input tokens and $12 per million output tokens, it undercuts Claude Sonnet 4.6 and GPT-5.4 while matching or beating them on most coding benchmarks. It also ships with a 1 million token context window — five times what Claude offers.
The catch? Cursor doesn't list Gemini 3.1 Pro in its built-in model picker. You need to configure it through a custom endpoint. This guide walks you through the entire setup, from API key to first autocomplete, in about three minutes.
Why Gemini 3.1 Pro for Cursor?
Let's look at the numbers before we get into setup. Here's how Gemini 3.1 Pro stacks up against the other models you'd typically use in Cursor:
| Model | Input / 1M tokens | Output / 1M tokens | Context | SWE-bench Verified |
|---|---|---|---|---|
| Gemini 3.1 Pro | $2.00 | $12.00 | 1M | ~65% |
| Claude Sonnet 4.6 | $3.00 | $15.00 | 200K | ~62% |
| GPT-5.4 | $2.50 | $15.00 | 1M | ~60% |
| GPT-5.4 Mini | $0.30 | $1.30 | 1M | ~45% |
| DeepSeek V3.2 | $0.27 | $1.10 | 128K | ~50% |
Gemini 3.1 Pro hits a sweet spot that didn't exist six months ago. It's cheaper than Claude Sonnet on both input and output, has 5x the context window, and scores higher on SWE-bench. The 1M context window is particularly useful in Cursor — you can feed entire codebases into a single prompt without worrying about truncation.
There's also the multimodal angle. Gemini 3.1 Pro handles images natively, so you can paste screenshots of UI bugs or architecture diagrams directly into Cursor's chat and get useful responses. Claude and GPT can do this too, but Gemini's image understanding is arguably the strongest of the three.
Option 1: Google AI Studio API Key (Direct)
Google exposes Gemini through an OpenAI-compatible endpoint, which means Cursor can talk to it natively. Here's the setup:
Step 1: Get your API key
Go to aistudio.google.com/apikey and create a new key. It's free to generate, and Google gives you a generous free tier for experimentation.
Step 2: Configure Cursor
- Open Cursor Settings (Cmd+Shift+J on Mac, Ctrl+Shift+J on Windows)
- Navigate to Models → OpenAI API Key section
- Check "Override OpenAI Base URL"
- Set Base URL to:
https://generativelanguage.googleapis.com/v1beta/openai - Paste your Google AI Studio API key
- Click "Add Model" and type:
gemini-3.1-pro - Click Verify — you should see a green checkmark
That's it. Select gemini-3.1-pro from the model dropdown in Cursor's chat or Cmd+K panel, and you're running Gemini.
Limitations of the direct approach
Google's direct API works, but there are a few friction points:
- Rate limits on the free tier are tight (15 RPM for Gemini 3.1 Pro)
- Billing setup requires a Google Cloud project for production use
- No fallback — if Google's API has issues, your Cursor stops working
- You're locked into Gemini only. Switching to Claude or GPT means reconfiguring everything
Option 2: OpenAI-Compatible API Gateway (Recommended)
A better approach for most developers: use an API gateway that gives you Gemini, Claude, and GPT through a single endpoint. You configure Cursor once and switch models by changing a string.
Setup with KissAPI
- Sign up at api.kissapi.ai/register and grab your API key
- In Cursor Settings → Models → OpenAI API Key section:
- Check "Override OpenAI Base URL"
- Set Base URL to:
https://api.kissapi.ai/v1 - Paste your KissAPI key
- Add model:
gemini-3.1-pro
The advantage here is flexibility. Tomorrow you might want to try Claude Opus 4.6 for a complex refactor — just add claude-opus-4-6 as another model in Cursor and switch. No new API keys, no new billing accounts, no reconfiguration.
Testing Your Setup
Once configured, open Cursor's chat panel (Cmd+L) and try a quick test:
// Ask Gemini to write a function
"Write a TypeScript function that debounces
async functions with proper cancellation support"
You should see a response within 2-3 seconds. If you get an error, double-check:
- The base URL doesn't have a trailing slash
- The model name is exactly
gemini-3.1-pro(notgemini-proorgemini-3.1) - Your API key is valid (test it with curl first if unsure)
Quick curl test to verify your key works:
curl https://api.kissapi.ai/v1/chat/completions \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-3.1-pro",
"messages": [{"role": "user", "content": "Say hello"}],
"max_tokens": 50
}'
Optimizing Gemini 3.1 Pro in Cursor
Gemini behaves a bit differently from Claude and GPT in Cursor. Here are some tips I've picked up from daily use:
Use the context window aggressively
With 1M tokens of context, you can include way more reference code than with Claude's 200K limit. When working on a large feature, use @codebase liberally. Gemini handles the extra context without degrading response quality — something that wasn't true of earlier Gemini versions.
Be specific with instructions
Gemini 3.1 Pro follows instructions well, but it tends to be more verbose than Claude Sonnet. If you want concise code, say so explicitly. Adding "be concise, no explanations" to your system prompt in Cursor's rules file (.cursorrules) helps.
Leverage multimodal input
Paste screenshots directly into Cursor's chat. Gemini excels at understanding UI layouts, error screenshots, and diagrams. This is genuinely useful for frontend work — screenshot a design, paste it in, and ask Gemini to implement it.
Watch for the "helpful assistant" tendency
Gemini sometimes adds unnecessary comments and explanations in generated code. A .cursorrules file with something like this helps:
# .cursorrules
- Write clean, production-ready code
- No unnecessary comments
- Prefer explicit types over inference
- Use modern syntax (ES2024+, Python 3.12+)
- When editing existing code, match the style
Cost Comparison: A Real Month of Cursor Usage
Here's what a typical month looks like for a developer using Cursor 4-6 hours per day. These numbers are based on actual token usage, not theoretical estimates:
| Model | Input tokens/mo | Output tokens/mo | Monthly cost |
|---|---|---|---|
| Gemini 3.1 Pro | 5M | 1.5M | $28.00 |
| Claude Sonnet 4.6 | 5M | 1.5M | $37.50 |
| GPT-5.4 | 5M | 1.5M | $35.00 |
| GPT-5.4 Mini | 5M | 1.5M | $3.45 |
Gemini 3.1 Pro saves you roughly $10/month compared to Claude Sonnet, and that gap widens if you use more tokens. For teams of 5-10 developers, that's $50-100/month — not life-changing, but not nothing either.
The real savings come from the context window. With Claude, you sometimes need to split large codebases across multiple requests. With Gemini's 1M context, one request often does the job. Fewer requests = fewer output tokens = lower cost.
When NOT to Use Gemini 3.1 Pro
Gemini isn't the best choice for everything. Here's when you should switch:
- Complex multi-file refactoring: Claude Opus 4.6 is still the king here. It tracks dependencies across files better than any other model.
- Agentic coding tasks: If you're using Cursor's agent mode for multi-step tasks, Claude Sonnet tends to follow tool-use patterns more reliably.
- Quick throwaway scripts: GPT-5.4 Mini at $0.30/$1.30 is 7x cheaper than Gemini Pro. For simple scripts and one-off tasks, don't overpay.
The ideal setup? Keep multiple models configured in Cursor and switch based on the task. Gemini 3.1 Pro for daily coding and large-context work. Claude Opus for hard problems. GPT-5.4 Mini for quick tasks. This "model routing" approach can cut your total API spend by 40-60% compared to using one model for everything.
Using Gemini 3.1 Pro Outside Cursor
Once you have your API key set up, you can use the same endpoint in other tools:
Python (OpenAI SDK)
from openai import OpenAI
client = OpenAI(
api_key="your-api-key",
base_url="https://api.kissapi.ai/v1"
)
response = client.chat.completions.create(
model="gemini-3.1-pro",
messages=[
{"role": "user", "content": "Refactor this function to use async/await"}
],
max_tokens=2000
)
print(response.choices[0].message.content)
Node.js
import OpenAI from 'openai';
const client = new OpenAI({
apiKey: 'your-api-key',
baseURL: 'https://api.kissapi.ai/v1'
});
const response = await client.chat.completions.create({
model: 'gemini-3.1-pro',
messages: [{ role: 'user', content: 'Explain this error trace' }]
});
console.log(response.choices[0].message.content);
curl
curl https://api.kissapi.ai/v1/chat/completions \
-H "Authorization: Bearer your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-3.1-pro",
"messages": [
{"role": "system", "content": "You are a senior developer."},
{"role": "user", "content": "Review this PR diff for bugs"}
]
}'
Try Gemini 3.1 Pro in Cursor Today
Sign up for KissAPI and get free credits. Access Gemini 3.1 Pro, Claude, GPT-5.4, and 200+ models through one API key.
Start Free →