Skip to main content
429Retryable

Google Gemini 429 Resource Exhausted

Quota exceeded — RPM, TPM, or daily request caps for your tier. Free-tier limits are far lower than paid.

Most likely causes

  1. 1.Free-tier RPM/daily limits (very low) hit during development
  2. 2.Paid-tier TPM exhausted by long contexts
  3. 3.Many instances sharing a project quota

Fix checklist

  • Check which quota tripped in the error details (it names the metric)
  • Enable billing / raise tier for production workloads
  • Request quota increases in the Cloud console for sustained needs
  • Backoff + client-side rate limiting per project, not per process

Retry guidance

Exponential backoff with jitter from 1s. For daily-quota exhaustion, retrying before the quota window resets is pointless — fail fast and alert.

// Retry 429 with exponential backoff + full jitter.
async function callWithBackoff(payload: unknown, maxAttempts = 5) {
  for (let attempt = 0; attempt < maxAttempts; attempt++) {
    const res = await fetch("https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-pro:generateContent", {
      method: "POST",
      headers: {
        "content-type": "application/json",
        "x-goog-api-key": process.env.GEMINI_API_KEY!,
      },
      body: JSON.stringify(payload),
    });
    if (res.status !== 429) return res;
    // Honor Retry-After when present; otherwise exponential backoff, capped at 32s.
    const retryAfter = Number(res.headers.get("retry-after"));
    const base = Number.isFinite(retryAfter) && retryAfter > 0
      ? retryAfter * 1000
      : Math.min(1000 * 2 ** attempt, 32_000);
    await new Promise((r) => setTimeout(r, base * (0.5 + Math.random() * 0.5)));
  }
  throw new Error("Google Gemini 429: still failing after backoff — check https://status.cloud.google.com");
}

Provider status page: status.cloud.google.com