Menu

Rate limiting AI endpoints when the unit isn't a request
📰

Rate limiting AI endpoints when the unit isn't a request

DEV Community: laravel·Keel·2 days ago
#kJF9U92K
#devtolaravel#devto#dev#estimate#tokens
Long article (759 words) — no AI summary yet.
Reading 0:00
15s threshold

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.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.