Rate Limiting
Understanding API rate limits
Rate Limiting
The Servicebay API implements rate limiting to ensure fair usage and service stability.
Rate Limits
| Limit | Value |
|---|---|
| Requests per minute | 100 |
| Per | API Key |
Each API key has its own rate limit counter.
Rate Limit Headers
Every response includes rate limit information:
| Header | Description |
|---|---|
X-RateLimit-Limit | Maximum requests per minute |
X-RateLimit-Remaining | Remaining requests in current window |
X-RateLimit-Reset | Unix timestamp when limit resets |
Example Response Headers
X-RateLimit-Limit: 100
X-RateLimit-Remaining: 95
X-RateLimit-Reset: 1705325400Handling Rate Limits
When you exceed the rate limit, you'll receive a 429 Too Many Requests response:
{
"success": false,
"error": "Rate limit exceeded. Please wait before making more requests."
}Implementing Retry Logic
async function fetchWithRetry(url, options, maxRetries = 3) {
for (let attempt = 0; attempt < maxRetries; attempt++) {
const response = await fetch(url, options);
if (response.status === 429) {
const resetTime = response.headers.get("X-RateLimit-Reset");
const waitMs = parseInt(resetTime) * 1000 - Date.now();
if (waitMs > 0 && attempt < maxRetries - 1) {
console.log(`Rate limited. Waiting ${waitMs}ms...`);
await new Promise((resolve) => setTimeout(resolve, waitMs));
continue;
}
}
return response;
}
throw new Error("Max retries exceeded");
}Best Practices
- Monitor rate limit headers - Track remaining requests to avoid hitting limits
- Implement exponential backoff - Wait longer between retries on repeated failures
- Cache responses - Reduce API calls by caching data that doesn't change frequently
- Batch operations - Where possible, combine multiple operations into fewer requests
- Use webhooks - For real-time updates, consider webhooks instead of polling
Need Higher Limits?
If you need higher rate limits for your use case, please contact support@servicebay.io.