Skip to main content
408Retryable
Google Gemini 408 Request Timeout
The connection idled out before the request completed — typically network-level rather than model-level on the Gemini API.
Most likely causes
- 1.Slow upload of large inline payloads
- 2.Proxy/VPN adding latency past the timeout
Fix checklist
- Upload media via the Files API first, then reference it
- Retry on a better network path; keep request bodies small
Retry guidance
Retry with backoff from 1s, 3 attempts.
// Retry 408 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 !== 408) 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 408: still failing after backoff — check https://status.cloud.google.com");
}Provider status page: status.cloud.google.com