How Are Subscription Quotas Calculated? A Breakdown of 5-Hour Windows and Failed-Request Billing
This article explains how subscription-based LLM quotas actually work: how a 5-hour window is computed, whether failed requests consume quota, how to size short-term versus long-term limits, how quota recovers after a subscription resets, and how to make rate-limit responses and quota ledgers understandable. It includes practical guidance on fixed versus sliding windows, pre-deduction and settlement with idempotency, ratio formulas, dual-timeline alignment, error semantics, and a pre-launch checklist.
1. The Boundaries of Quota Design: Separate Model Capability, Compute Cost, and Quota Rules
When people discuss LLM API quotas, subscription billing, and rate limiting, what they really care about is usually not “is the model strong enough.” It is “why am I being charged,” “how is the 5-hour quota actually calculated,” “do failed requests consume quota,” and “when does my quota come back after a subscription resets.”
On the surface these look like billing questions, but they are really product-experience questions. Model capability depends mainly on data quality, training methods, and parameter scale. Compute cost and response speed depend mainly on inference optimization, scheduling strategy, and resource scale. Quota design depends on rate-limiting algorithms, window partitioning, billing semantics, and product communication. Users do not necessarily resist paying, but they strongly resist paying for something they cannot understand.
Traditional API billing is usually measured in requests or tokens, which makes the accounting fairly intuitive. Subscriptions are different: they bundle “unpredictable compute usage” into a “fixed price plus multi-dimensional quotas.” If the short-window quota, long-window quota, subscription cycle, and failed-request handling are inconsistent, users cannot form a stable expectation. So the core goals of subscription quota design can be summarized in three sentences: allocations must be derivable, consumption must be explainable, and the experience must be predictable.
2. How Is the 5-Hour Quota Calculated? From Fixed Windows to Sliding Windows
Subscription-based LLM services commonly use a multi-dimensional limit structure: time windows, cumulative quotas, and rate limits work together. The key to “how is the 5-hour quota calculated” is not simply setting a number, but defining how the window rolls, how consumption accumulates, and whether failed requests count.
There are three common window implementations.
The first is the fixed window. It is sliced by natural hour or natural day. It is simple to implement, but it tends to produce “end-of-window spikes.” For example, users may concentrate their usage just before the window ends; the moment it resets they start again immediately, so the instantaneous load is uneven.
The second is the sliding window. It looks backward a fixed duration from the current moment. A 5-hour window, for instance, continuously observes effective consumption over the last 5 hours, which better expresses a “rolling quota.”
The third is token bucket or leaky bucket. These algorithms suit controlling request rate and concurrency, not directly expressing “total available quota within a period.” Real systems often combine them: edge rate limiting uses a token bucket to block instantaneous bursts, while billing quotas use a sliding window to record effective consumption.
The recommended approach is: use a sliding window for short-period quotas and a fixed window for long-period quotas, and clearly define the time zone and reset semantics. For example, “the 5-hour window rolls over the most recent 5 hours” and “the weekly quota resets at Monday 00:00 of the natural week, in the UTC+8 time zone.”
For the atomic decision implementation, it is better to avoid concatenating request_id and cost into a single string. A request_id may contain a colon, such as a key structure like tenant:user. If you rely on splitting at the first colon, you can easily extract the wrong cost value. A safer approach is to store only the request_id as the ZSET member and keep the cost in a separate hash field, for example cost:{request_id}. In addition, the timestamp should use server time, for example by calling redis.call(‘TIME’) in Lua, rather than trusting a now value passed by the client, to prevent the client from manipulating the window reset via future or past timestamps.
Illustrative logic:
-- KEYS[1]: quota:{tenant:user}:session_5h:zset-- member: request_id-- score: event timestamp (seconds)-- KEYS[2]: quota:{tenant:user}:session_5h:cost-- field: request_id-- value: cost-- ARGV[1]: window_sec (window length)-- ARGV[2]: limit (quota for the window)-- ARGV[3]: cost (this request's consumption)-- ARGV[4]: request_id (idempotency key)local window_sec = tonumber(ARGV[1])local limit = tonumber(ARGV[2])local cost = tonumber(ARGV[3])local req_id = ARGV[4]-- Use Redis server-side time to reduce the risk of time manipulationlocal t = redis.call('TIME')local now = tonumber(t[1])-- If this request has already been billed successfully, return the cached resultlocal cached = redis.call('HGET', KEYS[2], req_id)if cached thenreturn cachedend-- Remove expired events outside the windowredis.call('ZREMRANGEBYSCORE', KEYS[1], '-inf', now - window_sec)local events = redis.call('ZRANGEBYSCORE', KEYS[1], now - window_sec, '+inf')local used = 0for i = 1, #events dolocal event_cost = redis.call('HGET', KEYS[2], events[i])if event_cost thenused = used + tonumber(event_cost)endendif used + cost > limit then-- Rejection results should not be cached long-term, to avoid returning a stale rejection after the window recoversreturn "0:" .. tostring(limit - used)endredis.call('ZADD', KEYS[1], now, req_id)redis.call('HSET', KEYS[2], req_id, cost)redis.call('EXPIRE', KEYS[1], window_sec)redis.call('EXPIRE', KEYS[2], window_sec)return "1:" .. tostring(limit - used - cost)
If request volume is very high, iterating over the ZSET entry by entry adds overhead. In production you can split the window into multiple small buckets, for example one bucket every 5 minutes, where each bucket records the weighted consumption for that period. When deciding, you only need to sum the most recent 60 buckets, because 60 × 5 minutes = 300 minutes = 5 hours. To reduce the number of buckets, you can instead use one bucket every 25 minutes and sum the most recent 12 buckets, which also covers 5 hours. The key is that the number of buckets must match the bucket length; avoid a wrong calculation like “12 five-minute buckets,” which looks precise but is incorrect.
Quota decisions must also satisfy three engineering requirements.
First, atomicity. The check, deduction, and recording must happen in the same atomic operation, to prevent concurrent requests from breaking through the limit.
Second, idempotency. When the same request_id is submitted repeatedly, it should not be charged twice. A successful deduction can be written as an idempotency record, but a rejection result should not be cached long-term.
Third, rollback capability. Failed requests, timed-out requests, and system-error requests should be able to be explicitly rolled back, to avoid “technical failures” being wrongly counted as user consumption.
3. Do Failed Requests Consume Quota? Pre-Deduction, Settlement, and Idempotency
Whether failed requests consume quota is one of the most contentious issues in subscription quotas. Users are especially sensitive in long-running, overnight, and batch scenarios: if a request times out, the server errors, the content is blocked, or the task fails midway, has the quota already been deducted? And can it be restored after being deducted?
A recommended approach is to split request consumption into two stages: pre-deduction and settlement.
Pre-deduction stage: before a long-running task starts, freeze part of the quota based on the maximum estimated cost.
Settlement stage: after the task ends, settle based on actual effective output or actual usage, refunding the difference.
Failure stage: if it is a system failure, the pre-deduction should be released automatically; if it is a business failure, decide whether to bill partially according to product policy.
The idempotency key should include at least the following fields:
- request_id: a unique request ID generated by the client;
- scope: the quota dimension, for example session_5h, week, or month;
- payload_hash: a digest of the request body, used to identify the same request;
- client_nonce: a retry nonce, to prevent accidental replay;
- issued_at: when the request was initiated;
- account_id: the account dimension, to facilitate reconciliation.
A pre-deduction ledger can be designed like this:
{"hold_id": "hold_20260214_001","request_id": "req_456","scope": "session_5h","hold_cost": 120,"settled_cost": 0,"status": "pending","created_at": "2026-02-14T10:00:00Z","settled_at": null,"refund_id": null}
After the task succeeds, the ledger is updated to:
{"hold_id": "hold_20260214_001","request_id": "req_456","scope": "session_5h","hold_cost": 120,"settled_cost": 96,"status": "settled","created_at": "2026-02-14T10:00:00Z","settled_at": "2026-02-14T10:12:30Z","refund_id": null}
After the task fails or times out, the ledger is updated to:
{"hold_id": "hold_20260214_001","request_id": "req_456","scope": "session_5h","hold_cost": 120,"settled_cost": 0,"status": "failed_refunded","created_at": "2026-02-14T10:00:00Z","settled_at": "2026-02-14T10:03:00Z","refund_id": "refund_789"}
The suggested order for settlement rollback is:
- First check the idempotency key; if the request has already been processed successfully, return the historical result directly.
- Query the pre-deduction ledger and confirm whether the current hold_id status is pending.
- If the task succeeds, settle by actual usage, refunding the excess or charging the shortfall.
- If the task fails, release the pre-deducted quota and write a refund_id.
- If the rollback fails, push it into a compensation queue for a scheduled reconciliation task to repair later.
- Reconciliation results should be written to an audit log, to support user appeals and platform troubleshooting.
It is important to emphasize here that whether rejection results should be idempotently cached must be made explicit. If a “quota insufficient” rejection is written into the idempotency cache long-term, it can cause a user to still receive the stale rejection when retrying after the window has partially recovered. So a more reasonable design is: only successful deductions write an idempotent result; rejection responses should only hold a short-term concurrency lock, or not be cached at all.
Exception-compensation example: a long-running task hits a database write failure during settlement, so the pre-deducted quota is not released. In this case the system should not just return “try again later.” Instead, it should write the hold_id into compensation_queue and re-execute the rollback in the next reconciliation run. If the rollback succeeds, update the ledger and notify the user; if it fails, raise a manual alert.
4. How Do You Set the Ratio? Empirical Guidance for r and M
Many teams ask: how should short-period and long-period quotas be sized relative to each other? For example, what should the relationship be between the 5-hour quota and the weekly quota?
Let the weekly quota be W and the 5-hour quota be S, so the ratio is r = W / S. In engineering practice, r should not be set arbitrarily from experience. It should be validated against user behavior patterns, the failed-request-no-charge policy, and concurrency constraints.
If the target is a typical user who works “5 business days, using the service intensively for 5 hours a day,” then r ≥ 5 can serve as an empirical lower bound. The reasoning: if a user maxes out one 5-hour window every day, they consume about 5S per week. If W is clearly smaller than 5S, the weekly quota becomes an invisible ceiling too early, and the short-period quota loses its buffering purpose.
However, note that r ≥ 5 is not a universal conclusion. It depends on the following premises:
- users use the service on business days, with lower activity on weekends;
- the weighted cost per request is relatively stable;
- failed requests are not counted as effective consumption;
- it is mostly single account, single device, single payment subject;
- there are no large bursts of batch processing or long-context tasks.
If the user base includes a lot of long outputs, long contexts, batch generation, or overnight tasks, r may need to be raised. If users are mostly low-frequency, lightweight users, r can be lowered appropriately, but you must ensure the short-period quota still has meaningful constraint.
For the month quota M relative to the week quota W, a common reference is M ≈ 4.3W, because a month is roughly 30 days and 30 / 7 ≈ 4.3. This ratio is only a starting point for conversion, not a fixed standard. Actual design must also consider:
- whether there are promotions, workday peaks, or end-of-month catch-up tasks within the month;
- the true effective consumption after failure rollbacks;
- whether concurrent requests amplify short-period ceiling hits;
- whether long-period plans roll monthly;
- whether users can easily understand the monthly total.
The measurement semantics of the ratio design must also be unified. It is recommended to count only “effective consumption,” meaning the quota consumption that actually affects user experience after deducting failed-request rollbacks. Grayscale validation can observe the following metrics:
- ceiling-hit rate: what proportion of users hit the ceiling within a window;
- ceiling-hit distribution: whether the users who hit the ceiling cluster in the two extremes of high-frequency short sessions and low-frequency long sessions;
- complaint rate: whether hitting the ceiling generates “I can’t understand the rules” feedback;
- renewal rate: whether the quota rules affect renewals after adjustment;
- predicted ceiling error: whether the system’s predicted ceiling time is close to the actual ceiling time;
- failed-charge ratio: whether failed requests are wrongly counted as consumption.
One actionable strategy is: first use r ≥ 5 as the initial empirical value, then run grayscale on typical user segments. If most users in the middle hit the ceiling frequently, check whether the ratio is too low. If only a few extreme users hit the ceiling and can clearly recover afterward, the rules are relatively healthy.
5. How Does Quota Recover After a Subscription Cycle Resets? Dual-Timeline Alignment
Continuous monthly and annual subscribers often run into a confusing situation: the subscription cycle has just reset, so why is the short-period window still limited? Often the problem is that the “subscription cycle” and the “quota window” are not aligned.
A dual-timeline model is recommended:
- Subscription timeline: determines when the total quota resets, for example the renewal date or the subscription cycle end date;
- Window timeline: determines how the rolling window advances, for example rolling every 5 hours or every 7 days.
Alignment rules can be designed like this:
- Clearly declare the two timelines: the total quota resets on the subscription cycle, and the short-period window rolls on natural time.
- After renewal, the total quota bound to the subscription cycle is restored accordingly.
- Rolling windows are not force-cleared on renewal; they continue to slide according to the established rules.
- Long-period plans must state whether the quota rolls monthly or rolls by the plan cycle, so that quarterly or annual subscribers do not mistakenly think the quota is released all at once.
- Whether unused quota carries over should be stated in advance; if it does not carry over, the exact time it is cleared at expiry should also be explicit.
- For refunds, upgrades/downgrades, and cross-cycle changes, provide quota-proration rules to avoid the perception of “saved money but lost quota.”
In addition, anti-abuse risk control needs to be front-loaded. If the platform finds multiple accounts sharing a payment subject, device fingerprint, IP/ASN, or highly similar call patterns, it should trigger association detection and risk scoring. Handling options can include stronger identity verification, temporary limits, manual review, or restricting high-risk capabilities. However, such detection involves processing personal information and device data, so it should follow the data-minimization principle, comply with privacy regulations, and clearly inform users in the terms of service and privacy policy. The policy wording should not describe how to bypass limits; it should emphasize compliant detection of accounts, payments, devices, and behavior.
6. Why Are Rate-Limit Messages Hard to Understand? Error Semantics and the Quota Ledger
Rate limiting itself is not frightening; what is frightening is a user who only sees “too many requests, please try again later.” A better approach is to make the rate-limit response carry enough information for users to know: which dimension hit the ceiling, how much has been used, when it will recover, and whether they can continue.
A suggested response structure is:
{"error": {"code": "QUOTA_WINDOW_EXCEEDED","scope": "session_5h","used_ratio": 1.0,"reset_at": "2026-02-14T15:30:00Z","next_scope_remaining_ratio": 0.42}}
This can be paired with response headers:
- X-Quota-Scope: the quota dimension that hit the ceiling;
- X-Quota-Used: the amount already used in the current window;
- X-Quota-Limit: the total quota of the current window;
- X-Quota-Remaining: the remaining quota in the current window;
- X-Quota-Reset-At: the estimated recovery time;
- Retry-After: the suggested retry wait in seconds;
- X-Quota-Cost: the actual billed or pre-deducted cost of this request.
A copy template can be written as:
“Your ceiling was hit on the session_5h dimension; it is at 100% used with 0 remaining; recovery is estimated at 2026-02-14T15:30:00Z. This week’s quota has 42% remaining. To continue your task, wait for the window to recover, or reduce the single-response output length.”
Beyond the rate-limit response, the account page should also provide a “quota ledger”:
- real-time remaining quota for each window: 5-hour, weekly, monthly;
- reset countdown;
- estimated ceiling time projected from the current consumption rate;
- per-request consumption details;
- an explanation of whether failed requests are charged;
- a timeline comparison chart of the subscription cycle and the quota windows.
The value of a quota ledger is that users no longer have to guess to understand the rules. Most quota disputes are not because the rules themselves are unacceptable, but because users cannot verify their own assumptions.
7. Edge Cases and the Feedback Loop: Long Tasks, Retries, and Off-Peak Scheduling
Under subscriptions, a few edge cases are the most likely to trigger disputes:
- Overnight long tasks: users start a task at night and wake up to find their quota heavily consumed;
- Mid-task failure: consumed quota cannot be recovered;
- Retries and replays: network jitter or client retries cause duplicate charges;
- Peak-time congestion: responses slow down, and users assume their quota was secretly deducted.
Corresponding strategies can include:
- support checkpoint resume for long tasks, splitting tasks into resumable stages and settling by actual output;
- automatically roll back failed portions and mark “not billed on failure” in the bill;
- constrain retries with idempotency keys so repeated requests are not charged twice;
- offer quota discounts or priority scheduling during off-peak periods, turning “slow” into a predictable benefit;
- display pre-deduction, settlement, and rollback records in the bill so users can verify them.
The feedback loop should also be productized. Users can submit a request_id or a time range to self-service query their quota decision records. Suggested self-diagnosis fields include:
- request_id;
- account_id;
- scope;
- decision;
- reason_code;
- used_before;
- used_after;
- cost;
- hold_id;
- refund_id.
When rules change, announce it in advance and provide an old-versus-new comparison. An announcement template can include:
“Change time: 2026-03-01 00:00; scope: subscription-plan users; change: the 5-hour window shifts from a fixed window to a sliding window; old vs. new: the fixed window recovers at the top of the hour, while the sliding window accumulates over the most recent 5 hours; grayscale: first open to 10% of users; feedback channel: the quota appeal page in the help center.”
Monitoring metrics are recommended to link “ceiling-hit rate,” “complaint rate,” and “renewal rate,” plus:
- retry success rate within 1 hour after hitting the ceiling;
- complaint rate after hitting the ceiling;
- renewal rate within 24 hours after hitting the ceiling;
- failed-charge ratio;
- predicted ceiling error;
- average recovery duration;
- long-task rollback latency;
- compensation completion rate.
The observation period should cover at least 2 subscription cycles or 4 weeks, to avoid misjudging based on short-term data alone.
8. Pre-Launch Self-Check: Subscription Quota and Rate-Limiting Checklist
| Check item | Pass criteria | Section |
|---|---|---|
| Short- vs. long-period ratio | Does r start from an empirical lower bound and get validated by grayscale? | 4 |
| Monthly vs. weekly quota | Does it reference M ≈ 4.3W and adjust for user segments? | 4 |
| Subscription cycle reset | Does quota bound to the subscription cycle restore in sync? | 5 |
| Rolling-window implementation | Does it use a sliding window or time buckets and avoid boundary spikes? | 2 |
| Bucket length vs. bucket count | Does bucket duration × bucket count equal the target window, avoiding arithmetic errors? | 2 |
| Failed-request semantics | Are platform failures, timeouts, and overload requests explicitly not billed? | 3 |
| Failure rollback | Can it complete automatically, and is rollback latency acceptable? | 3 |
| Retry idempotency | Are repeated requests not charged twice, and are rejection results avoided in long-term cache? | 3 |
| User visibility | Can users see each window’s remaining quota, reset time, and estimated ceiling time in real time? | 6 |
| Rate-limit semantics | Does it include the ceiling dimension, recovery time, remaining quota, and Retry-After? | 6 |
| Long-task capability | Does it support pre-deduction, settlement, checkpoint resume, and failure rollback? | 3, 7 |
| Bill verification | Does it show pre-deduction, settlement, and rollback details, and can users verify them? | 7 |
| Risk-control compliance | Does it cover association detection across accounts, payments, devices, and call behavior, and meet privacy-disclosure requirements? | 5 |
| Change announcement | Are rule changes announced in advance with an old-vs-new comparison? | 7 |
| Monitoring metrics | Does it monitor ceiling-hit rate, complaint rate, renewal rate, failed-charge ratio, and predicted ceiling error? | 7 |
If any one of these items cannot be answered, it means the quota rules are not yet fully productized. Subscription quota design is not a simple parameter configuration; it is a complete mechanism built around user expectations, engineering implementation, and risk-control governance.
9. Summary: It Can Be Expensive, but the Logic Must Be Clear
The quota design of subscription-based LLM services is essentially about finding a balance among cost control, fairness of experience, and explainable rules. Model capability is a technical problem, compute and speed are an engineering problem, and quota design is a product-attitude problem.
What users complain about is often not “expensive,” but “I can’t understand it” and “I can’t do the math.” When questions like how the 5-hour quota is calculated, whether failed requests are charged, and how quota recovers after a subscription resets all have clear answers, users can more easily build a stable expectation.
So the quota system should aim to be: derivable in allocation, rolling in windows, aligned in cycles, rollback-safe on exceptions, observable in state, and explainable in risk control. Only when the rules are clear enough can the subscription business model remain sustainable in the long run, and only then can users shift from “complaining about quota” to “planning their usage.”
