@@ -280,6 +280,7 @@ export abstract class APIClient {
280
280
options : FinalRequestOptions < Req > ,
281
281
{ retryCount = 0 } : { retryCount ?: number } = { } ,
282
282
) : { req : RequestInit ; url : string ; timeout : number } {
283
+ options = { ...options } ;
283
284
const { method, path, query, headers : headers = { } } = options ;
284
285
285
286
const body =
@@ -292,9 +293,9 @@ export abstract class APIClient {
292
293
293
294
const url = this . buildURL ( path ! , query ) ;
294
295
if ( 'timeout' in options ) validatePositiveInteger ( 'timeout' , options . timeout ) ;
295
- const timeout = options . timeout ?? this . timeout ;
296
+ options . timeout = options . timeout ?? this . timeout ;
296
297
const httpAgent = options . httpAgent ?? this . httpAgent ?? getDefaultAgent ( url ) ;
297
- const minAgentTimeout = timeout + 1000 ;
298
+ const minAgentTimeout = options . timeout + 1000 ;
298
299
if (
299
300
typeof ( httpAgent as any ) ?. options ?. timeout === 'number' &&
300
301
minAgentTimeout > ( ( httpAgent as any ) . options . timeout ?? 0 )
@@ -323,7 +324,7 @@ export abstract class APIClient {
323
324
signal : options . signal ?? null ,
324
325
} ;
325
326
326
- return { req, url, timeout } ;
327
+ return { req, url, timeout : options . timeout } ;
327
328
}
328
329
329
330
private buildHeaders ( {
@@ -351,15 +352,22 @@ export abstract class APIClient {
351
352
delete reqHeaders [ 'content-type' ] ;
352
353
}
353
354
354
- // Don't set the retry count header if it was already set or removed through default headers or by the
355
- // caller. We check `defaultHeaders` and `headers`, which can contain nulls, instead of `reqHeaders` to
356
- // account for the removal case.
355
+ // Don't set theses headers if they were already set or removed through default headers or by the caller.
356
+ // We check `defaultHeaders` and `headers`, which can contain nulls, instead of `reqHeaders` to account
357
+ // for the removal case.
357
358
if (
358
359
getHeader ( defaultHeaders , 'x-stainless-retry-count' ) === undefined &&
359
360
getHeader ( headers , 'x-stainless-retry-count' ) === undefined
360
361
) {
361
362
reqHeaders [ 'x-stainless-retry-count' ] = String ( retryCount ) ;
362
363
}
364
+ if (
365
+ getHeader ( defaultHeaders , 'x-stainless-timeout' ) === undefined &&
366
+ getHeader ( headers , 'x-stainless-timeout' ) === undefined &&
367
+ options . timeout
368
+ ) {
369
+ reqHeaders [ 'x-stainless-timeout' ] = String ( options . timeout ) ;
370
+ }
363
371
364
372
this . validateHeaders ( reqHeaders , headers ) ;
365
373
0 commit comments