Building a Distributed AI Rate Limiting Server with RPM and TPM Support Using Envoy Ratelimit
For conventional HTTP APIs, limiting the number of requests per minute is usually enough. For large language model APIs, however, limiting only the request count is far from sufficient: one request may consume only a few dozen tokens, while another may consume tens of thousands. Therefore, a practical AI gateway usually needs to support all of the following: RPM (Requests Per Minute): the number of requests per minute. TPM (Tokens Per Minute): the number of tokens per minute. Separate metering by tenant, API key, model, or plan. Shared quotas across multiple Envoy instances. Protection against quota multiplication caused by per-instance counters under high concurrency. Consistent 429 Too Many Requests responses and remaining-quota information. This article explains how to build a distributed AI rate limiting system with envoyproxy/ratelimit, Redis, and Envoy. ...