@@ -268,6 +268,7 @@ export abstract class APIClient {
268
268
options : FinalRequestOptions < Req > ,
269
269
{ retryCount = 0 } : { retryCount ?: number } = { } ,
270
270
) : { req : RequestInit ; url : string ; timeout : number } {
271
+ options = { ...options } ;
271
272
const { method, path, query, headers : headers = { } } = options ;
272
273
273
274
const body =
@@ -278,9 +279,9 @@ export abstract class APIClient {
278
279
279
280
const url = this . buildURL ( path ! , query ) ;
280
281
if ( 'timeout' in options ) validatePositiveInteger ( 'timeout' , options . timeout ) ;
281
- const timeout = options . timeout ?? this . timeout ;
282
+ options . timeout = options . timeout ?? this . timeout ;
282
283
const httpAgent = options . httpAgent ?? this . httpAgent ?? getDefaultAgent ( url ) ;
283
- const minAgentTimeout = timeout + 1000 ;
284
+ const minAgentTimeout = options . timeout + 1000 ;
284
285
if (
285
286
typeof ( httpAgent as any ) ?. options ?. timeout === 'number' &&
286
287
minAgentTimeout > ( ( httpAgent as any ) . options . timeout ?? 0 )
@@ -309,7 +310,7 @@ export abstract class APIClient {
309
310
signal : options . signal ?? null ,
310
311
} ;
311
312
312
- return { req, url, timeout } ;
313
+ return { req, url, timeout : options . timeout } ;
313
314
}
314
315
315
316
private buildHeaders ( {
@@ -337,15 +338,22 @@ export abstract class APIClient {
337
338
delete reqHeaders [ 'content-type' ] ;
338
339
}
339
340
340
- // Don't set the retry count header if it was already set or removed through default headers or by the
341
- // caller. We check `defaultHeaders` and `headers`, which can contain nulls, instead of `reqHeaders` to
342
- // account for the removal case.
341
+ // Don't set theses headers if they were already set or removed through default headers or by the caller.
342
+ // We check `defaultHeaders` and `headers`, which can contain nulls, instead of `reqHeaders` to account
343
+ // for the removal case.
343
344
if (
344
345
getHeader ( defaultHeaders , 'x-stainless-retry-count' ) === undefined &&
345
346
getHeader ( headers , 'x-stainless-retry-count' ) === undefined
346
347
) {
347
348
reqHeaders [ 'x-stainless-retry-count' ] = String ( retryCount ) ;
348
349
}
350
+ if (
351
+ getHeader ( defaultHeaders , 'x-stainless-timeout' ) === undefined &&
352
+ getHeader ( headers , 'x-stainless-timeout' ) === undefined &&
353
+ options . timeout
354
+ ) {
355
+ reqHeaders [ 'x-stainless-timeout' ] = String ( options . timeout ) ;
356
+ }
349
357
350
358
this . validateHeaders ( reqHeaders , headers ) ;
351
359
0 commit comments