"Prompt Caching & Cost Control for Gemini Apps"

"A 429 from the Gemini API is not a signal to retry — it is a signal you are out of quota, and every retry digs deeper. Here is the quota-aware Flutter pattern: never retry 429, fall back across models, rate-limit the client, and cache aggressively."

The standard advice for a 429 is exponential backoff — wait and retry. For the Gemini API free tier, that advice is actively harmful: a 429 means you are out of quota, and every retry consumes more of the quota you don't have. If your Flutter app hits the gemini api free tier limits and throws quota exceeded 429 errors, the fix is not to retry harder. It is to stop retrying 429s entirely, fall back across models, and make sure you never pay for the same prompt twice. The 429, exactly as your app sees it Through Firebase AI Logic it surfaces as an exception carrying the quota error: FirebaseAIException: 429 RESOURCE_EXHAUSTED. Quota exceeded for the current project. Please check AI Studio for your rate limits and usage: https://aistudio.google.com Through raw REST it is the HTTP status with a RESOURCE_EXHAUSTED body. Either way, the app's instinct — and most retry libraries' default — is to retry. That instinct is the bug. Why 429 happens — and why retries make it worse A 429 fires when you exceed any of four dimensions: requests per minute (RPM), tokens per minute (TPM), requests per day (RPD), or spend-based limits on paid tiers. On the free tier, the daily cap is the usual killer — a chatty feature can burn a day's quota before lunch. Two uncomfortable truths: Retrying a 429 cannot succeed soon. The quota window (especially RPD) doesn't clear because you asked again. Each retry is a wasted request that, on tight windows, pushes your next legitimate request further out. Nobody can tell you the exact numbers. Google no longer publishes per-model free-tier RPM/TPM/RPD tables — AI Studio's rate-limit page (login required) is the only authoritative source for *your* project, and secondary sources conflict wildly. Any article quoting hard…

Explore