@agorio/sdk • Docs
Interface: TokenBucketOptions
HTTP rate-limit primitive — token-bucket per host, drop-in over a fetch-shaped function.
const bucket = new TokenBucket({ capacity: 2, refillPerSec: 2 }); const limited = withRateLimit(globalThis.fetch, bucket);
For multi-host workloads pass a factory keyed on URL origin:
const limited = withRateLimit(globalThis.fetch, ({ origin }) => origin.endsWith(‘.myshopify.com’) ? new TokenBucket({ capacity: 2, refillPerSec: 2 }) : new TokenBucket({ capacity: 10, refillPerSec: 10 }) );
Bucket factories are memoized by origin so each host gets one bucket for the lifetime of the wrapped fetch.
Properties
capacity
capacity:
number
Maximum tokens the bucket can hold (burst size).
Defined in
src/http/rate-limit.ts:22
now()?
optionalnow: () =>number
Optional injected clock for tests. Default: Date.now
Returns
number
Defined in
src/http/rate-limit.ts:26
refillPerSec
refillPerSec:
number
Tokens added per second.
Defined in
src/http/rate-limit.ts:24