Rate Limits
Understanding API rate limits and best practices
The Fanbeam API uses rate limiting to ensure fair usage and maintain service quality.
Rate Limit Tiers
Standard Tier
- Limit: 100 requests per minute per API key
- Burst: Up to 200 requests in a short burst
- Window: Rolling 60-second window
Enterprise Tier
- Limit: 1000 requests per minute per API key
- Burst: Up to 2000 requests in a short burst
- Window: Rolling 60-second window
Rate Limit Headers
All API responses include rate limit headers:
X-RateLimit-Limit: 100
X-RateLimit-Remaining: 95
X-RateLimit-Reset: 1640995200X-RateLimit-Limit- Maximum requests allowed per windowX-RateLimit-Remaining- Remaining requests in current windowX-RateLimit-Reset- Unix timestamp when the rate limit resets
Rate Limit Exceeded
When you exceed the rate limit, you'll receive a 429 Too Many Requests response:
{
"error": "RATE_LIMIT_EXCEEDED",
"message": "Rate limit exceeded. Please try again later.",
"retryAfter": 60
}The retryAfter field indicates how many seconds to wait before retrying.
Best Practices
Implement Exponential Backoff
async function makeRequestWithRetry(url: string, options: RequestInit) {
let retries = 0;
const maxRetries = 3;
while (retries < maxRetries) {
const response = await fetch(url, options);
if (response.status === 429) {
const retryAfter = parseInt(response.headers.get('Retry-After') || '60');
await new Promise(resolve => setTimeout(resolve, retryAfter * 1000));
retries++;
continue;
}
return response;
}
throw new Error('Max retries exceeded');
}Monitor Rate Limit Headers
const response = await fetch('https://fanbeam.app/api/posts', {
headers: { 'X-API-Key': 'your-api-key' },
});
const remaining = parseInt(response.headers.get('X-RateLimit-Remaining') || '0');
if (remaining < 10) {
console.warn('Rate limit approaching. Consider throttling requests.');
}Batch Requests When Possible
Instead of making multiple individual requests, use bulk endpoints:
// ❌ Don't do this
for (const postId of postIds) {
await client.posts.remove({ params: { id: postId } });
}
// ✅ Do this instead
await client.posts.bulkDelete({ body: { ids: postIds } });