Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/AmeyaBorkar/throttlekit/llms.txt

Use this file to discover all available pages before exploring further.

ThrottleKit gives you rate limiting you can reason about precisely — from a 169 ns in-process checkSync call to a globally coordinated fleet with a machine-checked overshoot bound. Eight algorithms, six storage backends, and 13 framework adapters share one core and zero runtime dependencies.

Quickstart

Get a working rate limiter in under two minutes with in-memory GCRA.

Installation

Install ThrottleKit and choose the peer dependencies you need.

Algorithms

GCRA, token bucket, fixed/sliding window, leaky bucket, quota, and more.

Storage Backends

In-memory, Redis, Postgres, DynamoDB, Deno KV, and Cloudflare — bit-identical decisions on all.

Framework Adapters

Drop-in middleware for Express, Fastify, Hono, Next.js, tRPC, gRPC, and more.

Distributed Leasing

GALE: TLA⁺-verified fleet-size-independent overshoot bound for high-throughput fleets.

Unified Admission

Compose rate, concurrency, and cost into a single decision — including LLM token budgets.

API Reference

Complete reference for every export, type signature, and option.

Why ThrottleKit

Most rate limiters just count requests. ThrottleKit governs three axes — rate, concurrency, and cost — and gives you a provable bound on each.

169 ns Sync API

checkSync returns a full Decision in 169 ns with ~0 allocations. A true synchronous hot path, no await needed.

Proven Bit-Identical

The same GCRA runs in JS and Redis Lua. A conformance suite with thousands of generated timelines proves both paths agree exactly.

Zero Runtime Deps

24 tree-shakeable subpath exports. Install only the peer deps your stores and adapters actually need.

Get Started in 30 Seconds

import { rateLimit, gcra } from "throttlekit";

const limiter = rateLimit({
  strategy: gcra({ limit: 100, periodMs: 60_000, burst: 20 }),
});

const decision = limiter.checkSync(userId);
if (!decision.allowed) {
  throw new Error(`Rate limited — retry in ${decision.retryAfterMs}ms`);
}
Every check returns a Decision with { allowed, limit, remaining, resetAt, retryAfterMs }. No magic, no surprises.
1

Install

npm install throttlekit
2

Create a limiter

Pick a strategy and call rateLimit(). The default in-memory store requires no infrastructure.
3

Check every request

Call limiter.checkSync(key) on hot synchronous paths or await limiter.check(key) anywhere else.
4

Go distributed

Swap in a RedisStore, PostgresStore, or use twoTier() for leased local-first limiting with a bounded global overshoot.
ThrottleKit requires Node 18+ for the in-memory and fetch-based paths. Redis, Postgres, DynamoDB, Deno KV, and Cloudflare adapters require their respective optional peer dependencies.

Build docs developers (and LLMs) love