UpstashRedisRateLimiter is the Rate Limit component’s serverless backend. It builds on @upstash/ratelimit and Upstash Redis over HTTP REST to enforce distributed limits across instances and edge functions, with no shared in-memory state. It implements the framework’s IRateLimiter interface, so the calling code is identical to any other backend.
What the limiter gives you
Counters live in Upstash Redis, so one limit holds across every instance and region. The HTTP REST transport works in edge functions and short-lived runtimes. You pick the limiting algorithm with a single option: fixed window, sliding window, or token bucket. Upstash rate-limit analytics are on by default, so the dashboard has data to show. And the interface is the sameIRateLimiter as the other backends: check, isLimited, reset, and getCount.
Installation
UpstashRedisRateLimiter ships with @talosjs/rate-limit and depends on the Upstash rate-limit and Redis clients.
Environment variables
url, token), which take precedence over the environment. They are validated when the limiter is constructed, so misconfiguration fails fast.
Options
UpstashRedisRateLimiter accepts an options object as its second constructor argument:
Algorithms
Thealgorithm option is a tagged union. Pick one and supply its parameters:
window and interval are Upstash Duration strings such as "60 s", "1 m", or "1 h". The default is a sliding window of 120 requests per 60 seconds.
How it works
check(key) calls the underlying limiter and normalizes the result into a RateLimitResultType:
Usage
Key the limiter by whatever identifies the caller: an IP, a user id, or an API key.Use in the app
In an@talosjs/app application, pass UpstashRedisRateLimiter to the rateLimiter slot of your App config. The framework registers it and exposes it as the "rateLimiter" container constant.
check() yourself. When a request is over the limit it short-circuits with a 429 Too Many Requests and sets the standard headers automatically:
rateLimiter slot instead. Set RATE_LIMIT_UPSTASH_REDIS_URL and RATE_LIMIT_UPSTASH_REDIS_TOKEN in your .env.yml (or environment).
Exceptions
UpstashRedisRateLimiter throws RateLimitException (HTTP 429) on misconfiguration or operation failures, carrying a machine-readable key.
Choosing limits well
Match the algorithm to the case: sliding window for smooth API limits, fixed window for simple per-minute caps, and token bucket where you want to tolerate bursts. Rate-limit by user id on authenticated routes and by IP on public ones, and give each limiter a distinctprefix. Surface resetAt to clients through a Retry-After header alongside the 429 so they back off correctly. Keep the REST URL and token in .env rather than in source. When several limiters share one Upstash database, a distinct prefix/namespace per limiter keeps their counters from colliding.
See the Rate Limit component for the full interface and the other backends.