g14o
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/ratelimit

Peers 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

Import paths

Use caseImport
Rate limit factoryimport { createRateLimit } from "@g14o/ratelimit"
Lifecycle hooksimport type { RateLimitHooks } from "@g14o/ratelimit"
Custom store helpersimport { createStore, defineStore } from "@g14o/ratelimit"
In-memory storeimport { memoryStore } from "@g14o/ratelimit/memory"
Upstash storeimport { upstashStore } from "@g14o/ratelimit/upstash"
Redis store (node-redis / ioredis)import { redisStore } from "@g14o/ratelimit/redis"
Redis / env helpersimport { 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 next

Express alternative

For Express middleware and route handlers, use @g14o/ratelimit-express.

pnpm add @g14o/ratelimit-express @upstash/redis @upstash/ratelimit express

Hono alternative

For Hono middleware and route handlers, use @g14o/ratelimit-hono.

pnpm add @g14o/ratelimit-hono @upstash/redis @upstash/ratelimit hono

On this page