Skip to main content

Automatic Retries

The SDK automatically retries on transient errors (429, 500, 503, 504, and network errors) with exponential backoff. Retry behavior:
  • GET and DELETE requests are always retried
  • Enrichment calls generate an idempotency key and reuse it across automatic retries. Supply your own idempotencyKey to safely retry across separate calls
  • A 409 for the same enrichment that is still in progress is retried after Retry-After and returns the stored result. A 409 with reason: "payload_mismatch" is not retried
  • The Retry-After header is respected when present
  • With pacing, after a 429 other calls on the same client wait too (see Pacing), and a retry is only sent with at least min(1s, timeout / 2) of maxRetryTime left
  • Defaults: 3 retries, 500ms base delay, 30s max delay
Disable retries entirely:

Pacing

Pacing keeps a client’s requests within your organization’s rate limits, so a burst of calls, such as Promise.all over a batch, waits its turn on the client instead of being refused with 429. It is on by default in Node.js and Bun, and off by default elsewhere (see Cloudflare Workers and other runtimes).
  • Concurrency. Enrichments in flight stay within X-RateLimit-Concurrency-Limit. Only enrichments wait for one of these slots, so reads are not held behind a queued batch.
  • Rate. All requests are spaced to the per-second rate in X-RateLimit-Limit on responses whose X-RateLimit-Scope is rps or absent. When X-RateLimit-Remaining shows fewer requests left than the client expects, for example while another process uses the same organization, the client slows down to match.
  • Before the limits are known. Until a response reports them, at most 5 requests are in flight, enrichments included. A proxy that strips the X-RateLimit-* headers keeps a client at this limit; set pacing: false or explicit limits in that case.
  • After a 429. Every call on the client waits for the limit it names: X-RateLimit-Scope: rps, or no scope, pauses all requests; concurrency pauses enrichments, and enrichments that hold a slot but have not been sent give it back. The pause lasts the Retry-After time plus up to 20% (at most 1 second) of jitter. Without Retry-After, it lasts until X-RateLimit-Reset, measured against the response’s Date header, when that is at most 10 seconds away; otherwise the normal backoff applies. Other calls wait at most 60 seconds before trying again.
  • Fewer enrichments after a concurrency 429. The client keeps fewer enrichments in flight than were running when it was refused, then adds one back after as many successful enrichments as its current limit, counting only enrichments sent after the decrease. Refusals of enrichments sent before the limit was known do not lower it.
  • Retries first. A call that is retried keeps its place, and its enrichment slot while the limit allows, and goes ahead of calls that have not been sent yet.
  • Budgets. Waiting for a turn before the first attempt is limited by pacing.maxWait (default: maxRetryTime), not by timeout or maxRetryTime. A call that waits longer rejects with PacingTimeoutError and is never sent or charged. maxRetryTime starts when the first attempt is sent. Pass a signal to cancel a call at any point.
Pacing is per client, so share one client across a batch. Processes that share an organization also share its limits: give each one lower limits. Your limits apply when they are lower than the API’s:
To send every request as soon as it is made, disable pacing:

Cloudflare Workers and other runtimes

Pacing is off by default in Cloudflare Workers, Deno, edge runtimes and browsers. Workers bind the work of each request to that request, so one request cannot reliably wait for another’s call to finish. In Workers, create the client inside each request handler, or keep pacing off. Within one request, pacing: true still paces a batch of calls on that request’s client. If you opt in with a client shared across requests, a slot granted to a request that no longer runs returns to the pool within a second; pass { signal: request.signal } to each call, so a call whose client has gone is not sent.

Tests with fake timers

Pacing uses Date.now() and setTimeout. In tests that fake timers, fake both and advance the clock, or set pacing: false.

Rate Limiting

Rate limit information is available on responses from rate-limited endpoints. The SDK paces requests and handles 429 responses automatically, but you can monitor usage:

Health & API Info

Raw Requests

For endpoints not yet covered by a resource class, or when you need the full HTTP response (headers, rate limit info):
The client also exposes rawPost and rawDelete for other HTTP methods.

TypeScript

The SDK is written in TypeScript and ships with complete type definitions. All request and response types are exported: