Gemini API returns 429 RESOURCE_EXHAUSTED on the free tier
429 RESOURCE_EXHAUSTEDShort answer
Gemini limits are applied per Google Cloud project, not per API key, so a new key in the same project does not reset anything. A 429 means a limit was hit: request rate, tokens, or the daily quota. Check your limits in AI Studio, slow down with backoff, and link billing if the project is not eligible for the free tier.
Fix it fast
1Find out which cause you have
Send one small request and print the whole error. Set MODEL to a model name taken from your AI Studio rate limit page. The error body names the limit that was hit.
from google import genai client = genai.Client() # reads GEMINI_API_KEY MODEL = "your-model-name" try: print(client.interactions.create(model=MODEL, input="ping").output_text) except Exception as exc: print(exc)2Match what you see, then jump to its fix
What does the error look like?
429 RESOURCE_EXHAUSTED
Cause 1 of 3
A per-project limit was reached
1Check
The rate limits page states that limits are per project and not per API key, and that daily request quotas reset at midnight Pacific time. Exceeding any one limit gives a 429. Experimental and preview models have stricter limits.
python -c "print('compare your requests per minute and per day with the AI Studio rate limit page')"2Fix
Reduce the call rate, send fewer tokens per call, and switch from a preview model to a stable one. Retrying later is correct when the daily quota is the cause.
python -c "print('lower the call rate, shorten prompts, and move to a stable model')"3Verify
The single request from the first step succeeds after the window has reset.
python first_step.pyConfirmed by aistudio.google.com
Cause 2 of 3
Requests are retried too fast
1Check
The troubleshooting page classes 429 as a transient error and recommends exponential backoff with random jitter and a cap on retries. It adds that the Python SDK already retries up to four times.
grep -rn "retry\|sleep" my_app/2Fix
Wrap the call in a retry with growing waits and a limit, and do not loop without a pause.
import random, time
def call_with_backoff(fn, tries=5):
for n in range(tries):
try:
return fn()
except Exception as exc:
if "429" not in str(exc) or n == tries - 1:
raise
time.sleep(2 ** n + random.random())3Verify
A batch of calls finishes without an unhandled 429.
python run_batch.pyConfirmed by aistudio.google.com
Cause 3 of 3
The project is not eligible for the free tier
1Check
The troubleshooting page says not every Google Cloud project or account is eligible for the free tier, and that eligibility is decided per project. A new key in the same project does not change it.
python -c "print('open AI Studio, select the project, read its tier')"2Fix
Link an active Cloud Billing account to the project. The page notes that this moves usage to paid-tier rates and does not unlock free-tier quota.
python -c "print('set up billing for the project in AI Studio')"3Verify
The rate limit page now shows a paid tier and the first request succeeds.
python first_step.pyConfirmed by aistudio.google.com
How do I stop it coming back?
- Count requests per minute and per day in your own code, against the limits for your model.
- Keep one project per app, since all keys in a project share the same limits.
- Use stable model names in production; preview models have stricter limits.
- Let your retry code cap its attempts so one bad hour does not grow into a loop.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- stegnor.comMy company site: 804 pages from a Python and Jinja generator, with 15 free browser tools.
- MenuloA restaurant discovery platform in Germany, kept current by a Python ingestion pipeline.
- ShopGoAn e-commerce aggregator with a Python scraping engine behind its catalog, past 10K Google Play downloads.
Related fixes
AI
The OpenAI API answers 429: out of credit, or just too fast?
"type": "insufficient_quota"
A 429 from the OpenAI API means one of two unrelated things.
5 causes, each with a fixAI
Azure OpenAI says the API deployment for this resource does not exist
The API deployment for this resource does not exist
Azure OpenAI does not take a model name in the model field.
2 causes, each with a fixAI
Azure OpenAI fails with an SSL certificate verification error
httpx.ConnectError: [SSL: CERTIFICATE_VERIFY_FAILED]
The client checks the endpoint's certificate against its CA bundle, which is certifi by default.
2 causes, each with a fixAI
LangChain says it could not import the chromadb package
ImportError: Could not import chromadb python package. Please install it with `pip install chromadb`.
The message comes from LangChain's old Chroma class, which cannot import chromadb in the Python that runs your code.
2 causes, each with a fixAI
ChatPromptTemplate is missing the variable agent_scratchpad
Expected: ['agent_scratchpad', 'input']
A tool-calling agent keeps its tool calls and tool results in a prompt slot named agent_scratchpad.
2 causes, each with a fixAI
LangChain no longer exports AgentExecutor from langchain.agents
ImportError: cannot import name 'AgentExecutor' from 'langchain.agents'
LangChain v1 moved legacy classes into a separate package called langchain-classic, and AgentExecutor lives there now.
2 causes, each with a fix