Rate Limiting

Understanding API rate limits

Rate Limiting

The Servicebay API implements rate limiting to ensure fair usage and service stability.

Rate Limits

LimitValue
Requests per minute100
PerAPI Key

Each API key has its own rate limit counter.

Rate Limit Headers

Every response includes rate limit information:

HeaderDescription
X-RateLimit-LimitMaximum requests per minute
X-RateLimit-RemainingRemaining requests in current window
X-RateLimit-ResetUnix timestamp when limit resets

Example Response Headers

X-RateLimit-Limit: 100
X-RateLimit-Remaining: 95
X-RateLimit-Reset: 1705325400

Handling 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

  1. Monitor rate limit headers - Track remaining requests to avoid hitting limits
  2. Implement exponential backoff - Wait longer between retries on repeated failures
  3. Cache responses - Reduce API calls by caching data that doesn't change frequently
  4. Batch operations - Where possible, combine multiple operations into fewer requests
  5. 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.

On this page