Skip to content
Workspace
Contact
Status
Owner
Tags

Every API key has a request budget per minute. When you exceed it the API returns 429 Too Many Requests with a Retry-After header.

PlanRequests per minuteBurst
Starter6020
Team30060
EnterpriseCustomCustom
with-retry.tsts
1export async function withRetry<T>(fn: () => Promise<Response>, attempts = 4): Promise<Response> {
2 for (let i = 0; i < attempts; i++) {
3 const res = await fn()
4 if (res.status !== 429) return res
5 const wait = Number(res.headers.get("Retry-After") ?? 2 ** i)
6 await new Promise((r) => setTimeout(r, wait * 1000))
7 }
8 throw new Error("Rate limit: retries exhausted")
9}

Batch endpoints count as one request regardless of how many records they carry.


Pages inside

Comments

V