Skip to main content
500Retryable

Google Gemini 500 Internal Error

Unexpected error on Google's side. With Gemini this is also the documented symptom of an input context that is too long for the model to handle.

Most likely causes

  1. 1.Transient internal failure
  2. 2.Excessively long input context (documented Gemini quirk: surfaces as 500 INTERNAL)
  3. 3.Ongoing incident

Fix checklist

  • Retry with backoff first
  • If reproducible with a long prompt, cut context size — this is the known long-input failure mode
  • Try a different model variant; report persistent cases via AI Studio feedback

Retry guidance

Exponential backoff from 1s, 3 attempts. If it fails deterministically with the same long prompt, shrink the input instead of retrying.

// Retry 500 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 !== 500) 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 500: still failing after backoff — check https://status.cloud.google.com");
}

Provider status page: status.cloud.google.com