Simple & Powerful Rate Limiting

bunlimit

A simple and powerful rate limiting library for Bun, using Bun's native Redis client. Inspired by Upstash Ratelimit.

import { RedisClient } from 'bun'
import { Ratelimit, fixedWindow } from 'bunlimit'

const redis = new RedisClient('redis://localhost:6379')

const ratelimit = new Ratelimit({
  redis,
  limiter: fixedWindow(10, 60), // 10 requests per 60 seconds
})

const { success, remaining } = await ratelimit.limit('user-123')

if (!success) {
  throw new Error('Rate limit exceeded')
}
🚀

Built for Bun

Uses Bun's native Redis client for maximum performance

🔌

Flexible Adapters

Support for ioredis, node-redis, and custom clients

🎯

Multiple Algorithms

Fixed Window, Sliding Window, and Token Bucket

📊

Analytics

Optional request tracking and analytics built-in

💪

Type-Safe

Full TypeScript support with complete type definitions

Simple API

Intuitive and easy to use, inspired by Upstash