GEMINI LABJP
FLASH3.5 — Gemini 3.5 Flash reaches general availability for sustained frontier performance on agentic and coding tasks (Jun)MANAGED-AGENTS — Managed Agents launch in public preview on the Gemini API, running in secure Google-hosted Linux sandboxes (Jun)ANTIGRAVITY-AGENT — A general-purpose Antigravity Agent ships in public preview, autonomously planning, coding, managing files, and browsing the web (Jun)SCHEMA — The Interactions API schema moves from outputs to steps; the legacy schema is removed on Jun 8 (Jun)DEPRECATION — gemini-3.1-flash-image-preview and gemini-3-pro-image-preview shut down on Jun 25 (Jun)FILESEARCH — File Search adds multimodal support via gemini-embedding-2, plus event-driven webhooks (Jun)FLASH3.5 — Gemini 3.5 Flash reaches general availability for sustained frontier performance on agentic and coding tasks (Jun)MANAGED-AGENTS — Managed Agents launch in public preview on the Gemini API, running in secure Google-hosted Linux sandboxes (Jun)ANTIGRAVITY-AGENT — A general-purpose Antigravity Agent ships in public preview, autonomously planning, coding, managing files, and browsing the web (Jun)SCHEMA — The Interactions API schema moves from outputs to steps; the legacy schema is removed on Jun 8 (Jun)DEPRECATION — gemini-3.1-flash-image-preview and gemini-3-pro-image-preview shut down on Jun 25 (Jun)FILESEARCH — File Search adds multimodal support via gemini-embedding-2, plus event-driven webhooks (Jun)
Articles/API / SDK
API / SDK/2026-04-14Beginner

Fixing Gemini API Errors: 5 Common Problems Developers Hit and How to Solve Them

Gemini API throwing 400 INVALID_ARGUMENT, 429 RESOURCE_EXHAUSTED, or model not found errors? This guide covers the 5 most common issues with exact error messages and step-by-step fixes, including migrating to gemini-2.5-pro-latest.

Gemini API203troubleshooting119error fix3gemini-2.5-pro20developers

Whether you're just getting started with the Gemini API or upgrading to a newer model, the first roadblock is usually the same: code that looks right, documentation that seems to match — and an error that doesn't explain itself clearly.

Here are the five most common Gemini API errors, what's actually causing them, and how to fix each one.

Error 1: models/gemini-pro is not found or 404 NOT_FOUND

What's happening

The model names gemini-pro and gemini-1.0-pro have been retired. Requests using these names return a 404 error.

[GoogleGenerativeAI Error]: Error fetching from https://generativelanguage.googleapis.com/...
Status: 404 Not Found
{"error":{"code":404,"message":"models/gemini-pro is not found for API version v1beta"}}

Why it happens

Older tutorials and GitHub samples often reference deprecated model names. Even when official documentation is updated, the code people are following isn't.

How to fix it

Switch to a currently supported model name. As of April 2026:

# ❌ Old (broken)
model = genai.GenerativeModel('gemini-pro')
model = genai.GenerativeModel('gemini-1.0-pro')
 
# ✅ Current
model = genai.GenerativeModel('gemini-2.5-pro-latest')      # Latest Gemini 2.5 Pro
model = genai.GenerativeModel('gemini-2.0-flash')            # Fast and cost-efficient
model = genai.GenerativeModel('gemini-2.5-flash-preview-04-17')  # 2.5 Flash (preview)

To see what models are available to your project:

import google.generativeai as genai
genai.configure(api_key="YOUR_GEMINI_API_KEY")
for m in genai.list_models():
    if 'generateContent' in m.supported_generation_methods:
        print(m.name)

Error 2: 400 INVALID_ARGUMENT — Request Format Issues

What's happening

The request structure doesn't match the API spec. This is especially common when migrating from Gemini 1.x to 2.x — the API format for certain parameters changed.

Pattern A: Old system_instruction format

# ❌ Gemini 1.x style (may fail in 2.x)
response = model.generate_content(
    [{"role": "system", "parts": [{"text": "You are a helpful assistant"}]},
     {"role": "user",   "parts": [{"text": "Hello"}]}]
)
 
# ✅ Gemini 2.x recommended
model = genai.GenerativeModel(
    model_name='gemini-2.5-pro-latest',
    system_instruction="You are a helpful assistant"
)
response = model.generate_content("Hello")

Pattern B: Unsupported parameter in generation_config

# ❌ topK not supported on all models
config = genai.GenerationConfig(topK=40)
 
# ✅ Stick to core parameters
config = genai.GenerationConfig(
    temperature=0.7,
    max_output_tokens=1024
)

How to fix it

Check the details field in the error response — it usually specifies which field is causing the problem. Then verify against the official generate content reference.

Error 3: 429 RESOURCE_EXHAUSTED — Rate Limit Hit

What's happening

You've hit the API rate limit for your project tier.

