Install this version
v0.1.1rune add @rune/rate-limit@0.1.1Manifest hash sha256:40d8dd77e9dca8d9e2a471a5d9149f361fd2f102971da141d6fcde546175ef46
runebook · rune
Bounded token-bucket rate limiting for web routes, commands, and events.
Library Rune. Boilerplate code consumed by other Runes — the host never loads it directly. Install it as a dependency of your own Rune and import from it.
rune add @rune/rate-limit@0.1.1Manifest hash sha256:40d8dd77e9dca8d9e2a471a5d9149f361fd2f102971da141d6fcde546175ef46
The author declares these capabilities as a guide. Rune scripts run with server access.
No capabilities declared by the author. Rune scripts run with server access.
A per-key token bucket for commands, API routes, and other requests.
rune add @rune/rate-limit
import { createRateLimiter } from "@rune/rate-limit";
const limiter = createRateLimiter({ capacity: 10, intervalMs: 60_000 });
function checkLimit(accountId: string): Response | undefined {
const decision = limiter.consume(accountId);
if (!decision.allowed) {
return new Response("Too many requests", {
status: 429,
headers: { "Retry-After": String(Math.ceil(decision.retryAfterMs / 1000)) },
});
}
}
Each identity can burst up to capacity. Tokens refill continuously, with
a full refill taking intervalMs. consume(key, cost = 1) returns
allowed, remaining, and retryAfterMs. Set a higher cost for heavier
requests, up to the bucket capacity.
The default budget is 10,000 keys. sweep() discards fully refilled entries.
When the budget is exhausted, new keys are rejected until space frees up.
Keep the limiter alive across requests and use a trusted identity such as
an account ID. Use a shared limiter if replicas need one global quota.