Overview

Klyra implements rate limiting to ensure fair usage and system stability. Rate limits vary by subscription plan and are applied at both the request level and the account level.

Rate Limit Types

Klyra enforces several types of rate limits:

  1. Requests per minute (RPM): Limits the number of API requests you can make per minute
  2. Requests per day (RPD): Limits the total number of API requests per day
  3. Concurrent requests: Limits the number of simultaneous requests your account can make
  4. Payload size: Limits the size of content that can be moderated in a single request

Rate Limit Headers

All API responses include headers that provide information about your current rate limit status:

HeaderDescription
X-RateLimit-LimitThe maximum number of requests per minute
X-RateLimit-RemainingThe number of requests remaining in the current minute
X-RateLimit-ResetThe time in seconds until the rate limit resets
X-Daily-Limit-RemainingThe number of requests remaining for the current day

Rate Limits by Plan

Handling Rate Limits

When you exceed a rate limit, the API will return a 429 Too Many Requests status code with a JSON response body containing information about the limit and when it will reset:

{
  "error": {
    "code": "rate_limit_exceeded",
    "message": "You have exceeded the rate limit of 60 requests per minute",
    "type": "rate_limit_error",
    "param": null,
    "reset_at": 1623180660
  }
}

Best Practices for Rate Limit Management

  1. Implement exponential backoff: When receiving a 429 response, use exponential backoff to retry the request:
async function moderateWithBackoff(content, maxRetries = 5) {
  let retries = 0;
  
  while (retries < maxRetries) {
    try {
      return await klyra.moderateText({ content });
    } catch (error) {
      if (error.error?.code === 'rate_limit_exceeded' && retries < maxRetries) {
        const resetAt = error.error.reset_at || 0;
        const currentTime = Math.floor(Date.now() / 1000);
        const waitTime = resetAt > currentTime 
          ? (resetAt - currentTime) * 1000 
          : (2 ** retries) * 1000;
        
        console.log(`Rate limited. Retrying in ${waitTime/1000} seconds...`);
        await new Promise(resolve => setTimeout(resolve, waitTime));
        retries++;
      } else {
        throw error;
      }
    }
  }
  
  throw new Error('Max retries exceeded');
}
  1. Use a request queue: Implement a queue system to throttle your requests and stay within rate limits.

  2. Monitor your usage: Check the rate limit headers to track your usage and adjust your request patterns accordingly.

  3. Batch requests when possible: Instead of sending many small requests, batch them together when your use case allows.

Increasing Your Rate Limits

If you need higher rate limits than what your current plan provides:

  1. Upgrade your plan: Visit the pricing page to find a plan that meets your needs.

  2. Enterprise customization: For enterprise customers, we offer customized rate limits tailored to your specific requirements. Contact sales to discuss your needs.

  3. Temporary increases: If you need a temporary rate limit increase for a specific event or campaign, contact support at least 5 business days in advance.