API Codex
API Guides

Rate Limiting & Quotas

API Codex implements rate limiting to ensure fair usage and maintain service quality for all users. This guide explains how rate limiting works and how to handle it effectively.

Overview

Rate limiting protects our APIs from abuse and ensures reliable performance for all users. Each subscription tier has different limits based on:

  • Requests per second (RPS)
  • Requests per month
  • Concurrent connections
  • Payload size limits

Subscription Tiers

Rate Limits by Plan

PlanRequests/MonthRequests/SecondConcurrent ConnectionsSupport
Basic (Free)100-1,0001 RPS2Community
Pro10,00010 RPS10Email
Ultra100,00050 RPS50Priority
Mega1,000,000+100+ RPSUnlimitedDedicated

Note: Exact limits vary by specific API. Check each API's pricing page on RapidAPI for details.

Rate Limit Headers

All API responses include headers that inform you about your current rate limit status:

Standard Headers

Code
x-ratelimit-requests-limit: 1000 x-ratelimit-requests-remaining: 847 x-ratelimit-requests-reset: 1640995200
HeaderDescriptionExample
x-ratelimit-requests-limitTotal requests allowed in current window1000
x-ratelimit-requests-remainingRequests remaining in current window847
x-ratelimit-requests-resetUnix timestamp when limit resets1640995200

Reading Rate Limit Headers

javascriptCode
const rateLimit = { limit: parseInt(response.headers.get('x-ratelimit-requests-limit')), remaining: parseInt(response.headers.get('x-ratelimit-requests-remaining')), reset: parseInt(response.headers.get('x-ratelimit-requests-reset')) }; // Warn if approaching limit (< 10% remaining) if (rateLimit.remaining < rateLimit.limit * 0.1) { console.warn('Approaching rate limit!'); }

Handling Rate Limits

429 Too Many Requests

When you exceed your rate limit, you'll receive a 429 status code:

jsonCode
{ "error": "Too Many Requests", "message": "Rate limit exceeded. Please retry after some time.", "retryAfter": 60 }

Implementing Retry Logic

Exponential Backoff

javascriptCode
async function executeWithRetry(requestFn, maxRetries = 3) { for (let attempt = 0; attempt < maxRetries; attempt++) { const response = await requestFn(); if (response.status === 429) { const retryAfter = response.headers.get('Retry-After'); const delay = retryAfter ? parseInt(retryAfter) * 1000 : 1000 * Math.pow(2, attempt) + Math.random() * 1000; await new Promise(r => setTimeout(r, delay)); continue; } return response; } throw new Error('Max retries exceeded'); }

Request Queue Management

For bulk operations, implement a request queue that:

  • Tracks requests per time window
  • Waits when limit is reached
  • Processes requests in order

Rate Limiting Strategies

1. Client-Side Throttling

Track requests in a sliding window and wait if limit is reached before making new requests.

2. Adaptive Rate Limiting

Adjust request rate based on remaining quota:

  • > 80% used: Slow down significantly
  • < 20% used: Can increase rate
  • 0 remaining: Wait until reset

3. Circuit Breaker Pattern

After multiple rate limit errors:

  • CLOSED → Normal operation
  • OPEN → Reject requests immediately, wait for timeout
  • HALF-OPEN → Test with one request, recover or stay open

Optimization Techniques

1. Request Batching

Combine multiple operations where possible. Check if the API supports batch endpoints.

2. Response Caching

Cache responses with appropriate TTLs to reduce API calls:

  • DNS lookups: 24 hours (respect TTL from response)
  • Email validation: 1 hour
  • Text analysis: 30 minutes

3. Parallel Processing with Limits

Process multiple requests in parallel, but limit concurrency to avoid overwhelming the API. Use Promise.race() to maintain a pool of active requests.

Monitoring & Alerts

Set up monitoring to track rate limit usage:

Alert LevelConditionAction
Warning> 80% usageReview request patterns
Critical0 remainingReduce request rate, investigate

Track metrics like average usage, peak usage, and requests per minute to identify patterns and optimize your usage.

Best Practices

Do's ✅

  1. Always check rate limit headers in responses
  2. Implement exponential backoff for retries
  3. Cache responses when appropriate
  4. Use request queuing for bulk operations
  5. Monitor your usage proactively
  6. Implement circuit breakers for resilience
  7. Batch requests when possible

Don'ts ❌

  1. Don't ignore 429 responses - Always handle them
  2. Don't retry immediately - Use backoff strategies
  3. Don't hammer the API - Respect rate limits
  4. Don't hardcode delays - Use adaptive timing
  5. Don't waste quota - Cache when possible

Upgrading Your Plan

If you consistently hit rate limits, consider upgrading:

  1. Monitor your usage patterns
  2. Calculate required capacity
  3. Visit RapidAPI
  4. Select appropriate plan
  5. Upgrade seamlessly without code changes

Next Steps

Last modified on