/agentic-awesome-skills:upstash-ratelimitfrom agentic-awesome-skills
Adds distributed rate limiting to API routes, middleware, and edge functions using @upstash/ratelimit with sliding window, fixed window, and token bucket algorithms backed by Upstash Redis.
Ships in agentic-awesome-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
@upstash/ratelimit implements distributed rate limiting on top of Upstash
Redis. Because state lives in Redis, every instance of a serverless function
or edge worker shares the same counters, which an in-memory limiter cannot
do. It ships three algorithms (fixed window, sliding window, token bucket),
per-identifier keys, optional in-memory blocking of already-limited
identifiers, and optional analytics.
429 Too Many Requests.api-rate-limit-handler.npm install @upstash/ratelimit @upstash/redis
Set UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN in the environment.
import { Ratelimit } from "@upstash/ratelimit";
import { Redis } from "@upstash/redis";
export const ratelimit = new Ratelimit({
redis: Redis.fromEnv(),
limiter: Ratelimit.slidingWindow(10, "10 s"), // 10 requests per 10 seconds
prefix: "rl:api",
analytics: true,
});
Constructing the limiter at module scope lets the built-in ephemeral cache short-circuit blocked identifiers without a Redis call.
limit() with a stable identifierconst { success, limit, remaining, reset, pending } = await ratelimit.limit(userId);
success is false when the identifier is over its limit. reset is a Unix
timestamp in milliseconds. pending is a promise for background work
(analytics, multi-region sync); await it or pass it to waitUntil on edge
runtimes so the function is not frozen before it completes.
import { Ratelimit } from "@upstash/ratelimit";
import { Redis } from "@upstash/redis";
import { NextResponse, type NextRequest } from "next/server";
const ratelimit = new Ratelimit({
redis: Redis.fromEnv(),
limiter: Ratelimit.slidingWindow(20, "1 m"),
});
export async function middleware(request: NextRequest) {
// Conservative shared bucket until an authenticated principal or a platform-verified
// client address adapter is integrated. Never trust a caller-supplied forwarding header.
const identifier = "anonymous-global";
const { success, limit, remaining, reset, pending } = await ratelimit.limit(identifier);
await pending; // Or pass to the deployment platform’s verified waitUntil API.
if (!success) {
return new NextResponse("Too Many Requests", {
status: 429,
headers: {
"X-RateLimit-Limit": String(limit),
"X-RateLimit-Remaining": String(remaining),
"X-RateLimit-Reset": String(reset),
"Retry-After": String(Math.max(0, Math.ceil((reset - Date.now()) / 1000))),
},
});
}
return NextResponse.next();
}
export const config = { matcher: "/api/:path*" };
The shared anonymous bucket protects against spoofed identifiers but shares quota among callers. For per-user limits, use a server-verified session identity; for per-IP limits, use the deployment platform's trusted address API after verifying proxy overwrite and direct-origin restrictions.
const limiters = {
free: new Ratelimit({
redis: Redis.fromEnv(),
prefix: "rl:free",
limiter: Ratelimit.tokenBucket(5, "10 s", 10), // refill 5 per 10 s, burst 10
}),
pro: new Ratelimit({
redis: Redis.fromEnv(),
prefix: "rl:pro",
limiter: Ratelimit.tokenBucket(50, "10 s", 100),
}),
};
const { success } = await limiters[plan].limit(apiKey);
prefix per endpoint or plan so limits do not collide.Retry-After and X-RateLimit-* headers with 429 responses.slidingWindow for most APIs; use tokenBucket when short bursts
are acceptable; use fixedWindow when the lowest Redis cost matters.Ratelimit inside the request handler.pending completing on its own in edge runtimes.x-forwarded-for without validating it is set by
your proxy; clients can spoof it otherwise.limit() call is at least one HTTP round trip to Redis, so it adds
latency to every request it guards.MultiRegionRatelimit trades strict accuracy for lower latency and does
not support the token bucket algorithm.timeout (5 s) lets requests through
(reason: "timeout"); this fails open, not closed.Use a server-verified plan and identifier; do not send raw API keys as Redis identifiers. Hash a stable key identifier where appropriate, review analytics disclosure/retention and choose an explicit timeout/error policy for security-sensitive endpoints rather than assuming fail-open is acceptable.
undefined or a fresh random value.pending to waitUntil (ctx.waitUntil(pending)) so
the background request is not cancelled when the response is sent.@upstash-redis - The client this package uses for storage.@api-rate-limit-handler - Client-side backoff and retry when you are the
one being rate limited.@upstash-qstash - Queue and smooth traffic to downstream services instead
of rejecting it.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
upstash, rate-limiting, redis, serverless, edge, middleware, 429
npx claudepluginhub krishnakanthb13/antigravity-awesome-skills --plugin agentic-awesome-skills3 plugins in 2 repositories ship this exact skill · first indexed Oct 23, 2026
2,799 skills in this plugin
/007Security audit, hardening, threat modeling (STRIDE/PASTA), Red/Blue Team, OWASP checks, code review, incident response, and infrastructure security for any project./00-andruia-consultantUsar al iniciar o mejorar un proyecto de IA: diagnostica código y restricciones, propone skills existentes y redacta tareas y un plan de implementación en español./10-andruia-skill-smithUsar para crear o mejorar una skill de Andru.ia: define entradas y resultados, redacta SKILL.md con ejemplos y límites, valida la estructura y prepara una PR.Other plugins' skills for the same job