Rate limits without running Redis.
Define a bucket once, check any key on every request, and get told when to retry.
coss.risk.limit()
const { } = await ..({
: "password_reset",
: .,
});
if ( && !.) {
const = .((. ?? 0) / 1000);
throw new (`Try again in ${} seconds.`);
}password_reset
5 per hour, per address
{
"allowed": true,
"limit": 5,
"remaining": 4,
"reset_ms": 720000,
"retry_after_ms": null,
"degraded": false
}Bursts, then a steady rate
Every key gets burst tokens that refill at the bucket's rate, using GCRA, the same engine that limits coss.com's own API.
Read the docssearchlimit: 10, period_seconds: 60, burst: 30
- At once30
- Minute 110
- Minute 210
- Minute 310
Limit by anything
A user, an email address or an IP address, up to 512 characters. coss.com stores only a keyed hash of it.
Read the docsKeys
| Limit by | You send | coss.com stores |
|---|---|---|
| User | user_8fK2a | 9f2c…a17e |
| ada@example.com | 41be…07d3 | |
| IP address | 203.0.113.7 | c60a…e92b |
apiburst: 100
| Request | cost | remaining | allowed |
|---|---|---|---|
| search | 1 | 99 | |
| export | 20 | 79 | |
| full_backup | 100 | 79 |
Heavier requests cost more
Take several tokens at once for an export or a batch. A denied request takes nothing.
Read the docsWhile coss.com can't count
| on_failure | allowed | degraded |
|---|---|---|
| allow | true | |
| deny | true |
You choose how it fails
Keep your product up, or protect what's expensive, per bucket. The answer tells you either way.
Read the docsLimits
- Algorithm
- GCRA
- Buckets per environment
- 100
- Bucket names
- 1–64 characters, unique, fixed
- Period
- 1 second to 1 day
- Tokens per bucket
- up to 1,000,000
- Key length
- up to 512 characters, stored hashed
- Failure mode
- allow (default) or deny
- Checks per API key
- 500 per second, bursts of 1,000
- Denied check
- 200 with allowed false
Questions
Define a bucket with coss.risk.limitBuckets.create(), such as 5 password resets per hour, then call coss.risk.limit() with the bucket and a key on every request. coss.com counts in its own store and answers whether the request is allowed and when to retry.
GCRA, the generic cell rate algorithm, the same engine coss.com limits its own API with. Each key gets a bucket of burst tokens that refills at limit per period, so a key can make a burst of requests at once and then continues at the steady rate.
Each bucket chooses. With on_failure set to allow, the default, checks let requests through; with deny, they refuse them. Either way the answer carries degraded true, so you can tell.
Yes. The key is any string up to 512 characters that identifies who or what you limit, such as a user id, an email address or an IP address. coss.com keeps only a keyed hash of it, never the key itself.
No. The SDK retries network errors with the same Idempotency-Key, and a retried check is charged once.
Yes. Rate limiting is one of Risk's building blocks, on the same API key and SDK. Buckets are managed under Risk in the dashboard or with coss.risk.limitBuckets.
Works with
On the same key, SDK, webhooks and logs: nothing more to set up.
Compared
Start with Rate limiting today.
Development keys record every request and event and deliver nothing.