Retry logic uses exponential backoff
Why it matters
AI APIs are susceptible to transient failures: 429 Too Many Requests during traffic spikes, 503 Service Unavailable during provider incidents, and occasional 500 errors. Without retry logic, every transient error immediately surfaces to the user as a failed request — even though the same call would succeed 2 seconds later. Without exponential backoff, retries that fire immediately in a tight loop amplify rate limit pressure at exactly the wrong time, causing cascading failures across all requests rather than absorbing the spike gracefully. ISO 25010 reliability requires predictable behavior under transient failure conditions.
Severity rationale
Medium because missing or improperly implemented retry logic converts transient API errors into user-visible failures and can worsen rate limit pressure under load.
Remediation
Use the Vercel AI SDK's built-in maxRetries parameter, which applies exponential backoff automatically. For custom SDK wrappers, implement backoff explicitly with a bounded retry count.
// Vercel AI SDK — exponential backoff built in
const result = await streamText({
model: openai("gpt-4o"),
messages,
maxTokens: 1000,
maxRetries: 3, // SDK waits 1s, 2s, 4s between attempts
});
// Custom wrapper for non-SDK paths
async function withBackoff<T>(fn: () => Promise<T>, maxAttempts = 3, baseDelay = 1000): Promise<T> {
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
try { return await fn(); }
catch (err) {
if (attempt === maxAttempts) throw err;
await new Promise(r => setTimeout(r, baseDelay * Math.pow(2, attempt - 1)));
}
}
throw new Error("Unreachable");
}
Verify by inspecting each streamText or generateText call for maxRetries, or by simulating a 429 response and observing delayed retry attempts in server logs.
DetectionPro
The detection method for this pattern is part of AuditBuffet Pro.
The full method (what to look for, pass and fail conditions, and how results get reported) ships inside the AI Token Optimization Audit. The pattern definition, severity rationale, and remediation remain openly licensed under CC-BY-4.0.
External references
- iso-25010:2011 · reliability.fault-tolerance — Fault Tolerance — exponential backoff absorbs transient API failures
Taxons
History
- 2026-04-18·v1.0.0·Initial import from ai-token-optimization·automated