Rate Limits
Guides, route-group overviews, and live schema entry points for the Plexichat backend.
Rate limits
Plexichat applies multiple layers of request protection to keep the API stable under normal traffic and abuse conditions. The values below are configurable defaults; the single source of truth for documented defaults is src/config_defaults.py (rate_limiting), which is merged into runtime config at startup. Enforcement reads from runtime config (src/core/ratelimit/*), and src/core/ratelimit/config.py fallbacks are kept aligned with config_defaults.py. Operators may tune any limit in config.yaml.
Default limits
Configure limits under rate_limiting in config.yaml. The server reloads them at startup. If the config key is missing, the fallback values in src/core/ratelimit/config.py apply.
Global limits
Global limits apply to all requests regardless of source. They act as a backstop against total server overload.
- 25000 requests per 60 seconds, burst 5000
rate_limiting:
global:
requests: 25000
window_seconds: 60.0
burst: 5000
Per-user limits
Per-user limits apply to each authenticated user.
- 10000 requests per 60 seconds, burst 2500
- 300000 requests per hour
- 5000000 requests per day
rate_limiting:
user:
requests: 10000
window_seconds: 60.0
burst: 2500
hourly_limit: 300000
daily_limit: 5000000
Per-IP limits
Per-IP limits apply to each client IP address regardless of authentication. They catch unauthenticated abuse and credential-stuffing attempts.
- 5000 requests per 60 seconds, burst 1500
- 150000 requests per hour
- 1000000 requests per day
rate_limiting:
ip:
requests: 5000
window_seconds: 60.0
burst: 1500
hourly_limit: 150000
daily_limit: 1000000
Configure api.trusted_proxies and api.trust_x_forwarded_for when you run behind a reverse proxy. Otherwise all traffic appears to come from the proxy IP and shares a single bucket. See API and server configuration.
Multipliers and bypass
rate_limiting:
bot_multiplier: 1.5
webhook_multiplier: 1.0
admin_bypass: true
internal_bypass: true
| Field | Default | Description |
|---|---|---|
bot_multiplier |
1.5 |
Multiplier for bot accounts. A bot gets 15000 requests per minute when users get 10000. |
webhook_multiplier |
1.0 |
Multiplier for webhook delivery requests. |
admin_bypass |
true |
When true, admins bypass per-user limits. Global and IP limits still apply. |
internal_bypass |
true |
When true, internal service-to-service requests bypass limits. |
The server also supports a bypass secret in the X-RateLimit-Bypass header. The value is compared with hmac.compare_digest on UTF-8 encodings to avoid timing attacks and 500 errors on malformed headers. See src/api/middleware/rate_limiting.py and src/core/ratelimit/middleware.py.
Do not use stale values such as bot_multiplier: 0.5 or webhook_multiplier: 2.0. A multiplier below 1.0 restricts bots below user levels, which you rarely want.
Route-level limits
The code defines stricter limits for sensitive or high-volume routes in addition to the global, user, and IP limits. See src/core/ratelimit/config.py (DEFAULT_ROUTE_LIMITS).
Common examples:
- Auth endpoints —
POST /auth/login(5 per 60s),POST /auth/register(3 per 60s),POST /auth/2fa/*(5 per 60s). Seesrc/core/ratelimit/middleware.py. - Message send —
POST /channels/{id}/messages(10 per 5s, burst 5, wired torate_limiting.routes.send_message). - Media uploads —
POST /media/upload(10 per 60s, hourly 100). - Webhooks —
POST /webhooks/{id}/{token}(5 per 2s). - Static client —
static_client:html(300 per 60s) andstatic_client:assets(5000 per 60s), wired throughsrc/config_defaults.py.
Use get_route_config(route) and get_default_config() from src/core/ratelimit/config.py to inspect the active route config.
How the middleware works
Plexichat enforces limits in ASGI middleware (src/core/ratelimit/middleware.py and src/api/middleware/rate_limiting.py). For each HTTP request the middleware:
- Extracts the client IP with
src/utils/net.py:get_client_ip()(trusted-proxy aware). - Extracts user info (
user_id,is_bot,is_admin,is_internal) fromrequest.state. - Resolves a route pattern with
extract_route_info()(src/core/ratelimit/middleware.py). - Calls
ratelimit.check_rate_limit()and returns429with rate-limit headers when the check fails.
OPTIONS requests (CORS preflight) and paths in exclude_paths are not rate-limited.
What clients should expect
- Limits can be applied globally, per user, per IP, or per route and resource.
- The server can tune any limit away from the code defaults in
src/config_defaults.py. - Bots and feature tiers may receive different multipliers depending on server policy. See
src/core/ratelimit/config.py. - Admin and internal bypass behavior is configurable. Do not assume it is available.
Responses and headers
Rate-limited requests return 429 Too Many Requests with standard rate-limit headers and retry metadata in the response body. See src/core/ratelimit/middleware.py.
On success, the middleware can include rate-limit headers when include_headers_on_success is true (the default in src/api/middleware/rate_limiting.py).
Client recommendations
- Back off on
429instead of retrying immediately. Use exponential backoff. - Use pagination and caching to reduce repeated reads.
- Batch operations where the API supports it.
- Keep message send loops and reaction spam under control.
- Prefer gateway events over high-frequency polling.