API usage limits and best practices for optimal performance
Rate limits help ensure fair usage and maintain API performance for all users. Different limits apply based on your subscription plan.
Every API response includes headers that show your current rate limit status:
HTTP/1.1 200 OK
X-RateLimit-Limit: 10000
X-RateLimit-Remaining: 999
X-RateLimit-Reset: 1736180400000| Header | Description |
|---|---|
| X-RateLimit-Limit | Maximum requests allowed in the current window |
| X-RateLimit-Remaining | Number of requests remaining in the current window |
| X-RateLimit-Reset | Unix epoch time in milliseconds when the window resets |
If you exceed your rate limit, you'll receive a 429 response:
HTTP/1.1 429 Too Many Requests
Content-Type: application/json
{
"success": false,
"error": {
"code": "RATE_LIMITED",
"message": "Too many requests",
"details": {
"rate_limit": {
"limit": 200,
"remaining": 0,
"reset": 1736180400000
}
}
}
}Here's how to handle rate limits in your code:
async function makeApiRequest(url, options) {
for (let attempt = 0; attempt <= 3; attempt++) {
const response = await fetch(url, options);
const body = await response.json();
if (response.status !== 429) {
if (!response.ok) throw new Error(body.error?.message || 'Request failed');
return body;
}
if (attempt === 3) throw new Error('Rate limit retry budget exhausted');
// Reset is a Unix timestamp in milliseconds, also supplied in 429 bodies.
const reset = Number(response.headers.get('X-RateLimit-Reset')
?? body.error?.details?.rate_limit?.reset);
const delay = Number.isFinite(reset) && reset > Date.now()
? reset - Date.now()
: 1000 * 2 ** attempt;
await new Promise(resolve => setTimeout(resolve, Math.max(1000, delay)));
}
}