Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
AI and LLM integration

Gemini API returns 429 RESOURCE_EXHAUSTED on the free tier

Error429 RESOURCE_EXHAUSTED

Short 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.

  • Applies to Python 3.12, google-genai SDK, langchain-google-genai
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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)
  2. 2Match what you see, then jump to its fix

    1. 1429 after a burst of calls, or late in the dayA per-project limit was reachedFix
    2. 2The 429 shows up in bursts, then the next call worksRequests are retried too fastFix
    3. 3Every call fails at once, even the first one, on a project with no usageThe project is not eligible for the free tierFix

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.py

Confirmed by aistudio.google.com

Did this fix it?

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.py

Confirmed by aistudio.google.com

Did this fix it?

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.py

Confirmed by aistudio.google.com

Did this fix it?

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:

Related fixes

AI

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 fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.