Client

Rate limiting

Built-in interceptor for global and per-route request rate limits.

accorudo/client ships a built-in interceptor that throttles requests using p-throttle. Calls beyond the limit are queued and delayed rather than rejected.

Usage

import { createRateLimiterInterceptor } from "accorudo/client";

mainApi.use(
  createRateLimiterInterceptor({
    global: { limit: 60, interval: 60_000 }, // 60 requests per minute, across all endpoints
    routes: {
      "/widget/:id/media": { limit: 5, interval: 60_000 }, // 5 uploads per minute
    },
  })
);

Config

type RateLimitWindow = {
  limit: number;     // max calls within `interval`
  interval: number;  // window size, in milliseconds
  strict?: boolean;  // throttle each call individually instead of using a windowed approach; default false
};

type RateLimiterConfig = {
  global?: RateLimitWindow;
  routes?: Partial<Record<string, RateLimitWindow>>;
};
  • global applies to every request, regardless of endpoint.
  • routes keys are matched against the interceptor's endpoint (the route template as declared, e.g. "/widget/:id" — not the resolved path), so a limit applies to a route no matter which path params a given call uses.
  • strict is forwarded to p-throttle's strict option: the default windowed algorithm limits the total calls per interval window, while strict spaces out every call individually.

Combining global and per-route limits

When both a global limit and a matching per-route limit are configured, a call proceeds only once both admit it.

Copyright © 2026