Rate limiting
Definition
A rate limit caps how many requests the gateway admits in any trailing window of time. It is configured as requests per window_sec seconds.
Function
Rate limits protect a gateway, and the providers behind it, from bursts and runaway clients. They cap request rate; budgets cap spend. A request must satisfy both.
Levels
- Gateway-level — caps the combined rate of every token of the gateway.
- Token-level — caps the rate of one authentication token.
A request is admitted only when every applicable level has capacity. The gateway-level limit is checked first.
Rules and facts
- A gateway without a
rate_limitobject is unlimited. - Only admitted requests count against the window.
- Limits are counted per gateway node, in node memory.
- Every response carries
X-RateLimit-LimitandX-RateLimit-Remaining. A refusal is429 rate_limitedwith aRetry-Afterheader that gives the time until a request would be admitted again. - Refusals are also counted per day and surface as a
rate_limitalert in the notifications center.
Window semantics
The window is a trailing window. Small limits are counted exactly; large limits are approximated from the previous and the current window. The exact cut-over, the approximation error and the behaviour under contention are described in Rate limiting.
See also
- Rate limiting — field defaults, headers and configuration.
- Configuration reference — Rate limiting.