Skip to main content
TrustGate ships two Redis-backed quota policies: 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.
SettingTypeNotes
limitintMax requests per window. Required.
windowdurationGo duration string: 30s, 1m, 1h. Required.
retry_afterstringRetry-After value in seconds when limited (default 60).
group_by_headerstringOptional sub-partition key (e.g. X-User-Id).
Responses carry 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.
SettingTypeDefaultNotes
unitenumtokenstokens or dollars.
countingenumtotalWhich usage accrues: total, input, or output.
aggregateobjectSingle budget for the whole scope: { max, time_window }.
rulesarrayPer-model budgets: [{ model, max, time_window }] (most specific pattern wins).
behavior_on_exceededenumrejectreject, throttle, downgrade_model, or alert_only.
downgrade_tostringTarget model for downgrade_model (same provider).
stream_usage_injectionboolfalseRequest + inject usage on streams so accrual works on streaming responses.
count_cache_readsboolfalseInclude Anthropic cache-read input tokens in counted/costed usage.
custom_pricingmapPer-token USD rates by model pattern, consulted before the built-in table (for dollar budgets).
group_by_headerstringOptional sub-partition key.
Use either aggregate (one counter for the scope) or rules (per-model). Window values below 60s are raised to 60s.
For a stateless per-request price guard (rather than a running budget), see the cost cap policy.

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.