google.api_core.exceptions.ResourceExhausted: 429 RESOURCE_EXHAUSTED
Quota exceeded for quota metric 'generate_content_requests' 
and limit 'generate_content_requests_per_day_per_project'

The three rate limits and how to handle each

| Limit Type | Free Tier (reference) | Fix | |---|---|---| | Requests per minute (RPM) | 15 RPM | Add time.sleep() between requests | | Tokens per minute (TPM) | 1,000,000 TPM | Shorten prompts | | Requests per day (RPD) | 1,500 RPD | Wait until tomorrow or upgrade |

For any script that makes multiple API calls, implement retry logic:

import time
import google.api_core.exceptions
 
def generate_with_retry(model, prompt, max_retries=3):
    for attempt in range(max_retries):
        try:
            return model.generate_content(prompt)
        except google.api_core.exceptions.ResourceExhausted:
            wait_time = 60 * (attempt + 1)  # 60s, 120s, 180s
            print(f"Rate limited. Waiting {wait_time}s...")
            time.sleep(wait_time)
    raise Exception("Max retries reached")

If you're consistently hitting the daily 1,500-request limit, upgrading to a paid plan through Google Cloud is the most sustainable fix.

Error 4: SAFETY Block — Empty Response

What's happening

Gemini's safety filters have blocked the response. The finish_reason is SAFETY, and no text is returned — which usually surfaces as an AttributeError or ValueError when accessing response.text.

How to fix it

Check finish_reason before accessing the text:

response = model.generate_content("...")
candidate = response.candidates[0]
print(f"Finish reason: {candidate.finish_reason}")
print(f"Safety ratings: {candidate.safety_ratings}")
 
if candidate.finish_reason.name == 'SAFETY':
    print("Response blocked by safety filter")
    # Revise prompt or adjust safety_settings

You can adjust safety_settings to relax filtering thresholds for specific categories. Note that this adjustment requires the Google Cloud API endpoint (not Google AI Studio) and should be used carefully.

Error 5: APIKeyInvalidError or Authentication Failure

What's happening

The API key is missing, expired, or belongs to a different project.

google.api_core.exceptions.PermissionDenied: 403 API_KEY_INVALID

Verification steps

  1. Go to Google AI Studio → "Get API key" to confirm the key is still valid
  2. Ensure the key is set correctly as an environment variable:
import os
api_key = os.environ.get("GEMINI_API_KEY")
if not api_key:
    raise ValueError("GEMINI_API_KEY environment variable is not set")
genai.configure(api_key=api_key)
  1. Never hardcode API keys in source files — if committed to Git, Google's secret scanning will automatically invalidate it. Always use environment variables or a .env file.

  2. If using Google Cloud authentication, verify your GOOGLE_APPLICATION_CREDENTIALS path and that the service account has the generativelanguage.googleapis.com API enabled.

Migration Checklist: Moving to gemini-2.5-pro-latest

Key things to verify when upgrading:

  • Update system_instruction to the new constructor-level format
  • Optionally add thinking_config to control the reasoning/thinking process
  • The context window is significantly larger — update any hardcoded length checks
  • Higher output token counts mean you'll hit TPM limits faster with large batches

When a Gemini API error appears, the first thing to check is the HTTP status code (400/403/404/429). That narrows it down to one of these five categories, and the fix is usually straightforward once you know which one you're dealing with.

Share

Thank You for Reading

Gemini Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • Copy-paste ready implementation code
  • New advanced guides published daily
  • $5/mo or $10 for lifetime access
View Membership →

If you found this article helpful, a small tip ($1.50) would mean a lot to us. Your support helps keep this site ad-free and covers server and hosting costs.

Related Articles

API / SDK2026-06-03
Gemini Live API Audio Sounds Sped Up — Fixing the Sample Rate Mismatch
When Gemini Live API responses sound high-pitched and sped up, or come back full of noise, the cause is almost always that the 24kHz output is being played at a different sample rate. Here are the concrete fixes for both the browser and iOS.
API / SDK2026-05-26
Why Gemini API Streaming Drops on iOS After Backgrounding — and How to Fix It
When your iOS app receives a streaming response from Gemini API and the user briefly switches to another app, the stream often goes silent forever. Here's how URLSession actually treats long-lived HTTP, and the smallest change that brings reliability back.
API / SDK2026-05-22
Why Gemini API Returns MALFORMED_FUNCTION_CALL — Causes and Fixes
Hit by finishReason: MALFORMED_FUNCTION_CALL in production? Three root causes, how to diagnose each, and the workarounds that actually worked in our indie iOS/Android pipeline.
📚RECOMMENDED BOOKS
Build a Large Language Model (From Scratch)
Sebastian Raschka
LLM Dev
Prompt Engineering for LLMs
Berryman & Ziegler
Prompting
AI Engineering
Chip Huyen
AI Eng
* Contains affiliate links
See all →