@upstash/ratelimit
@upstash/redis

Rate limiting is a technique used to control the rate of traffic sent or received by a network.

Code

import { Ratelimit } from "@upstash/ratelimit";
import { Redis } from "@upstash/redis";

const ratelimit = new Ratelimit({
  redis: Redis.fromEnv(),
  limiter: Ratelimit.fixedWindow(10, "30s"),
});

await ratelimit.limit(ip);

Demo

SuccessLimitRemainingReset
----

Links

Source CodeRatelimit SDKDocumentation