Rate limiter never recognizes Bearer API keys, so per-key limiting is dead code
Author: simpleqtCreated Sep 28, 2026Updated Sep 28, 2026
Labelstypes:bugai:pr-readyarea:apistatus:in-progress
Bug Description
_get_client_key in src/memos/api/middleware/rate_limit.py tries to rate-limit by API key when the Authorization header starts with krlk_:
auth_header = request.headers.get("Authorization", "")
if auth_header.startswith("krlk_"):
return f"ratelimit:key:{auth_header[:20]}"Real requests send Authorization: Bearer krlk_..., so the header never starts with krlk_ and this branch is unreachable. Every request — including ones carrying a valid API key — falls through to IP-based limiting, and behind a shared egress IP all keyed clients share one bucket.
Expected Behavior
Strip the Bearer scheme before checking the key prefix, so keyed requests get a per-key rate-limit bucket.
Environment
MemOS main, python 3.14.
Additional Context
Fix + red/green-verified tests ready; PR to follow referencing this issue.
Source: MemTensor/MemOS