Which HTTP status codes should you retry?

The short answer: retry 408, 425, 429, 502, 503 and 504, be careful with 500 and 409, and don't retry other 4xx errors. Here's each one, and why.

Status codes

StatusRetry?WhySpec
408 Request TimeoutRetryThe server gave up waiting for the request. The spec says the client may repeat it.RFC 9110
409 ConflictIt dependsUsually a real conflict with the resource's state, which retrying won't fix. Some APIs use it for lock contention; the OpenAI and Anthropic SDKs retry it.RFC 9110
425 Too EarlyRetryThe server won't process a request sent in TLS early data. Retry after the handshake completes.RFC 8470
429 Too Many RequestsRetryYou're being rate limited. Wait for Retry-After if it's present, otherwise back off.RFC 6585
500 Internal Server ErrorIt dependsOften transient. Safe to retry for idempotent requests (GET, PUT, DELETE) or a POST with an idempotency key; a plain POST may already have taken effect.RFC 9110
502 Bad GatewayRetryA proxy got a bad answer from upstream. Usually transient. Same idempotency caution as 500.RFC 9110
503 Service UnavailableRetryOverloaded or down for maintenance. Honor Retry-After if present.RFC 9110
504 Gateway TimeoutRetryA proxy timed out waiting for upstream. The upstream may still have done the work, so the same idempotency caution applies.RFC 9110
400 Bad RequestDon't retryThe request is malformed. Sending it again gets the same answer.RFC 9110
401 UnauthorizedDon't retryCredentials are missing or wrong. Refresh the token once if you can, then stop.RFC 9110
403 ForbiddenDon't retryYou're not allowed. Retrying won't change that.RFC 9110
404 Not FoundDon't retryUnless you just created the resource in an eventually consistent system, it isn't coming back.RFC 9110
405 Method Not AllowedDon't retryThe method isn't supported on this URL.RFC 9110
410 GoneDon't retryRemoved on purpose, and the server is saying so.RFC 9110
413 Content Too LargeDon't retryMake the request smaller instead. (A Retry-After here means the limit is temporary.)RFC 9110
422 Unprocessable ContentDon't retryThe request is well formed but invalid, like a declined card or a failed validation.RFC 9110
501 Not ImplementedDon't retryThe server doesn't support the feature at all.RFC 9110

Network errors

What happenedRetry?Why
Connection refused or DNS failureRetryNothing reached the server, so it's always safe to try again.
Connection reset or dropped mid-responseIt dependsThe server may have processed the request. Safe for idempotent requests or with an idempotency key.
Your own timeout firedIt dependsSame as a dropped connection: the work may have happened. Retry idempotent requests within an overall deadline.
TLS or certificate errorDon't retryA configuration problem, not a transient one.

Three rules that matter more than the list

  • Only repeat what's safe to repeat. GET, HEAD, PUT and DELETE are idempotent by definition (RFC 9110). For a POST that charges a card or sends an email, send an Idempotency-Key header and keep it the same on every retry, if the API supports one.
  • Let the server set the pace. When a 429 or 503 carries Retry-After, wait that long (check a value with the Retry-After parser). Otherwise back off exponentially with jitter (try the backoff calculator).
  • Give up eventually. Cap the number of attempts and the total time, then surface the error to the caller instead of hanging.

Check what your client really does

Most retry bugs only show up when a dependency actually fails. Jitterbox's resilience report watches your client against an API that fails on purpose and flags exactly these mistakes: no retry after a 429 or 5xx, a retry sooner than Retry-After, no backoff, too many attempts, a retried 400/401/403/404/405/410/413/422, and a dropped idempotency key. The guide How to test retry logic shows the setup.

Test it against real failures

Jitterbox gives you a fake version of the APIs you call, at a real URL, and makes them fail on purpose. Free during the beta.