High severity HTTP 404 beginner · Fix: 2-5 min

ValueError / InvalidArgument

google.generativeai.types.generation_types.ModelNotFoundError OR ValueError: model not found

What this error means
The GenerativeModel was initialized with an invalid or deprecated model name that doesn't exist in Google's API or is not accessible to your API key.

Stack trace

traceback
google.api_core.exceptions.NotFound: 404 Not Found
Error code: 404
Error message: models/gemini-pro not found or is not available for use.

Or:

ValueError: model 'gemini-pro' is not a valid model identifier. Valid models: ['gemini-1.5-pro', 'gemini-2.0-flash', 'gemini-1.5-flash']
QUICK FIX
Replace your model name with 'gemini-2.0-flash' (current standard), verify it with genai.list_models(), and confirm your API key has billing enabled.

Why it happens

The google-generativeai SDK validates model names against Google's current API catalog when you call GenerativeModel(). Older model names like 'gemini-pro', 'gemini-pro-vision', or typos like 'gemini-2.0-pro' (which doesn't exist) are rejected. Additionally, if your API key doesn't have access to a particular model tier (e.g., Gemini 2.0 Flash requires paid API access), the model won't be found even if the name is valid.

Detection

Before calling GenerativeModel(model_name), validate the model name against the list returned by genai.list_models(). Add logging that prints which model you're requesting and which models are available in your API tier. Monitor API responses for 404 errors on model initialization.

Causes & fixes

1

Using deprecated model names: 'gemini-pro', 'gemini-pro-vision', or 'gemini-1.5-pro-latest'

✓ Fix

Replace with current supported models: 'gemini-2.0-flash' (latest), 'gemini-1.5-pro', or 'gemini-1.5-flash'. Check available models with: genai.list_models() and look for models with 'gemini-' prefix.

2

Typo in model name: 'gemini-2.0-pro' (doesn't exist), 'gemini-1.5-pro-exp', or similar

✓ Fix

Verify the exact model name using genai.list_models(). The correct current models are: 'gemini-2.0-flash', 'gemini-1.5-pro', 'gemini-1.5-flash'. Check spelling character-by-character, including hyphens.

3

API key lacks access to the requested model tier (e.g., Gemini 2.0 Flash on free tier)

✓ Fix

Upgrade your Google Cloud project to a paid billing tier if requesting premium models. Free tier access is limited to 'gemini-1.5-flash' only. For Gemini 2.0 Flash, enable billing and verify the API key has the 'AI Platform' or 'Generative AI' permission.

4

Model name passed as None, empty string, or a variable that's undefined at runtime

✓ Fix

Ensure the model name is a non-empty string set before GenerativeModel() is called. Use os.environ['GEMINI_MODEL'] with a default fallback: model_name = os.environ.get('GEMINI_MODEL', 'gemini-2.0-flash')

Code: broken vs fixed

Broken - triggers the error
python
import google.generativeai as genai
import os

genai.configure(api_key=os.environ['GOOGLE_API_KEY'])

# ❌ BROKEN: Using deprecated model name
model = genai.GenerativeModel('gemini-pro')
response = model.generate_content('Hello, world!')
print(response.text)
Fixed - works correctly
python
import google.generativeai as genai
import os

genai.configure(api_key=os.environ['GOOGLE_API_KEY'])

# ✅ FIXED: Use current valid model name
model = genai.GenerativeModel('gemini-2.0-flash')
response = model.generate_content('Hello, world!')
print(response.text)

# OPTIONAL: Verify model exists first
available_models = [m.name for m in genai.list_models() if 'gemini' in m.name]
print(f'Available models: {available_models}')
Changed model name from deprecated 'gemini-pro' to 'gemini-2.0-flash', the current recommended model with full API support and billing access.

Workaround

If you must use a specific older model and can't upgrade, wrap GenerativeModel() in a try/except that catches the 404 error, then fall back to 'gemini-1.5-flash' as a default: try: model = genai.GenerativeModel(requested_model) except (ValueError, google.api_core.exceptions.NotFound): model = genai.GenerativeModel('gemini-1.5-flash') and log the fallback.

Prevention

Store the model name in an environment variable or config file, validate it against genai.list_models() at startup, and add integration tests that attempt to initialize the model before your app starts serving traffic. Use a config constant instead of hardcoded strings: GEMINI_MODEL = os.environ.get('GEMINI_MODEL', 'gemini-2.0-flash') and validate it once at boot time.

Python 3.8+ · google-generativeai >=0.3.0 · tested on 0.7.0
Verified 2026-04 · gemini-2.0-flash, gemini-1.5-pro, gemini-1.5-flash
Verify ↗

Community Notes

No notes yetBe the first to share a version-specific fix or tip.