# The Retry-After header: how long to wait, in seconds or a date

Retry-After tells a client when to try again, as a count of seconds or as an HTTP date. One dated response, and the wait worked out for both forms.

Canonical: https://spider.cloud/learn/retry-after/

Retry-After is an HTTP response header that tells a client how long to wait before it sends the next request. Its value is either a whole number of seconds, such as `120`, or a date in GMT. The client holds off until that many seconds have passed or that moment has come.

The header is defined in RFC 9110, the IETF document on HTTP semantics, which says servers send it "to indicate how long the user agent ought to wait before making a follow-up request." A client that reads it gets the server's own answer about when to come back. A client that ignores it has to guess, and a guess that is too short can draw the same refusal again.

This clip reads one 429 response on a clock, first as a count of seconds and then as a date.

How to read Retry-After. 54 s, no sound. The words are on screen, and the captions button shows them at your own text size.

Read the transcript

How to read Retry-After. A count of seconds or a date, and when to send the next request.

A value that is all digits counts seconds from when the response arrived. The response reads: 429 Too Many Requests. Retry-After: 120. The value is all digits, so it is a count of seconds. The response arrived at 18:49:43, so the client sends nothing for 120 s and the next request goes out at 18:51:43 at the earliest.

A date is a deadline. On a clock kept in sync, wait until it comes. The response reads: 429 Too Many Requests. Date: Fri, 20 Nov 2026 18:49:40 GMT. Retry-After: Fri, 20 Nov 2026 18:51:40 GMT. The value is a date, a deadline of 18:51:40. The response arrived at 18:49:43, so on a clock kept in sync 117 s are left, and the next request goes out at 18:51:40.

Or subtract Date from Retry-After and count that gap yourself. The response reads: 429 Too Many Requests. Date: Fri, 20 Nov 2026 18:49:40 GMT. Retry-After: Fri, 20 Nov 2026 18:51:40 GMT. Date is read: when the server wrote this. The value is a date, a deadline of 18:51:40. The Date header says the server wrote the response at 18:49:40, so the two are 120 s apart. The client counts 120 s from 18:49:43, when the response arrived, and sends the next request at 18:51:43, 3 s after the deadline.

Some values give you no wait to count. Other values: Retry-After: ?. past: Already passed: no wait. 120s: Not valid. Use your own pause. none: Do not retry at once.

Read the full page. The page is at spider.cloud/learn/retry-after.

## The two forms

RFC 9110 gives the value one line of grammar, `Retry-After = HTTP-date / delay-seconds`, and spells it out in prose: "The Retry-After field value can be either an HTTP-date or a number of seconds to delay after receiving the response." The RFC's own examples show one of each.

```text
Retry-After: Fri, 31 Dec 1999 23:59:59 GMT
Retry-After: 120
```

The seconds form is the simpler one. In the RFC's words, "A delay-seconds value is a non-negative decimal integer, representing time in seconds." So `1.5` is not a valid value, and neither is `120s`. The count starts when the response arrives, not when the request left.

The date form names a moment. Senders are meant to write it in one fixed layout, the one in the first example, which the RFC calls IMF-fixdate. Readers have to be more forgiving: "A recipient that parses a timestamp value in an HTTP field MUST accept all three HTTP-date formats." The other two are layouts the RFC marks as obsolete.

## Which responses carry it

RFC 9110 ties a meaning to two kinds of response. For the first it says "When sent with a 503 (Service Unavailable) response, Retry-After indicates how long the service is expected to be unavailable to the client." On a redirect it sets a floor, and the RFC says it "indicates the minimum time that the user agent is asked to wait before issuing the redirected request."

A crawler is more likely to meet it on a 429. RFC 6585 added the 429 status for a client that sends too many requests, and the example response in that RFC carries `Retry-After: 3600`, an hour. The same RFC also says "servers are not required to use the 429 status code", so a site under load may refuse or drop your requests without any header at all. The [status codes page](/learn/http-status-codes/) covers what to do with each of those codes when no Retry-After comes with them.

RFC 9110 names one more code. For a 413, a request body too large to accept, the RFC says "If the condition is temporary, the server SHOULD generate a Retry-After header field to indicate that it is temporary and after what time the client MAY try again."

## One response with the seconds form

The run below uses httpbin.org, a public service for testing HTTP clients. Its `/response-headers` endpoint sets the response headers named in its query string and writes them back into the body as JSON, so the header can be read from the page text. Set `SPIDER_API_KEY` to your key, then paste this.

```bash
curl -s https://api.spider.cloud/scrape \
  -H "Authorization: Bearer $SPIDER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"url": "https://httpbin.org/response-headers?Retry-After=120", "request": "http", "return_format": "raw", "user_agent": "examplebot/1.0 (+https://example.com/bot; bot@example.com)"}'
```

The run on 2026-11-20 returned one page. Below are the time line our client printed, the page's `url`, `status` and `error`, and the one line of the `content` field that holds the header. The other lines of the body are left out.

```text
/scrape at 2026-11-20T18:49:39+00:00, 1 pages in 1.2 s
url:     https://httpbin.org/response-headers?Retry-After=120
status:  200
error:   null
content: "Retry-After": "120"
```

The status is 200. That comes from the practice endpoint, which sets the header on an ordinary success because you asked it to. On a live site the same line is more likely to come with a 429 or a 503.

## Working out the wait for the seconds form

The value is `120`, which is all digits, so it is the seconds form. The wait is 120 seconds, counted from the moment your client received the response.

The time line above does not give that moment. It marks when the call started, cut to the whole second, and the 1.2 seconds covers the whole call. So record the receive time in your own client, as soon as the response arrives.

