Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Retry-After Header: API Rate Limits Explained

· 6 min read · Home Tech

In this article
  1. Background: Why Rate Limits Exist
  2. How the Retry-After Header Works
  3. Relationship to Other Rate Limit Headers
  4. How to Choose Between Retry-After and Exponential Backoff
  5. Common Problems and Misconceptions
  6. Comparing Retry-After Across Popular APIs
  7. Costs and Safety of Ignoring Retry-After
  8. Alternatives to Retry-After
  9. Frequently Asked Questions

The Retry-After HTTP header tells a client exactly how long to wait before making its next request after an API rate limit has been exceeded. It appears in 429 Too Many Requests or 503 Service Unavailable responses, and its value is either a number of seconds or an HTTP date. By honoring this header, clients can avoid hammering a server that is already overloaded, and they can resume normal operation as soon as the limit resets.

Background: Why Rate Limits Exist

APIs use rate limits to protect their infrastructure from abuse, accidental or intentional. Without limits, a single client could send thousands of requests per second, degrading service for everyone else. Rate limits also help API providers manage costs, prevent security attacks like credential stuffing, and ensure fair usage across all consumers.

When a client exceeds the allowed number of requests within a time window, the server responds with a status code indicating the problem. The Retry-After header is the standard way to communicate when the client can try again. It is defined in RFC 7231 and is widely supported by API platforms.

How the Retry-After Header Works

The header can carry one of two formats:

  • Delay-seconds: An integer representing the number of seconds to wait. Example: Retry-After: 120 means wait 120 seconds.
  • HTTP-date: A specific date and time after which to retry, in IMF-fixdate format (e.g., Retry-After: Wed, 21 Oct 2025 07:28:00 GMT).

Most APIs use the delay-seconds format because it is simpler for clients to parse. However, the date format is useful when the reset time is tied to a fixed schedule, such as a daily quota reset at midnight UTC.

When a client receives a 429 response, it should:

  1. Read the Retry-After header.
  2. If present, wait the specified time before retrying.
  3. If absent, use a fallback strategy (e.g., exponential backoff).

This behavior is recommended by RFC 7231, which states that a server SHOULD send the header with a 429 response.

Relationship to Other Rate Limit Headers

Many APIs also send headers like X-RateLimit-Limit, X-RateLimit-Remaining, and X-RateLimit-Reset. These are not standardized, but they provide additional context:

  • X-RateLimit-Limit: Maximum requests allowed in the current window.
  • X-RateLimit-Remaining: How many requests are left before hitting the limit.
  • X-RateLimit-Reset: Unix timestamp when the limit resets.

While Retry-After tells you how long to pause, the X-RateLimit-Reset tells you when the window resets. They should be consistent, but if they differ, trust Retry-After because it is the server’s explicit instruction.

How to Choose Between Retry-After and Exponential Backoff

If the server provides Retry-After, use it. It is the most accurate signal. However, there are cases where you might still need a backoff strategy:

  • No Retry-After header: Some APIs omit it. In that case, implement exponential backoff with jitter (randomized delay) to avoid thundering herd problems.
  • Multiple limits: If you hit a limit for a specific endpoint, the header may only apply to that endpoint, not the whole API.
  • Server errors: For 503 responses, Retry-After may indicate a temporary outage, not a rate limit. Combine it with a retry count limit to avoid infinite loops.

A common practice is to use Retry-After when present, and fall back to exponential backoff starting at 1 second and doubling up to a maximum (e.g., 60 seconds) when absent.

Common Problems and Misconceptions

One misconception is that Retry-After is always in seconds. It can also be a date, so clients must parse both formats. Another issue is that some servers send the header even when the limit is not exceeded, such as in a 200 response to indicate when the next window begins—though this is rare and not standard.

Another problem is ignoring the header entirely. Some clients retry immediately, which can lead to repeated 429 responses and potentially getting the client’s IP banned. Always honor the header to maintain good API citizenship.

Also, be aware that the header value can be a float in some implementations, though the spec says it should be an integer. Use a tolerant parser that accepts both integer and decimal numbers.

While the header is standard, its usage varies. For example:

  • GitHub: Sends Retry-After in seconds when rate limited, and also provides X-RateLimit-Reset.
  • Twitter/X: Uses Retry-After in seconds on 429 responses.
  • Stripe: Sends Retry-After on 429 responses, and recommends honoring it.

Even if an API does not document the header, it is safe to assume it follows the RFC. If you are unsure, check the API’s documentation or test with a controlled request.

Costs and Safety of Ignoring Retry-After

Ignoring Retry-After can have real costs: your application may be temporarily blocked, you may incur higher latency due to repeated failures, and you might even be charged for failed requests if the API bills per call. In extreme cases, providers may revoke access keys.

Safety-wise, always implement a maximum retry count to avoid infinite loops. For example, if you still receive 429 after 5 retries, stop and alert the user. Also, consider using a distributed lock if you have multiple servers making requests, to avoid all of them retrying at the same time.

Alternatives to Retry-After

Some APIs use a Retry-After equivalent in the response body, such as a JSON field named retry_after or retryAfter. Others use the Retry-After header only for 503 responses, not for rate limits. In such cases, you must read the documentation.

Another alternative is to implement client-side rate limiting to avoid hitting the limit in the first place. By tracking your own request count and reset time, you can throttle requests proactively, reducing the need to handle 429 responses at all.

Frequently Asked Questions

What does Retry-After: 0 mean?

It means the server suggests you can retry immediately. This might happen if the limit resets right away or if the server is just signaling a temporary condition that is already over. However, it is still a signal to pause briefly, as immediate retries may still fail.

Is Retry-After required on 429 responses?

No, it is not required by the RFC, but it is strongly recommended. If it is missing, you should implement a fallback like exponential backoff.

Can Retry-After be used for 503 responses?

Yes. For 503 Service Unavailable, the header indicates how long the service is expected to be down. It is not always rate-limit related, but the same client logic applies.

How do I parse Retry-After in my code?

Check if the value is an integer. If so, treat it as seconds. If not, try to parse it as an HTTP date (e.g., using Date.parse in JavaScript or datetime.strptime in Python). If both fail, ignore it and use a default backoff.

What if Retry-After is very large, like 86400?

That means wait a full day. This could happen if you hit a daily quota. In that case, you might want to stop making requests entirely and inform the user, rather than keeping the connection open.

Does Retry-After apply to all endpoints?

Not necessarily. The header is per-response, so it applies to the specific request that got the 429. Other endpoints may have different limits. Read the API documentation to understand the scope.