@@ -272,6 +272,64 @@ describe('retries', () => {
272
272
expect ( count ) . toEqual ( 3 ) ;
273
273
} ) ;
274
274
275
+ test ( 'omit retry count header' , async ( ) => {
276
+ let count = 0 ;
277
+ let capturedRequest : RequestInit | undefined ;
278
+ const testFetch = async ( url : RequestInfo , init : RequestInit = { } ) : Promise < Response > => {
279
+ count ++ ;
280
+ if ( count <= 2 ) {
281
+ return new Response ( undefined , {
282
+ status : 429 ,
283
+ headers : {
284
+ 'Retry-After' : '0.1' ,
285
+ } ,
286
+ } ) ;
287
+ }
288
+ capturedRequest = init ;
289
+ return new Response ( JSON . stringify ( { a : 1 } ) , { headers : { 'Content-Type' : 'application/json' } } ) ;
290
+ } ;
291
+ const client = new Anthropic ( { apiKey : 'my-anthropic-api-key' , fetch : testFetch , maxRetries : 4 } ) ;
292
+
293
+ expect (
294
+ await client . request ( {
295
+ path : '/foo' ,
296
+ method : 'get' ,
297
+ headers : { 'X-Stainless-Retry-Count' : null } ,
298
+ } ) ,
299
+ ) . toEqual ( { a : 1 } ) ;
300
+
301
+ expect ( capturedRequest ! . headers as Headers ) . not . toHaveProperty ( 'x-stainless-retry-count' ) ;
302
+ } ) ;
303
+
304
+ test ( 'overwrite retry count header' , async ( ) => {
305
+ let count = 0 ;
306
+ let capturedRequest : RequestInit | undefined ;
307
+ const testFetch = async ( url : RequestInfo , init : RequestInit = { } ) : Promise < Response > => {
308
+ count ++ ;
309
+ if ( count <= 2 ) {
310
+ return new Response ( undefined , {
311
+ status : 429 ,
312
+ headers : {
313
+ 'Retry-After' : '0.1' ,
314
+ } ,
315
+ } ) ;
316
+ }
317
+ capturedRequest = init ;
318
+ return new Response ( JSON . stringify ( { a : 1 } ) , { headers : { 'Content-Type' : 'application/json' } } ) ;
319
+ } ;
320
+ const client = new Anthropic ( { apiKey : 'my-anthropic-api-key' , fetch : testFetch , maxRetries : 4 } ) ;
321
+
322
+ expect (
323
+ await client . request ( {
324
+ path : '/foo' ,
325
+ method : 'get' ,
326
+ headers : { 'X-Stainless-Retry-Count' : '42' } ,
327
+ } ) ,
328
+ ) . toEqual ( { a : 1 } ) ;
329
+
330
+ expect ( ( capturedRequest ! . headers as Headers ) [ 'x-stainless-retry-count' ] ) . toBe ( '42' ) ;
331
+ } ) ;
332
+
275
333
test ( 'retry on 429 with retry-after' , async ( ) => {
276
334
let count = 0 ;
277
335
const testFetch = async ( url : RequestInfo , { signal } : RequestInit = { } ) : Promise < Response > => {
0 commit comments