Works on this device
HTTP Retry Policy Generator
Write a retry policy for an HTTP client. Choose what to retry, which methods may be sent again, how long to wait and when to stop. The tool writes the policy as JSON, as JavaScript for fetch, or as Python for requests with urllib3, and checks single answers against it.
Enter your values
Check these values
Your values are worked out in this browser. They are not sent to a server.
Your result will show here
Fill in the values, then choose the button below them.
Your result
How it was worked out
How to use this generator
- Choose Write a retry policy to get code or JSON, or Check one answer to see what the policy does with one failed request.
- Type the number of retries and the status codes to retry, and tick whether connection failures and timeouts are retried.
- Choose the methods that may be sent again, whether to honour Retry-After, the backoff and the timeouts.
- Choose Generate. Copy the text or download it as a file. Read the code and test it before you use it.
The rules behind a good policy
- Retry only what can succeed later: 408 (Request Timeout), 429 (Too Many Requests), 500, 502, 503 and 504, and failed connections and timeouts. Most other 4xx answers mean that the request itself is wrong.
- Retry only methods that may run twice: GET, HEAD, OPTIONS and TRACE are safe, and with PUT and DELETE they are idempotent (RFC 9110, section 9.2). A retried POST can make a second order or payment, unless the server supports an Idempotency-Key header (an IETF Internet-Draft).
- Honour Retry-After (RFC 9110, section 10.2.3): a whole number of seconds or an HTTP date such as Wed, 21 Oct 2026 07:28:00 GMT. Set a longest wait you accept.
- Back off: wait longer before each retry, with jitter so that clients do not retry together. The rules are those of the Retry Backoff Calculator.
- Limit the time: longest time = (retries + 1) × timeout per try + the longest total wait, unless a total time limit stops it earlier.
Worked example
The default policy retries 408, 429, 500, 502, 503 and 504 up to 3 times, for idempotent methods only. Exponential backoff from 200 ms with factor 2 and full jitter waits at most 200, 400 and 800 ms, 1.4 s in total. If every answer asks for the longest Retry-After you accept (60 s), the waits add up to 180 s, and with a timeout of 10 s per try the longest time is 4 × 10 + 180 = 220 s.
In the check: a GET that got 503 with no Retry-After, as the first retry, waits a random time from 0 to 200 ms and has 2 retries left. If the answer says Retry-After: 120, the client stops, because 120 seconds is more than the 60 seconds it accepts.
Limits you should know
- The tool writes text. It does not send requests and cannot test your API.
- The JSON layout is this tool's own; no library reads it as it is. The JavaScript needs a current browser or Node.js 20 or later.
- The urllib3 Retry class cannot express everything: it doubles every wait, waits nothing before the first retry, has no full or equal jitter and no longest Retry-After. The code says what differs. Check the parameters against the urllib3 documentation for your version.
- To split a time budget over several calls, use the Request Timeout Calculator. To plan how many requests stay under a rate limit, use the API Rate Limit Calculator.