Skip to content
D
Documentation

RetryOptions

reference
1 min readUpdated

Import it from ky.

ts
type RetryOptions = { … }

Properties

NameTypeDefaultDescription
limit?number | undefined2The number of times to retry failed requests. Must be a finite, non-negative integer.
methods?readonly HttpMethod[] | undefined['get', 'put', 'head', 'delete', 'options', 'trace', 'query']The HTTP methods allowed to retry.
statusCodes?readonly number[] | undefined[408, 413, 429, 500, 502, 503, 504]The HTTP status codes allowed to retry.
afterStatusCodes?readonly number[] | undefined[413, 429, 503]The retriable HTTP status codes that should respect retry timing headers. These status codes must also be included in statusCodes.
maxRetryAfter?number | undefinedInfinityIf the retry delay from a retry timing header is greater than maxRetryAfter, Ky will use maxRetryAfter.
backoffLimit?number | undefinedInfinityThe upper limit of the delay per retry in milliseconds. To clamp the delay, set backoffLimit to 1000, for example.
delay?((attemptCount: number) => number) | undefinedattemptCount => 0.3 * (2 ** (attemptCount - 1)) * 1000A function to calculate the delay in milliseconds between retries given attemptCount (starts from 1).
jitter?boolean | ((delay: number) => number) | undefinedundefined (no jitter)Add random jitter to retry delays to prevent thundering herd problems.
retryOnTimeout?boolean | undefinedfalseWhether to retry when the request times out before a response is returned. Timeouts while reading a response body through Ky shortcut methods are not retried because the response has already been received.
shouldRetry?((state: ShouldRetryState) => boolean | void | Promise<boolean | void>) | undefinedundefinedA function to determine whether a retry should be attempted.

Was this page helpful?

RetryOptions — ky · GPT-6 Luna