Loading...
async function call(req) {
let res = await fetch(URL, req);
while (res.status === 429) res = await fetch(URL, req);
return res;
}async function call(req, attempt = 0) {
const res = await fetch(URL, req);
if (res.status !== 429 || attempt >= 5) return res;
const retryAfter = Number(res.headers.get('retry-after')) * 1000;
const delay = retryAfter || 2 ** attempt * 1000 + Math.random() * 500;
await new Promise((r) => setTimeout(r, delay));
return call(req, attempt + 1);
}Retries respect 'retry-after', use exponential backoff with jitter and stop after a fixed number of attempts.
RPM limits requests per minute, TPM limits tokens per minute. A few large prompts can hit the token limit while the request count stays low.
Yes, retry server errors and timeouts with backoff, like 429. Do not retry 400-level errors such as invalid requests or auth failures, except 429.
Limits usually grow with usage tier or account spend. Meanwhile, cache results, batch offline work and spread load with a queue.