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`, `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.
261
+
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.
263
262
264
263
If `retry` is a number, it will be used as `limit` and other defaults will remain in place.
265
264
@@ -281,8 +280,6 @@ The `jitter` option adds random jitter to retry delays to prevent thundering her
281
280
282
281
The `retryOnTimeout` option determines whether to retry when a request times out. By default, retries are not triggered following a [timeout](#timeout).
283
282
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
-
286
283
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.
287
284
288
285
**Note:** This is different from the `beforeRetry` hook:
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.
386
+
Timeout in milliseconds for getting a response. Each retryattempt gets the full timeout. Cannot be greater than 2147483647.
405
387
406
388
If set to `false`, there will be no timeout.
407
389
390
+
##### totalTimeout
391
+
392
+
Type: `number | false`\
393
+
Default: `false`
394
+
395
+
Total timeout in milliseconds for the entire operation, including all retries and delays. Cannot be greater than 2147483647. Throws a `TimeoutError` if exceeded.
396
+
397
+
This is useful when you want to cap the total time spent on an operation, while still allowing each individual retry to use the full per-attempt `timeout`.
398
+
399
+
```js
400
+
importkyfrom'ky';
401
+
402
+
// Each attempt gets 5s, but the whole operation must complete within 30s
Copy file name to clipboardExpand all lines: source/types/options.ts
+29-3Lines changed: 29 additions & 3 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`, `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.
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.
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,14 +171,40 @@ export type KyOptions = {
171
171
retry?: RetryOptions|number;
172
172
173
173
/**
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.
174
+
Timeout in milliseconds for getting a response. Each retryattempt gets the full timeout. Cannot be greater than 2147483647.
175
175
176
176
If set to `false`, there will be no timeout.
177
177
178
178
@default 10000
179
179
*/
180
180
timeout?: number|false;
181
181
182
+
/**
183
+
Total timeout in milliseconds for the entire operation, including all retries and delays. Cannot be greater than 2147483647. Throws a `TimeoutError` if exceeded.
184
+
185
+
This is useful when you want to cap the total time spent on an operation, while still allowing each individual retry to use the full per-attempt `timeout`.
186
+
187
+
If set to `false` or not specified, there is no total timeout.
188
+
189
+
@default false
190
+
191
+
@example
192
+
```
193
+
import ky from 'ky';
194
+
195
+
// Each attempt gets 5s, but the whole operation must complete within 30s
196
+
const json = await ky('https://example.com', {
197
+
timeout: 5000,
198
+
totalTimeout: 30_000,
199
+
retry: {
200
+
limit: 3,
201
+
retryOnTimeout: true,
202
+
}
203
+
}).json();
204
+
```
205
+
*/
206
+
totalTimeout?: number|false;
207
+
182
208
/**
183
209
Hooks allow modifications during the request lifecycle. Hook functions may be async and are run serially.
Copy file name to clipboardExpand all lines: source/types/retry.ts
-25Lines changed: 0 additions & 25 deletions
Original file line number
Diff line number
Diff line change
@@ -123,31 +123,6 @@ 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
-
151
126
/**
152
127
A function to determine whether a retry should be attempted.
0 commit comments