Rate Limit Error Handling

Learn how to properly handle rate limit errors and implement retry logic.

Rate Limit Error Response

When you exceed your rate limit, the API returns a 429 Too Many Requests status code.

Loading code...
Error Response Fields
  • success - Always false
  • error - Error code: rate_limit_exceeded
  • message - Human-readable error message
  • retryAfter - Seconds to wait before retrying

Important Headers

Rate Limit Headers
  • Retry-After - Number of seconds to wait before retrying (present on 429 responses)
  • X-RateLimit-Limit - Your plan's rate limit (e.g., 10, 20)
  • X-RateLimit-Remaining - Requests remaining in current window
  • X-RateLimit-Reset - Timestamp when the limit resets

Basic Retry Logic

Always respect the Retry-After header when implementing retry logic.

Loading code...

Exponential Backoff

For more robust error handling, implement exponential backoff with jitter.

Loading code...
How Exponential Backoff Works
  • • Start with a short delay (e.g., 1 second)
  • • Double the delay after each failed retry
  • • Cap the maximum delay to avoid excessive waits
  • • Still respect the Retry-After header when present
  • • Add jitter to prevent thundering herd problems

Error Handling Best Practices

Do
  • • Always check for 429 status codes
  • • Respect Retry-After headers
  • • Implement exponential backoff
  • • Log rate limit errors for monitoring
  • • Set maximum retry attempts
  • • Monitor rate limit headers proactively
Don't
  • • Ignore 429 errors
  • • Retry immediately without waiting
  • • Retry indefinitely
  • • Use fixed delays instead of Retry-After
  • • Make requests faster than your limit
  • • Ignore rate limit headers

Proactive Monitoring

Prevent Rate Limit Errors
Loading code...
PageSight | PageSight