0029. Per-caller rate limits
- Status: Accepted, implemented, 2026-10-18.
Context
Section titled “Context”The production-readiness review (LEFTOVERS, 2026-10-16) found no throttle on
authenticated callers. Request size is bounded (MaxBytesReader, the RPC
message limit), rejected credentials are audited at most 10 a second, and
JWKS refetches are spaced, but a leaked or runaway API key could call the API
or push OTLP as fast as the server answers. Quotas
(0021 and §17 “Tenancy”) limit what a project
spends, not how fast one credential calls.
Decision
Section titled “Decision”- The unit is the caller, as authentication names it: an API key
(
key:<name>), a user (user:<provider>/<subject>), or, where authentication is optional, an anonymous caller told apart by source address. A project is not the unit: one leaked key should not throttle its project’s other keys, and one key can reach several projects. - Three classes, each with its own token bucket per caller:
api(RPCs and REST),ingest(OTLP exports, gRPC and HTTP) andguardrails(the agentgateway webhook and ExtMcp). A collector’s export rate says nothing about how fast it may call the API, and guardrail checks sit in the request path of live LLM traffic. - One token per HTTP request. A middleware after authentication takes
it, so a stream costs one call however many messages it carries, and a
request is never charged twice (the gate authenticates some requests more
than once, such as MCP tool listing).
/mcpitself is not counted: its tool calls re-enter the API in process and are counted there. Open routes (/healthz, gRPC health,/.well-known/*,/ui/) and requests whose credential was rejected are not counted. - The refusal is the caller’s protocol’s. The middleware stores it on
the request and the gate returns it from
authenticate, after the credential check:ResourceExhaustedwith aRetry-Afterheader (seconds) for Connect and gRPC, HTTP 429 withRetry-Afterfor REST, OTLP/HTTP and the guardrail webhook. - On by default while authentication is enabled, with generous limits,
per replica:
api500/s (burst 1000),ingestandguardrails2000/s (burst 4000). They stop a leaked or runaway credential, not real load. Without authentication every caller is the same anonymous owner, so the limits are off.rate_limits.disabled: trueturns them off;rate_limits.principalsoverrides classes per principal, andper_second: 0lifts a class’s limit. - Visible, not audited per call.
evalsi_rate_limited_total{class}counts refusals, and a warning is logged at most once a minute per caller and class. Refusals are not audit events: a flood of them would flood the audit log, which is what 0026 keeps for decisions.
Consequences
Section titled “Consequences”- Limits are per replica. N replicas allow up to N times the rate; a shared limit would need the store or the cluster on every request, which the ingest path cannot afford.
- Anonymous callers behind one proxy share its address’s buckets.
- Buckets live in memory and are forgotten once unused for 10 minutes and refilled, so a caller back later starts with the full bucket it would have had anyway; a slow rate cannot be reset by waiting just past the idle time.
- The settings are read at start, not on configuration reload.
- Clients see a new error. The Python client raises it as
ServerErrorwith coderesource_exhaustedand does not retry; callers that retry should honorRetry-After.