You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Per-API-key rate limiting for the public API, backed by a Redis token bucket. Protects the API from abusive clients without needing per-endpoint logic.
Architecture
flowchart LR
A[Client Request] --> B[RateLimitMiddleware]
B --> C{Redis reachable?}
C -->|Yes| D[Check token bucket]
C -->|No| E[Fail open, log warning]
D -->|Under limit| F[Handler]
D -->|Over limit| G[429 Too Many Requests]
E --> F
%% Generated 2026-06-20 from: src/middleware/rate_limit.py
Loading
Key Components
RateLimitMiddleware
Location:src/middleware/rate_limit.py:12
Purpose: Intercepts every request, checks the caller's token bucket in Redis before passing through to the handler.
Key details: Fails open (lets the request through) if Redis is unreachable, rather than 500ing — see Known Issues for why this was changed.
Purpose: Defines the default requests-per-minute and burst size applied to every key.
Key details: Per-key overrides live in Redis under ratelimit:override:{key}, checked before falling back to DEFAULT_BUCKET.
API / Endpoints
Method
Path
Purpose
Auth
GET
/internal/ratelimit/status/{key}
Current bucket state for a key
Internal only
PUT
/internal/ratelimit/override/{key}
Set a custom limit for a key
Internal only
Configuration
Variable
Purpose
Default
Required
RATE_LIMIT_ENABLED
Kill switch for the whole feature
true
No
RATE_LIMIT_REDIS_URL
Redis instance backing the token buckets
redis://localhost:6379/2
No
How to Use
Set a per-customer override: PUT /internal/ratelimit/override/{key} with {"requests_per_minute": 500, "burst": 50}.
Troubleshooting
Symptom
Likely Cause
Fix
All requests suddenly unlimited
Redis unreachable, middleware failed open
Check Redis health; this is deliberate degraded behavior, not a bug — see Known Issues
A specific customer still rate-limited after override
Override key mismatch
Confirm the key matches exactly what RateLimitMiddleware reads at src/middleware/rate_limit.py:12 — it's the API key, not the customer ID
Known Issues
Fails open when Redis is down, meaning rate limiting is fully disabled during a Redis outage. This is intentional (⚠️ UNVERIFIED: assumed acceptable tradeoff — not confirmed with product) but means an outage window has zero protection.