You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
An object representing `limit`, `methods`, `statusCodes`, `afterStatusCodes`, `maxRetryAfter`, `backoffLimit`, `delay`, `jitter`, `retryOnTimeout`, and `shouldRetry` fields for maximum retry count, allowed methods, allowed status codes, status codes allowed to use the [`Retry-After`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After) time, maximum [`Retry-After`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After) time, backoff limit, delay calculation function, retry jitter, timeout retry behavior, and custom retry logic.
262
+
An object representing `limit`, `methods`, `statusCodes`, `afterStatusCodes`, `maxRetryAfter`, `backoffLimit`, `delay`, `jitter`, `retryOnTimeout`, `resetTimeout`, and `shouldRetry` fields for maximum retry count, allowed methods, allowed status codes, status codes allowed to use the [`Retry-After`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After) time, maximum [`Retry-After`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After) time, backoff limit, delay calculation function, retry jitter, timeout retry behavior, timeout reset behavior, and custom retry logic.
262
263
263
264
If `retry` is a number, it will be used as `limit` and other defaults will remain in place.
264
265
@@ -280,6 +281,8 @@ The `jitter` option adds random jitter to retry delays to prevent thundering her
280
281
281
282
The `retryOnTimeout` option determines whether to retry when a request times out. By default, retries are not triggered following a [timeout](#timeout).
282
283
284
+
The `resetTimeout` option gives each retry attempt the full `timeout` value instead of the remaining budget. By default, `timeout` is a total timeout across all retries, meaning later retries get progressively less time. When `resetTimeout` is `true`, each retry starts with a fresh timeout. If you need both per-request timeout and a total timeout cap, combine `resetTimeout: true` with `signal: AbortSignal.timeout(totalMs)`.
285
+
283
286
The `shouldRetry` option provides custom retry logic that **takes precedence over the default retry checks** (`retryOnTimeout`, status code checks, etc.) for retriable methods. It is only called after the retry limit and method checks pass.
284
287
285
288
**Note:** This is different from the `beforeRetry` hook:
Timeout in milliseconds for getting a response, including any retries. Can not be greater than 2147483647.
404
+
Timeout in milliseconds for getting a response, including any retries. Cannot be greater than 2147483647. Use [`retry.resetTimeout`](#retry) to give each retry attempt the full timeout instead of sharing a single budget across all attempts.
Copy file name to clipboardExpand all lines: source/types/options.ts
+3-2Lines changed: 3 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -145,7 +145,7 @@ export type KyOptions = {
145
145
prefix?: URL|string;
146
146
147
147
/**
148
-
An object representing `limit`, `methods`, `statusCodes`, `afterStatusCodes`, `maxRetryAfter`, `backoffLimit`, `delay`, `jitter`, `retryOnTimeout`, and `shouldRetry` fields for maximum retry count, allowed methods, allowed status codes, status codes allowed to use the [`Retry-After`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After) time, maximum [`Retry-After`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After) time, backoff limit, delay calculation function, retry jitter, timeout retry behavior, and custom retry logic.
148
+
An object representing `limit`, `methods`, `statusCodes`, `afterStatusCodes`, `maxRetryAfter`, `backoffLimit`, `delay`, `jitter`, `retryOnTimeout`, `resetTimeout`, and `shouldRetry` fields for maximum retry count, allowed methods, allowed status codes, status codes allowed to use the [`Retry-After`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After) time, maximum [`Retry-After`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After) time, backoff limit, delay calculation function, retry jitter, timeout retry behavior, timeout reset behavior, and custom retry logic.
149
149
150
150
If `retry` is a number, it will be used as `limit` and other defaults will remain in place.
151
151
@@ -171,7 +171,8 @@ export type KyOptions = {
171
171
retry?: RetryOptions|number;
172
172
173
173
/**
174
-
Timeout in milliseconds for getting a response, including any retries. Can not be greater than 2147483647.
174
+
Timeout in milliseconds for getting a response, including any retries. Cannot be greater than 2147483647. Use `retry.resetTimeout` to give each retry attempt the full timeout instead of sharing a single budget across all attempts.
Copy file name to clipboardExpand all lines: source/types/retry.ts
+25Lines changed: 25 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -123,6 +123,31 @@ export type RetryOptions = {
123
123
*/
124
124
retryOnTimeout?: boolean;
125
125
126
+
/**
127
+
Whether to reset the timeout for each retry attempt.
128
+
129
+
By default, the `timeout` option is a total timeout across all retries. When `resetTimeout` is `true`, each retry attempt gets the full `timeout` value instead of the remaining budget.
130
+
131
+
If you need both per-request timeout and a total timeout cap, combine `resetTimeout: true` with `signal: AbortSignal.timeout(totalMs)`.
132
+
133
+
@default false
134
+
135
+
@example
136
+
```
137
+
import ky from 'ky';
138
+
139
+
const json = await ky('https://example.com', {
140
+
timeout: 5000,
141
+
retry: {
142
+
limit: 3,
143
+
retryOnTimeout: true,
144
+
resetTimeout: true
145
+
}
146
+
}).json();
147
+
```
148
+
*/
149
+
resetTimeout?: boolean;
150
+
126
151
/**
127
152
A function to determine whether a retry should be attempted.
0 commit comments