diff --git a/src/client.ts b/src/client.ts index 2f45bc4..72d9b4f 100644 --- a/src/client.ts +++ b/src/client.ts @@ -53,7 +53,7 @@ export class Client { const _client = createApiClient({ baseUrl: endpoint, headers, - fetch: fetchRetry(fetch) as any, // https://github.com/jonbern/fetch-retry/issues/89 + fetch: fetchRetry(fetch, { retryOn: [429] }), // Retry on network errors and when rate limits or concurrency limits (due to external factors) are hit }); const _streamingClient = createStreamingApiClient({ baseUrl: endpoint, diff --git a/tests/e2e/client.test.ts b/tests/e2e/client.test.ts index c1ce6d9..8427c75 100644 --- a/tests/e2e/client.test.ts +++ b/tests/e2e/client.test.ts @@ -1,3 +1,5 @@ +import range from 'lodash/range.js'; + import { Client } from '../../src/client.js'; import { HttpError } from '../../src/errors.js'; import { @@ -210,4 +212,13 @@ describe('client', () => { }).rejects.toHaveProperty('name', 'AbortError'); }); }); + + describe('limits', () => { + test('should handle rate limits', async () => { + const promise = Promise.all( + range(0, 100).map(() => client.tune.types({})), + ); + await expect(promise).toResolve(); + }); + }); });