Skip to main content
408Retryable
Anthropic 408 Request Timeout
The request took too long to complete and was cut off — usually a long non-streaming generation hitting a gateway timeout.
Most likely causes
- 1.Non-streaming call with large max_tokens exceeding the ~10 min HTTP window
- 2.Slow tool-use turn assembled into one giant request
- 3.Client-side timeout shorter than realistic generation time
Fix checklist
- Stream responses (stream: true) — required for long generations
- Raise client timeout for batch-style work, or use the Batch API
- Split very long generations into continuation calls
Retry guidance
Retry once after switching to streaming; identical non-streaming retries will time out again.
// 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://api.anthropic.com/v1/messages", {
method: "POST",
headers: {
"content-type": "application/json",
"x-api-key": process.env.ANTHROPIC_API_KEY!,
"anthropic-version": "2023-06-01",
},
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("Anthropic 408: still failing after backoff — check https://status.anthropic.com");
}Provider status page: status.anthropic.com