@@ -294,6 +294,7 @@ export abstract class APIClient {
294
294
options : FinalRequestOptions < Req > ,
295
295
{ retryCount = 0 } : { retryCount ?: number } = { } ,
296
296
) : { req : RequestInit ; url : string ; timeout : number } {
297
+ options = { ...options } ;
297
298
const { method, path, query, headers : headers = { } } = options ;
298
299
299
300
const body =
@@ -306,9 +307,9 @@ export abstract class APIClient {
306
307
307
308
const url = this . buildURL ( path ! , query ) ;
308
309
if ( 'timeout' in options ) validatePositiveInteger ( 'timeout' , options . timeout ) ;
309
- const timeout = options . timeout ?? this . timeout ;
310
+ options . timeout = options . timeout ?? this . timeout ;
310
311
const httpAgent = options . httpAgent ?? this . httpAgent ?? getDefaultAgent ( url ) ;
311
- const minAgentTimeout = timeout + 1000 ;
312
+ const minAgentTimeout = options . timeout + 1000 ;
312
313
if (
313
314
typeof ( httpAgent as any ) ?. options ?. timeout === 'number' &&
314
315
minAgentTimeout > ( ( httpAgent as any ) . options . timeout ?? 0 )
@@ -337,7 +338,7 @@ export abstract class APIClient {
337
338
signal : options . signal ?? null ,
338
339
} ;
339
340
340
- return { req, url, timeout } ;
341
+ return { req, url, timeout : options . timeout } ;
341
342
}
342
343
343
344
private buildHeaders ( {
@@ -365,15 +366,22 @@ export abstract class APIClient {
365
366
delete reqHeaders [ 'content-type' ] ;
366
367
}
367
368
368
- // Don't set the retry count header if it was already set or removed through default headers or by the
369
- // caller. We check `defaultHeaders` and `headers`, which can contain nulls, instead of `reqHeaders` to
370
- // account for the removal case.
369
+ // Don't set theses headers if they were already set or removed through default headers or by the caller.
370
+ // We check `defaultHeaders` and `headers`, which can contain nulls, instead of `reqHeaders` to account
371
+ // for the removal case.
371
372
if (
372
373
getHeader ( defaultHeaders , 'x-stainless-retry-count' ) === undefined &&
373
374
getHeader ( headers , 'x-stainless-retry-count' ) === undefined
374
375
) {
375
376
reqHeaders [ 'x-stainless-retry-count' ] = String ( retryCount ) ;
376
377
}
378
+ if (
379
+ getHeader ( defaultHeaders , 'x-stainless-timeout' ) === undefined &&
380
+ getHeader ( headers , 'x-stainless-timeout' ) === undefined &&
381
+ options . timeout
382
+ ) {
383
+ reqHeaders [ 'x-stainless-timeout' ] = String ( options . timeout ) ;
384
+ }
377
385
378
386
this . validateHeaders ( reqHeaders , headers ) ;
379
387
0 commit comments