Rate limiting
A fixed-window limiter, counted per key per binding, on one node.
Configuration
"ratelimiters": [{ "binding": "API", "limit": 100, "period": 60 }]
limit and period (seconds) are fixed in sproutboat.jsonc — they cannot be changed per call.
Usage
const { success, resetAt } = env.API.limit({ key: clientIp });
if (!success) {
const retryAfter = Math.ceil((resetAt - Date.now()) / 1000);
return new Response("slow down", { status: 429, headers: { "retry-after": String(retryAfter) } });
}
Method
| Method | Signature | Returns |
|---|---|---|
limit |
({ key: string }) |
{ success: boolean, resetAt: number } — resetAt is epoch milliseconds |