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:

ModelInput / 1M tokensOutput / 1M tokensContextSWE-bench Verified
Gemini 3.1 Pro$2.00$12.001M~65%
Claude Sonnet 4.6$3.00$15.00200K~62%
GPT-5.4$2.50$15.001M~60%
GPT-5.4 Mini$0.30$1.301M~45%
DeepSeek V3.2$0.27$1.10128K~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

  1. Open Cursor Settings (Cmd+Shift+J on Mac, Ctrl+Shift+J on Windows)
  2. Navigate to Models → OpenAI API Key section
  3. Check "Override OpenAI Base URL"
  4. Set Base URL to: https://generativelanguage.googleapis.com/v1beta/openai
  5. Paste your Google AI Studio API key
  6. Click "Add Model" and type: gemini-3.1-pro
  7. 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:

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

  1. Sign up at api.kissapi.ai/register and grab your API key
  2. In Cursor Settings → Models → OpenAI API Key section:
  3. Check "Override OpenAI Base URL"
  4. Set Base URL to: https://api.kissapi.ai/v1
  5. Paste your KissAPI key
  6. 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:

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:

ModelInput tokens/moOutput tokens/moMonthly cost
Gemini 3.1 Pro5M1.5M$28.00
Claude Sonnet 4.65M1.5M$37.50
GPT-5.45M1.5M$35.00
GPT-5.4 Mini5M1.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:

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 →