For Gemini, first distinguish a temporary limit from depleted credit. Google's GenerateContent reference uses RESOURCE_EXHAUSTED for both HTTP 429 rate or spend pressure and HTTP 402 exhausted Prepay credit. Retrying both as the same error can waste capacity while leaving the account blocked.
Keep the API interface in the diagnostic record
Google's GenerateContent reference, labeled legacy, uses an uppercase error.status plus a numeric error.code. Its current Interactions reference instead uses string codes such as rate_limit_exceeded, quota_exceeded, too_many_requests, and payment_required. Do not assume every Gemini error has the first format.
- Per-minute or shorter request/token pressure
Meaning. The current workload exceeds an applicable throughput limit.
Action. Pace admission, inspect actual limits, and use bounded retries with backoff.
- Daily quota
Meaning. A brief retry delay does not reset the daily allowance.
Action. Check the project quota and its reset, or request an increase where available.
- Spend-based rate limit
Meaning. Google documents a rolling spend window whose applicability depends on billing history and account standing.
Action. Reduce expensive request pressure and inspect the applicable tier and rate-limit settings.
- HTTP 402 depleted Prepay credit
Meaning. The linked billing account has no usable Prepay balance.
Action. Stop automatic retries and have an authorized owner inspect credits and payment setup.
Project limits and billing-account controls have different scopes
Google documents RPM, input TPM, and RPD limits per project, not per API key. Model-specific dimensions can also apply. Changing keys inside the same project does not create a new throughput allowance. The documented daily request reset is midnight Pacific time, not midnight in the server's local time zone.
Billing history and tier affect other controls. Google's GenerateContent error reference says depleted Prepay credit stops keys linked to that billing account. Do not assume a new project sharing the account bypasses a credit failure. Separate environments for ownership and isolation when appropriate; do not present project creation as an unlimited-capacity workaround.
Use observed capacity, not a remembered free-tier number
Read the active limits in AI Studio for the actual project and model. Google states that published limits do not guarantee available capacity. Preview or experimental deployments can have different restrictions, and paid access does not eliminate quotas.
A concurrency cap and a request-start rate solve different problems. Fast calls can pass through a small pool at a high rate. Coordinate paced starts, token budgets, a bounded queue, and retries across every worker sharing the project. A synchronous exception from a queued operation must release its slot just like a rejected promise; do not leave the queue permanently stalled.
Retry only the failures that can clear
The current troubleshooting guide documents automatic retries in official SDKs. Before adding an application loop, inspect the version you deploy and configure one retry owner. Count initial attempts and retries separately, honor available server guidance, and stop or defer when the wait exceeds the operation's time budget.
A daily quota or depleted balance needs its own handling. Preserve the exact code and HTTP status rather than classifying only by the word “exhausted.” In Interactions, record streaming error events as failures even if the stream initially returned HTTP 200.
No account quota, billing state, or provider request was exercised for this guide. For a proposed capacity change, use the calculator for supported source-linked billing scenarios, then validate output quality and actual throughput separately. A quote is not a capacity guarantee or an exact future invoice.