Packages@g14o/ratelimit
Overview
Framework-agnostic rate limiting with Upstash Redis for any Request/Response runtime.
Framework-agnostic rate limiting with Upstash Redis. Works with any runtime that uses Web Request / Response (Next.js App Router, etc.).
RateLimitClient and RateLimitOptions accept optional type parameters for framework-specific request/response types (defaults: Request / Response).
Install
pnpm add @g14o/ratelimit @upstash/redis @upstash/ratelimitPeers are optional in package.json metadata for metadata-only installs; add both Upstash packages when using Redis-backed limits in production.
Quick start
import { createRateLimit } from "@g14o/ratelimit";
import { logger } from "@/lib/logger";
export const { withRateLimit, checkRateLimit, withUserRateLimit } =
createRateLimit({
redis: {
url: process.env.UPSTASH_REDIS_REST_URL!,
token: process.env.UPSTASH_REDIS_REST_TOKEN!,
},
logger,
});Learn more
- Setup — built-in tier defaults, custom tiers, build vs runtime
- Route handlers & middleware —
withRateLimit, per-user limits - API reference — types and
tokenConfigSnapshot
Import paths
| Use case | Import |
|---|---|
| Rate limit factory | import { createRateLimit } from "@g14o/ratelimit" |
| Lifecycle hooks | import type { RateLimitHooks } from "@g14o/ratelimit" |
| Custom store helpers | import { createStore, defineStore } from "@g14o/ratelimit" |
| In-memory store | import { memoryStore } from "@g14o/ratelimit/memory" |
| Upstash store | import { upstashStore } from "@g14o/ratelimit/upstash" |
| Redis store (node-redis / ioredis) | import { redisStore } from "@g14o/ratelimit/redis" |
| Redis / env helpers | import { createRedisClient, isBuildLikePhase } from "@g14o/ratelimit/config" |
Next.js alternative
For NextRequest / NextResponse types, use @g14o/ratelimit-nextjs.
pnpm add @g14o/ratelimit-nextjs @upstash/redis @upstash/ratelimit nextExpress alternative
For Express middleware and route handlers, use @g14o/ratelimit-express.
pnpm add @g14o/ratelimit-express @upstash/redis @upstash/ratelimit expressHono alternative
For Hono middleware and route handlers, use @g14o/ratelimit-hono.
pnpm add @g14o/ratelimit-hono @upstash/redis @upstash/ratelimit hono