Every rate limiter you have ever written counts something cheap: requests, logins, jobs. AI endpoints break that assumption. One request can cost forty tokens or forty thousand, and the difference is decided by the user's prompt, not by your code. A limiter that counts requests will happily let one account spend a month of margin in an afternoon.
The fix is not a stricter limiter. It is separating two jobs that a single counter was doing.
Requests and tokens are different limits
A request limiter protects your infrastructure: the queue, the connection pool, the upstream provider's per-minute quota. A token budget protects your money. They fail in different ways and they need different counters.
The request limiter is a burst control. Short window, high threshold, cheap to check, no database writes if you can avoid them.
The token budget is a spend control.…