Skip to content

Rule.io SDK


Rule.io SDK / client/src / RateLimitOptions

Interface: RateLimitOptions

Defined in: client/src/core/rate-limit.ts:40

User-facing rate-limit configuration. All fields optional with defaults.

Example

typescript
const client = new RuleClient({
  apiKey: process.env.RULE_API_KEY!,
  rateLimiting: {
    maxConcurrency: 4,
    maxRetries: 2,
    onRetry: ({ label, attempt, delayMs, honoredRetryAfter }) => {
      console.warn(
        `[rate-limit] retry ${attempt} of ${label} in ${delayMs} ms` +
          (honoredRetryAfter ? ' (server Retry-After)' : ' (backoff)')
      );
    },
  },
});

Properties

baseDelayMs?

optional baseDelayMs?: number

Defined in: client/src/core/rate-limit.ts:46

Base delay in ms for exponential backoff when no Retry-After header. Default: 1000.


maxConcurrency?

optional maxConcurrency?: number

Defined in: client/src/core/rate-limit.ts:42

Maximum concurrent in-flight HTTP requests. Default: 4.


maxDelayMs?

optional maxDelayMs?: number

Defined in: client/src/core/rate-limit.ts:48

Cap in ms for the exponential-backoff fallback. Default: 8000.


maxRetries?

optional maxRetries?: number

Defined in: client/src/core/rate-limit.ts:44

Number of retries on 429 (so total attempts = retries + 1). Default: 2.


maxRetryAfterMs?

optional maxRetryAfterMs?: number

Defined in: client/src/core/rate-limit.ts:54

Cap in ms for honoring a server-supplied Retry-After. If the header asks for a wait longer than this, the gate gives up and rethrows the 429 rather than stalling the caller. Default: 60_000 (60 s).


onRetry?

optional onRetry?: (info) => void

Defined in: client/src/core/rate-limit.ts:56

Hook invoked on each retry attempt.

Parameters

info

RetryInfo

Returns

void


random?

optional random?: () => number

Defined in: client/src/core/rate-limit.ts:60

RNG for jitter, in [0, 1). Overridable for tests.

Returns

number


sleep?

optional sleep?: (ms) => Promise<void>

Defined in: client/src/core/rate-limit.ts:58

Sleep function (overridable for tests).

Parameters

ms

number

Returns

Promise<void>