Skip to main content

Command Palette

Search for a command to run...

API Rate Limiting Cheat Sheet: Headers, Patterns & Best Practices

Complete developer reference: common headers, rate limits for 20+ APIs, implementation patterns, and production code examples

Published
5 min readView as Markdown

Quick Answer: API rate limiting controls how many requests a client can make to an API within a specific time window (e.g., 100 requests per minute). Essential response headers include X-RateLimit-Limit, X-RateLimit-Remaining, and Retry-After. Implement exponential backoff when hitting 429 errors.

Originally published at apistatuscheck.com

Rate limiting is the invisible traffic cop of the API world. Whether you're integrating with Stripe's payment APIs, GitHub's webhooks, or OpenAI's GPT models, understanding rate limits is non-negotiable for production applications.

What is API Rate Limiting?

API rate limiting controls the number of requests a client can make within a specified time window. It serves multiple purposes:

  • Performance Protection: Prevents resource monopolization
  • Cost Control: Manages infrastructure expenses
  • Security Defense: First line against DoS attacks
  • Fair Usage: Ensures equitable access across customers
  • Data Integrity: Prevents duplicate operations

Common Rate Limit HTTP Headers

HeaderDescriptionExample
X-RateLimit-LimitMax requests allowed5000
X-RateLimit-RemainingRequests remaining4273
X-RateLimit-ResetUnix timestamp for reset1738627200
Retry-AfterSeconds to wait (with 429)45

Parsing Headers in JavaScript

async function makeAPIRequest(url, options) {
  const response = await fetch(url, options);

  const limit = parseInt(response.headers.get('X-RateLimit-Limit'));
  const remaining = parseInt(response.headers.get('X-RateLimit-Remaining'));

  // Proactive throttling
  if (remaining < limit * 0.1) {
    console.warn('⚠️ Approaching rate limit');
    await sleep(1000);
  }

  if (response.status === 429) {
    const retryAfter = parseInt(response.headers.get('Retry-After') || '60');
    throw new RateLimitError(`Rate limited. Retry after ${retryAfter}s`);
  }

  return response.json();
}

Payment & Financial

APIFree/BasicStandardEnterprise
Stripe100 req/s (test)
25 req/s (live)
100 req/sCustom (1000+)
PayPal50 req/s100 req/sCustom
Plaid10 req/s50 req/sCustom

Communication

APILimitsNotes
Twilio1 msg/s (trial)
100 msg/s (paid)
Per account SID
SendGrid100 emails/day (free)
100 req/s (paid)
Plan-based
Slack1-100 req/minMethod-specific tiers

Developer Platforms

APIAuthenticatedUnauthenticated
GitHub5,000 req/hour60 req/hour
GitLab2,000 req/min10 req/min

AI & ML

APIModelRPMTPM
OpenAIGPT-4 (Tier 1)50030,000
OpenAIGPT-4 (Tier 5)10,000300M
AnthropicClaude (Pro)1,000Varies

E-commerce

APILimits
Shopify2 req/s (REST)
1000 points/s (GraphQL)
Amazon SP-API1-200 req/s (varies)

Cloud Infrastructure

ProviderServiceLimit
AWSAPI Gateway10,000 req/s
AWSLambda1,000 concurrent
Google CloudCloud Functions1,000 req/s

Implementation Patterns

Token Bucket

Most popular algorithm—allows controlled bursts while preventing abuse.

import time

class TokenBucket:
    def __init__(self, capacity, refill_rate):
        self.capacity = capacity
        self.tokens = capacity
        self.refill_rate = refill_rate
        self.last_refill = time.time()

    def consume(self, tokens=1):
        self._refill()
        if self.tokens >= tokens:
            self.tokens -= tokens
            return True
        return False

    def _refill(self):
        now = time.time()
        elapsed = now - self.last_refill
        tokens_to_add = elapsed * self.refill_rate
        self.tokens = min(self.capacity, self.tokens + tokens_to_add)
        self.last_refill = now

Fixed Window

Simplest implementation—fixed quota per time window.

Pros: Simple, predictable Cons: Burst vulnerability at window boundaries

Sliding Window

Considers past N time units from current moment.

Pros: Prevents burst exploitation Cons: Higher memory usage, more complex

Handling Rate Limits in Code

Exponential Backoff with Jitter

async function exponentialBackoff(fn, maxRetries = 5) {
  let retries = 0;

  while (retries < maxRetries) {
    try {
      return await fn();
    } catch (error) {
      if (error.status === 429) {
        retries++;
        if (retries >= maxRetries) throw new Error('Max retries exceeded');

        const baseDelay = Math.min(1000 * Math.pow(2, retries), 32000);
        const jitter = Math.random() * 1000;
        await sleep(baseDelay + jitter);
      } else {
        throw error;
      }
    }
  }
}

Request Queuing

class RateLimitedQueue {
  constructor(requestsPerSecond) {
    this.queue = [];
    this.requestsPerSecond = requestsPerSecond;
    this.delayBetweenRequests = 1000 / requestsPerSecond;
  }

  async enqueue(fn) {
    return new Promise((resolve, reject) => {
      this.queue.push({ fn, resolve, reject });
      this.processQueue();
    });
  }

  async processQueue() {
    if (this.processing || this.queue.length === 0) return;
    this.processing = true;

    while (this.queue.length > 0) {
      const { fn, resolve, reject } = this.queue.shift();
      try {
        const result = await fn();
        resolve(result);
      } catch (error) {
        reject(error);
      }
      if (this.queue.length > 0) {
        await sleep(this.delayBetweenRequests);
      }
    }
    this.processing = false;
  }
}

Monitoring Rate Limits

Proactive monitoring prevents surprises:

  • Track rate limit headers from every request
  • Alert at 80% consumption
  • Monitor 429 error rates
  • Use external monitoring services

API Status Check monitors 100+ APIs with real-time alerts.

FAQs

Q: Rate limiting vs throttling? A: Rate limiting enforces hard limits (429 errors). Throttling slows requests gradually.

Q: Request a limit increase? A: Document use case, show optimization efforts, contact support/sales.

Q: Implement my own rate limiting? A: Yes! Even internal APIs benefit from rate limiting.

Q: Webhooks during rate limits? A: Separate limits apply. Providers retry with exponential backoff.

Q: Risk of bans? A: Yes—persistent violations may result in IP bans or account suspension.

Q: Best algorithm? A: Token bucket for most applications—allows bursts while preventing abuse.

Q: Concurrent vs rate limits? A: Rate limits = requests/time. Concurrent = simultaneous in-flight requests.

Q: Test rate limit handling? A: Mock 429 responses, use test endpoints, load testing tools (k6, Artillery).


Read the full article with all code examples at: apistatuscheck.com/blog/api-rate-limiting-cheat-sheet

Monitor your APIs: API Status Check provides real-time monitoring and instant alerts for 100+ popular APIs.

More from this blog

A

Shibley

550 posts