Reliable Rate Limiting for Modern Apps

oss-ratelimit provides production-ready, flexible rate limiting for Node.js & Next.js, built with performance and developer experience in mind.

 
import { Ratelimit, fixedWindow, getRedisClient } from 'oss-ratelimit';
 
// 1. Prepare Redis Client (using environment variables is recommended)
// Option A: Use the library's helper (handles connection logic)
const redisClientPromise = getRedisClient({
  url: process.env.RATELIMIT_REDIS_URL || 'redis://localhost:6379',
});
const ratelimit = new Ratelimit({
  redis: redis,
  limiter: Ratelimit.slidingWindow(10, "10 s"),
  analytics: true,
});
 
async function handler(req) {
  const identifier = /* user ID or IP */;
  const { success } = await ratelimit.limit(identifier);
 
  if (!success) {
    return new Response("Rate limit exceeded", { status: 429 });
  }
  return new Response("Success!");
}
  

Powerful Features, Simple API

Everything you need to protect your applications from abuse and ensure availability.

Explore the Documentation

Find detailed guides, API references, and examples to integrate oss-ratelimit quickly.

Read the Docs