Gemini API 429 and 503 Errors: What They Mean and How to Fix Them
What the Gemini API 429 and 503 errors mean, how to tell them apart, and tested Python code that retries and falls back to another model.
Mahnoor 5 min read 4-item prompt pack
The Gemini API 429 error means you sent more requests than your project's limit allows. A 503 error means Google's servers for that model are too busy right now. Neither one means your key or your code is broken. Here's how to tell them apart, and the exact Python code I use to handle both.
429 vs 503 at a glance
429 RESOURCE_EXHAUSTED: you hit a limit (requests per minute, tokens per minute or requests per day). It's usually your code sending too many requests. Fix: wait and retry, send fewer requests, or use another model.
503 UNAVAILABLE ("This model is currently experiencing high demand" or "The model is overloaded"): Google is short on capacity for that model right now. It happens even when you're under your limits. Fix: retry after a short wait, or use another model.
Why you get a 429
The free tier limits how many requests and tokens you can send per minute, and how many requests per day. Three things catch beginners:
Loops. When I built our RAG study buddy, every note chunk was one embedding request. With 101 small chunks, it hit the per-minute limit straight away. AI agents are the same: every step of the loop is another request.
A new key doesn't help. Limits are per project, not per key. Five keys in the same project share the same limit.
The daily limit resets at midnight Pacific time, which is around noon to 1 PM in Pakistan. If you used up your daily requests, waiting a minute won't fix it.
Check your exact limits and usage on the rate limit and usage pages in Google AI Studio.
Why you get a 503
A 503 has nothing to do with your quota. It means the servers running that model are full, usually at busy times. I hit this exact error while building our AI agent lesson:
503 UNAVAILABLE. {'error': {'code': 503, 'message': 'This model is currently
experiencing high demand. Spikes in demand are usually temporary. Please try
again later.', 'status': 'UNAVAILABLE'}}Running the same code a minute later worked fine.
Fix 1: let the SDK retry for you
Good news: the official Python SDK (google-genai) already retries 429 and 5xx errors on its own, up to four times, waiting longer each time (about 1 second at first, up to 60 seconds). So if you still see the error, it failed several times in a row. You can give it more attempts:
from google import genai
from google.genai import types
client = genai.Client(http_options=types.HttpOptions(
retry_options=types.HttpRetryOptions(attempts=5, initial_delay=2, max_delay=30),
))This waits a little longer between tries, which gives a busy model time to recover.
Fix 2: fall back to another model
Each model has its own limits and its own servers. If one is busy or out of quota, another one usually isn't. This is the function I use in my projects:
from google import genai
from google.genai import types, errors
client = genai.Client(http_options=types.HttpOptions(
retry_options=types.HttpRetryOptions(attempts=5, initial_delay=2, max_delay=30),
))
# If one model is still busy, try the next one. Each model has its own limits.
MODELS = ["gemini-3.5-flash-lite", "gemini-3.1-flash-lite", "gemini-3.6-flash"]
def ask(prompt):
for model in MODELS:
try:
return client.models.generate_content(model=model, contents=prompt).text
except errors.APIError as error:
if error.code in (429, 503):
print(f"{model} is busy ({error.code}), trying the next model...")
continue
raise # 400, 403, 404: retrying will not fix these
raise RuntimeError("Every model is busy. Wait a minute and run it again.")
print(ask("Say hi in five words."))Here's what it printed when I tested it with the first model forced to fail:
gemini-3.5-flash-lite is busy (503), trying the next model...
Hello, how are you today?Fix 3: send fewer requests
Wait between calls in loops. A
time.sleep(1)inside a loop that calls Gemini keeps you under the per-minute limit.Cache answers. If you ask the same thing twice, save the first answer to a file or a dictionary and reuse it.
Make fewer, bigger requests. In RAG, use bigger chunks, so you have fewer chunks to embed.
Cap agent loops. Give every agent a
max_stepslimit, so one bad decision can't burn your whole daily quota.
Errors you should not retry
Only retry 429 and 5xx errors. Retrying these never helps:
400: something in your request is wrong (bad parameters or bad input). Fix the request.
403: a key or project problem (leaked key, verification needed, free tier unavailable). See how to get a free Gemini API key for each fix.
404: the model name is wrong or the model was retired. Check the model name.
The code above already does this: it only moves on for 429 and 503, and raises everything else straight away.
Keep building
Prompt pack
Every prompt from this lesson
2 free prompts + the Node.js version of the fix and a rate-limit-safe batch script.
Here is my Python code that calls the Gemini API with google-genai:
[paste your code]
Add handling for 429 and 503 errors:
1. Configure HttpRetryOptions on the client (5 attempts, initial_delay 2, max_delay 30).
2. If a model still fails with 429 or 503, fall back to the next model in a list.
3. Don't retry 400, 403 or 404 errors. Raise them.
Keep my code style and explain every change.
This is my code that calls the Gemini API:
[paste your code]
Count how many API requests it makes per run and per minute. Find the loops or repeated calls that cause 429 errors. Then rewrite it to make fewer requests (caching, batching, sleeping between calls) without changing what it does. Show me the request count before and after.
2 more items in the full pack
Free. Sign in once and every prompt pack on Morow Global unlocks.
Sign in free to unlockAlready a member? Sign in
FAQ
What does 429 RESOURCE_EXHAUSTED mean in Gemini?
Your project sent more requests or tokens than its limit allows (per minute or per day). Wait and retry, send fewer requests, or switch to another model.
What does Gemini 503 "model is overloaded" mean?
Google's servers for that model are busy. It isn't your quota or your code. Retry after a short wait or use another model.
Will a new API key fix a Gemini 429 error?
Not if it's in the same project. Gemini limits are per project, not per key.
When does the Gemini daily limit reset?
At midnight Pacific time, which is around noon to 1 PM in Pakistan.
Does the Gemini Python SDK retry automatically?
Yes. google-genai retries 429 and 5xx errors up to four times by default, and you can change this with HttpRetryOptions.