rate_limiter for request volume and
token_rate_limiter (“LLM Budget”) for token or dollar spend. Both follow their
policy scope — per consumer, or gateway-wide when global —
and accept a group_by_header to sub-partition the counter within that scope (e.g. per
end-user or tenant).
rate_limiter — request rate limiting
Counts requests in a sliding window. Runs at pre_request.
X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, and
(when limited) Retry-After.
token_rate_limiter — LLM Budget
Caps LLM usage by provider tokens or USD cost over time windows — the right control for
LLM cost, since a few large requests can cost more than many small ones. It checks the budget
at pre_request and accrues usage at post_response.
Use either
aggregate (one counter for the scope) or rules (per-model). Window
values below 60s are raised to 60s.
Choosing a scope
- Global policy → a gateway-wide ceiling protecting your upstream spend.
- Consumer-scoped policy → per-tenant quotas.
group_by_header→ fairness within a tenant (per end-user), without a policy per user.