Skip to content
Preptima
hardDesignScenarioMidSeniorStaff

Rate-limit an LLM gateway where one request can cost a hundred times another.

Rate limiting an LLM gateway by request count fails because cost is tokens, and output tokens are unknown at admission. Budget tokens per tenant, reserve input plus expected output, settle against reported usage when the stream ends, cap concurrent streams, and cancel upstream on disconnect.

5 min readUpdated 2026-10-10

Answer

Short answer

Count tokens, not requests. Rate limiting an LLM gateway by request rate lets a tenant inside its limit send requests a hundred times more expensive than another's. Budget tokens per tenant per minute, reserve an estimate at admission (counted input plus expected output), settle against the usage the model reports when the response ends, and cap concurrent streams separately because a long generation holds capacity for its whole duration.

Was this answer helpful?

Likely follow-ups

  • Two models sit behind the gateway at very different prices per token. What unit does a tenant's budget use?
  • How do you estimate expected output for a route that has no history yet?
  • The upstream provider starts returning 429s while your own tenant budgets all have headroom. What does the gateway do with the waiting requests?
  • How would you enforce the token budget across a fleet of gateway instances when settlement happens minutes after admission?

Related questions