@@ -315,6 +315,7 @@ export abstract class APIClient {
315
315
options : FinalRequestOptions < Req > ,
316
316
{ retryCount = 0 } : { retryCount ?: number } = { } ,
317
317
) : { req : RequestInit ; url : string ; timeout : number } {
318
+ options = { ...options } ;
318
319
const { method, path, query, headers : headers = { } } = options ;
319
320
320
321
const body =
@@ -327,9 +328,9 @@ export abstract class APIClient {
327
328
328
329
const url = this . buildURL ( path ! , query ) ;
329
330
if ( 'timeout' in options ) validatePositiveInteger ( 'timeout' , options . timeout ) ;
330
- const timeout = options . timeout ?? this . timeout ;
331
+ options . timeout = options . timeout ?? this . timeout ;
331
332
const httpAgent = options . httpAgent ?? this . httpAgent ?? getDefaultAgent ( url ) ;
332
- const minAgentTimeout = timeout + 1000 ;
333
+ const minAgentTimeout = options . timeout + 1000 ;
333
334
if (
334
335
typeof ( httpAgent as any ) ?. options ?. timeout === 'number' &&
335
336
minAgentTimeout > ( ( httpAgent as any ) . options . timeout ?? 0 )
@@ -358,7 +359,7 @@ export abstract class APIClient {
358
359
signal : options . signal ?? null ,
359
360
} ;
360
361
361
- return { req, url, timeout } ;
362
+ return { req, url, timeout : options . timeout } ;
362
363
}
363
364
364
365
private buildHeaders ( {
@@ -386,15 +387,22 @@ export abstract class APIClient {
386
387
delete reqHeaders [ 'content-type' ] ;
387
388
}
388
389
389
- // Don't set the retry count header if it was already set or removed through default headers or by the
390
- // caller. We check `defaultHeaders` and `headers`, which can contain nulls, instead of `reqHeaders` to
391
- // account for the removal case.
390
+ // Don't set theses headers if they were already set or removed through default headers or by the caller.
391
+ // We check `defaultHeaders` and `headers`, which can contain nulls, instead of `reqHeaders` to account
392
+ // for the removal case.
392
393
if (
393
394
getHeader ( defaultHeaders , 'x-stainless-retry-count' ) === undefined &&
394
395
getHeader ( headers , 'x-stainless-retry-count' ) === undefined
395
396
) {
396
397
reqHeaders [ 'x-stainless-retry-count' ] = String ( retryCount ) ;
397
398
}
399
+ if (
400
+ getHeader ( defaultHeaders , 'x-stainless-timeout' ) === undefined &&
401
+ getHeader ( headers , 'x-stainless-timeout' ) === undefined &&
402
+ options . timeout
403
+ ) {
404
+ reqHeaders [ 'x-stainless-timeout' ] = String ( options . timeout ) ;
405
+ }
398
406
399
407
this . validateHeaders ( reqHeaders , headers ) ;
400
408
0 commit comments