What to expect
Rate limits protect the API and keep tail latency predictable.
When you exceed a limit, you'll receive 429 Too Many Requests.
Design for 429s
Treat 429s as a normal condition. The happy path is: backoff, retry later, and avoid thundering herds.
Recommended client behavior
- Add jittered backoff
Use exponential backoff with jitter.
- Cap retries
Retries are not infinite. Surface the failure when you hit a ceiling.
- Spread load
If you send in bursts, prefer batching (one transmission with multiple recipients) or smoothing.
Example backoff (TypeScript)
ts
function sleep(ms: number) {
return new Promise((r) => setTimeout(r, ms));
}
function jitter(ms: number) {
return Math.floor(ms * (0.5 + Math.random()));
}
for (let attempt = 0; attempt < 5; attempt++) {
const res = await fetch("https://api.sendlib.com/v1/me", {
headers: { Authorization: `Bearer ${process.env.SENDLIB_API_KEY}` },
});
if (res.status !== 429) {
if (!res.ok) throw new Error(await res.text());
console.log(await res.json());
break;
}
const base = 250 * 2 ** attempt;
await sleep(jitter(Math.min(base, 5000)));
}Next
- Retry safety on create requests: Idempotency
- Troubleshooting: Troubleshooting