rate-limit
Implement or audit Upstash Redis rate limits with trusted user, tenant, API-key, or IP identifiers, 429 headers, and outage behavior. Use when protecting Next.js routes from abuse or cost.
How do I install this agent skill?
npx skills add https://github.com/tushaarmehtaa/tushar-skills --skill rate-limitIs this agent skill safe to install?
- Gen Agent Trust Hubpass
The skill provides safe and standard instructions for implementing rate limiting in a Next.js application using Upstash Redis. It follows security best practices such as failing open if the database is unreachable and including the Retry-After header for 429 responses.
- Socketpass
No alerts
- Snykpass
Risk: LOW · No issues
What does this agent skill do?
Rate limiting with Upstash
Rate limits are one layer of abuse and cost control. Design policy before wiring middleware.
For raw @upstash/ratelimit API shapes, use Upstash's official agent skill (upstash-ratelimit-js) if installed, otherwise the Upstash ratelimit features docs. SDK defaults below were checked on 2026-11-04 against that page and @upstash/ratelimit 2.2.0. Re-check them if that date is more than about 90 days old or the installed version differs.
Workflow
- Detect Next.js/runtime/version, deployed proxy/CDN, auth/API-key model, installed Upstash versions, protected routes, operation cost, existing quotas, and whether middleware/proxy already touches the request.
- Define a policy table per route class: identifier, algorithm/window/burst, cost weight, user tier, response behavior, and store-outage behavior. Ask only when the threat/cost tradeoff cannot be inferred. Give each tier its own limiter and prefix. Use
dynamicLimits: truewithsetDynamicLimit()only when a limit must change at runtime without a redeploy, such as load shedding; it supports single-regionfixedWindow,slidingWindow, andtokenBucketonly. - Prefer authenticated user, API key, or tenant+user identifiers. Use IP only for anonymous traffic and only from a deployment-provided trusted source. Never trust arbitrary
x-forwarded-forfrom the public internet; configure trusted proxy depth/platform headers. Do not collapse unknown clients to127.0.0.1. - Namespace by environment and route/policy. Do not apply blanket middleware and a per-route limiter to the same request unless deliberate layered limits use different keys.
- Configure explicit Upstash timeout and logging/metrics. Fail-open is the default unless you choose otherwise: when Redis does not answer within
timeout(5 s if unset),limit()returns success and says so inreason. Readreasonand choose outage behavior by endpoint:- low-risk availability paths may fail open with degraded telemetry;
- authentication, high-cost generation, or abuse-sensitive paths may use a local emergency limit, queue, credit reservation, or fail closed with a clear temporary response.
- Return
429with a non-negativeRetry-Afterand consistent rate-limit headers. Add headers to successful responses where useful. Do not emit misleading zero limits during fail-open degradation. - For weighted work, consume tokens based on server-calculated batch/operation cost. Combine rate limits with body-size limits, concurrency controls, idempotency, budgets/credits, and provider quotas where relevant.
- Preserve async work such as analytics synchronization using the runtime’s
waitUntilmechanism when the SDK exposes a pending promise. - Create the limiter outside the request handler.
ephemeralCacheis on by default: blocked identifiers are denied from memory until reset, without a Redis call, withreason: "cacheBlock". That only works while the instance stays warm, and it also changes test results.
Verification
Use deterministic tests with an isolated key prefix and controllable clock/window where possible. Create a fresh limiter per test or pass ephemeralCache: false, so a block cached by one case cannot decide the next. Simulate a Redis timeout and assert each endpoint's handling of the timeout reason. Test allowed/blocked/reset behavior, route isolation, authenticated and anonymous keys, spoofed forwarding headers, paid/free policies, concurrency, weighted requests, store timeout/outage behavior, and duplicate middleware avoidance. Run repository lint/type/test/build and inspect Upstash analytics only when enabled.
Output
Report the policy table, identifier trust model, files/env names changed, outage behavior, response headers, layered controls, automated test evidence, and remaining Upstash/deployment configuration.
How can the creator link this skill?
Add the canonical catalog link to the repository README so users can inspect current installs and available audits. The publishing guide covers the complete discovery path.
<a href="https://skillzs.dev/skills/tushaarmehtaa/tushar-skills/rate-limit">View rate-limit on skillZs</a>