Per-User API Rate Limits in SaaS: How to Implement Them
What "per-user API rate limits" actually means
Per-user API rate limits control how many requests (or tokens, or dollars) an individual end user of your SaaS can consume in a given window, as opposed to one global limit shared by your entire application. If you're searching for this, you're probably trying to solve one of two problems: either your upstream provider (OpenAI, Anthropic, Stripe, etc.) is rate-limiting your whole account and one noisy user is starving everyone else, or you need to enforce your own plan-based limits so a free-tier user can't rack up the same API bill as a paying customer.
Both problems have the same underlying fix: move rate limiting from "per application" to "per identity." Instead of one bucket for all traffic, you create a bucket (or several buckets) keyed to each user, team, or API key, and you check that bucket before letting the request through.
Why application-wide limits aren't enough
Most third-party APIs — including LLM providers — give you rate limits at the account or API-key level: X requests per minute, Y tokens per minute, Z concurrent requests. That's fine until your SaaS has real users, because:
- One user running a batch job can exhaust your entire quota and lock out everyone else.
- You have no way to offer different limits to different plan tiers without building that logic yourself.
- Debugging "why did user X get a 429" becomes impossible if all traffic shares one counter.
- You can't bill or throttle based on actual per-user consumption if you never measured it per user.
The fix is architectural: every inbound request needs to be attributed to a user before it's allowed to consume shared capacity.
Common strategies for enforcing per-user limits
1. Token bucket or sliding window, keyed by user ID
The most common implementation pattern is a token bucket (or leaky bucket) stored in Redis, keyed by user_id or api_key_id. Each request decrements the bucket; the bucket refills at a fixed rate. This gives you burst tolerance plus a steady-state cap.
// pseudo-code, Redis-backed token bucket
async function checkLimit(userId, cost = 1) {
const key = `rl:${userId}`;
const bucket = await redis.get(key) ?? maxTokens;
if (bucket < cost) return { allowed: false };
await redis.decrby(key, cost);
return { allowed: true };
}
Refill is usually handled with a scheduled job or by computing elapsed time on read (lazy refill), which avoids running a cron job per user.
2. Tiered limits by plan
Once limits are keyed by user, tying the bucket size to plan tier is trivial — look up the plan, pick a maxTokens value, and apply it. This is how most SaaS products differentiate free, pro, and enterprise access without separate codepaths.
3. Separate limits for separate resources
Requests-per-minute and tokens-per-minute (or dollars-per-day) often need independent tracking, especially if you're proxying an LLM. A user might stay under their request quota while still burning through a token budget with a handful of huge prompts. Track both if cost varies per request.
4. 429 responses with Retry-After
Whatever you build, return a proper 429 Too Many Requests with a Retry-After header so client SDKs can back off correctly instead of hammering your API in a retry loop.
HTTP/1.1 429 Too Many Requests
Retry-After: 12
Content-Type: application/json
{"error": "rate_limit_exceeded", "retry_after": 12}
Building this yourself: what it actually takes
If you decide to roll your own per-user rate limiting on top of an LLM provider, the real work isn't the bucket algorithm — it's everything around it:
- A Redis or equivalent store with low-latency reads on the hot path
- Per-key configuration (plan tier, custom overrides for enterprise accounts)
- Usage metering that's accurate even under concurrent requests
- Dashboards so you (and your users) can see consumption before hitting a wall
- Handling streaming responses, where token cost isn't known until the stream completes
- Separate concurrency limits, since "requests per minute" doesn't stop ten simultaneous long-running calls
That's a meaningful amount of infrastructure for something that's adjacent to your actual product.
Letting the API layer handle it instead
If your SaaS wraps a model like Claude, this is one of the areas where using a managed API layer pays off instead of reimplementing it. SubToAPI turns your Claude access into an HTTPS API with application API keys (sub_live_...), and each key carries its own usage metadata — so per-key (and by extension per-user, per-team) consumption is visible without you building a metering pipeline from scratch.
In practice that means:
- Issue a distinct
sub_live_...key per customer, team, or plan tier - Track usage per key in the dashboard instead of building your own counters
- Combine key-level visibility with your own plan logic (e.g., map free-tier users to a shared low-limit key, paid users to individual keys)
A basic request looks like any other Claude call, just routed through SubToAPI:
curl https://api.subtoapi.app/v1/messages \
-H "Authorization: Bearer $SUBTOAPI_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-3-5-sonnet-20241022",
"max_tokens": 1024,
"messages": [{"role": "user", "content": "Summarize this ticket."}]
}'
See the quickstart and messages docs for the full request shape, and streaming if your per-user limits need to account for long-lived responses. Plans start at Solo €9, with Team (€19/seat) and Scale (€49/seat) tiers for products that need seat-based access control on top of usage limits — see pricing for details, or start a free trial at signup.
A practical checklist
- Decide what you're limiting: requests, tokens, concurrency, or cost
- Key every bucket to a stable identifier (user ID, API key, team ID) — never to IP alone
- Choose burst-tolerant algorithms (token bucket) over hard fixed windows for better UX
- Return
429withRetry-After, and document it - Expose usage to users before they hit the ceiling, not just when they do
- If you're proxying an LLM, separate per-user limits from the provider's own account-level limits — they're not the same thing
questions
Do I need per-user rate limits if I only have a handful of customers? Not urgently, but add them before you have paying customers on different plans — retrofitting rate limiting after a billing dispute is harder than building it in from the start.
Should rate limits be enforced client-side or server-side? Always server-side. Client-side checks are a UX nicety (showing a user they're near their limit) but can't prevent abuse or bypass.
How is this different from my LLM provider's own rate limits? Provider limits apply to your whole account; per-user limits apply within your app, on top of that. You need both — the provider limit protects your account, the per-user limit protects your customers from each other.