Here is the sum with a receive time we made up for it. A response received at 18:49:43 UTC clears the next request to that host at 18:51:43 UTC.

Two minutes is short. The 3600 in the RFC 6585 example would hold the same host for an hour from receipt, and a crawl that has other hosts in its queue can work on them in the meantime.

## Working out the wait for the date form

This example is worked by hand. No server returned the two lines below, and the only response printed on this page is the seconds form above. Suppose a server had answered with a date instead.

```text
Date: Fri, 20 Nov 2026 18:49:40 GMT
Retry-After: Fri, 20 Nov 2026 18:51:40 GMT
```

The date is a deadline, and the deadline here is 18:51:40 GMT. The time left is the deadline minus the time now. If the response reached you at 18:49:43 and your clock agrees with the server's, 117 seconds are left.

That sum is only as good as your clock. Run a minute fast and it gives you 57 seconds, and you retry a minute early.

A second sum needs no clock of yours. RFC 9110 says the Date header "represents the date and time at which the message was originated", so the server wrote both lines against one clock. Subtract Date from Retry-After and you get 120 seconds. Count those 120 seconds on your own timer, starting when the response arrived.

The second sum is a cautious estimate. It is not the time left. Date marks when the server wrote the response, and the response then took time to reach you. In the example it took 3 seconds, so you resume at 18:51:43, which is 3 seconds after the deadline. A response held up for five minutes on the way would arrive after the deadline had passed, and this sum would still tell you to wait 120 seconds more. It can only run long, never short.

Pick by what you know about your clock. On a machine kept in sync with a time server, measure to the deadline. Anywhere else, use the gap to Date and accept that you wait a little longer than the server asked.

Some responses carry no Date header. RFC 9110 says an origin server with a clock "MUST generate a Date header field in all 2xx (Successful), 3xx (Redirection), and 4xx (Client Error) responses", which covers a 429, "and MAY generate a Date header field in 1xx (Informational) and 5xx (Server Error) responses", which leaves a 503 without a promise. With no Date, or with one you cannot parse, the time you received the response is all you have. The RFC allows that swap for a bad value. Its words are that a recipient "MAY replace that value with the time that response was received."

A date that has already passed means a wait of zero. A value that is neither all digits nor a date you can parse means the header told you nothing, so fall back to your own pause.

## Both forms in a few lines

This Python function returns the wait in whole seconds, counted from `received_at`. That argument is the time your client recorded when the response arrived, and the function never reads the clock itself. It returns `None` when the header is missing or cannot be read.

Pass the response's Date value as `date_header` to get the cautious estimate. Leave it out to measure from `received_at` to the deadline. A fractional wait rounds up, so a deadline 0.8 seconds away gives 1, not 0.

```python
import math
import re
from datetime import datetime, timezone
from email.utils import parsedate_to_datetime

def http_date(text):
    try:
        when = parsedate_to_datetime(text)
    except (TypeError, ValueError):
        return None
    if when.tzinfo is None:
        when = when.replace(tzinfo=timezone.utc)
    return when

def retry_after_seconds(value, received_at, date_header=None):
    if value is None:
        return None
    value = value.strip()
    if re.fullmatch(r"[0-9]+", value):
        return int(value)
    deadline = http_date(value)
    if deadline is None:
        return None
    start = http_date(date_header) if date_header else None
    if start is None:
        start = received_at
    return max(0, math.ceil((deadline - start).total_seconds()))
```

## Where the header fits in a crawl

Retry-After answers one response from one host. A [web scraping](/web-scraping/) job sends thousands, and the header is the server correcting your pace after the fact. Choose a [request rate](/learn/request-rate/) slow enough that it rarely shows up, read the site's [robots.txt](/learn/robots-txt/) for a Crawl-delay line before you start, and send a [User-Agent](/learn/user-agent/) that tells the operator who to write to. When the header does arrive, take it as the site's own number, and come back at a slower rate than the one that drew it.

## Do this, avoid this

### Do this

- Record the receive time as soon as each response arrives, before any parsing or queueing.
- Check whether the value is all digits. If it is, wait that many seconds from the receive time.
- For a date, count the gap to the response's Date header from the receive time, unless your clock is synced.
- Hold the wait per host, so other hosts in the queue keep going while one waits.
- Log the status, the raw header and the time you resumed, so you can check the sum later.

### Avoid this

- Reading the value with an integer parser and nothing else, which turns every date into an error or a zero.
- Adding a date to the current time as if it were a count of seconds.
- Measuring a date against a clock you have never synced.
- Reporting the Date-based wait as the time left until the deadline. It runs longer.
- Retrying a 429 at once because it came without the header.

You can test the function without sending a request. Feed it the made-up values from this page, with 18:49:43 as the receive time.

```python
received_at = datetime(2026, 11, 20, 18, 49, 43, tzinfo=timezone.utc)
date = "Fri, 20 Nov 2026 18:49:40 GMT"
deadline = "Fri, 20 Nov 2026 18:51:40 GMT"

print(retry_after_seconds("120", received_at))           # 120
print(retry_after_seconds(deadline, received_at, date))  # 120
print(retry_after_seconds(deadline, received_at))        # 117
```

The first two lines print 120 and the third prints 117. The 3 seconds between them are the trip the response made. If your own parser gives other numbers for these inputs, fix it before it meets a real 429.

## Sources

1. [RFC 9110, HTTP Semantics, sections 6.6.1 and 10.2.3, Date and Retry-After, IETF, June 2022](https://www.rfc-editor.org/rfc/rfc9110.html) Read November 20, 2026
2. [RFC 6585, Additional HTTP Status Codes, section 4, 429 Too Many Requests, IETF, April 2012](https://www.rfc-editor.org/rfc/rfc6585.html) Read November 20, 2026
