Rate limits
Rate limiting needs Redis (MNEMO_REDIS_URL). Without it no limits are
enforced. The Docker stack sets it by default.
Budgets
Each API key gets one token bucket per operation class. These are the base
budgets, which apply to a key on the free plan:
| Operation class | Matches | Limit | Burst |
|---|---|---|---|
recall | Paths starting with /recall, and /session/{id}/collapse | 600 / minute | 50 |
write | Other POST, PATCH, PUT, DELETE | 120 / minute | 20 |
turn | POST /session/{id}/turn | 600 / minute | 100 |
export | Paths starting with /export or /admin/export | 10 / day | |
admin | Other paths starting with /admin | 30 / minute | |
federation | Paths starting with /federation or /memory/federation | 60 / minute | |
other | Everything else (reads) | 600 / minute |
Where no burst is listed, the bucket holds the full budget of its window.
A key’s plan scales every budget: pro is 10 times the base and
enterprise is 100 times. The plan is set when the key is created.
There is also a concurrency cap per key: 10 requests in flight on free,
25 on pro, 100 on enterprise.
The budgets are constants in packages/server/src/ratelimit.ts. There is no
environment variable or database column to change them.
Response headers
When the limiter is active, responses carry:
X-RateLimit-Limit: 10
X-RateLimit-Remaining: 49
X-RateLimit-Reset: 1
Mnemosyne-Rate-Limit-Operation: recallX-RateLimit-Limitis the sustained rate in requests per second for the class (the daily cap forexport).X-RateLimit-Resetis the number of seconds until a token is available, not a Unix timestamp.
A 429 adds:
Retry-After: 1
Mnemosyne-Rate-Limited-Reason: request_rateThe reason is request_rate or concurrency (fleet_shed on a 503, see below). The error body carries the
same wait in retryAfterSeconds. See Error codes.
Load shedding
The server also watches the share of Postgres max_connections busy across
the cluster, read every 2 seconds. When it reaches a class’s threshold, a
request answers 503 with code fleet_shed, Retry-After: 5 and
Mnemosyne-Rate-Limited-Reason: fleet_shed. The threshold is 70% for
export, admin and federation, and 85% for every other class except
recall, which is never shed. Without a database the reading stays 0.
Fail-open behaviour
If Redis is configured but unreachable, the limiter fails open: requests are allowed and a warning is logged.