How to Reverse-Engineer AI Coding Plan Quotas from Usage Data: A Complete Method

    AI coding tools often show you nothing more than "95% of quota used" without revealing the underlying dollar amount or the quota base behind it. This guide walks through a complete reverse-engineering method: convert token usage into cost with a standard billing formula, infer the weekly quota by dividing spend by the used ratio, then derive monthly and short-window quotas through day ratios and window proportions. It includes a reusable Python script, cross-validation checks, a sensitivity analysis showing that total input volume and the cache-folding factor (not hit rate alone) drive the bill, and a look at how decode throughput and pricing models distort your conclusions. Use it to turn an opaque bundled quota into a cost model that is measurable, comparable, and budgetable.

    1. The Starting Point: A Bill That Only Shows a “Percentage”

    Most developers using AI coding agents have hit this: after finishing a medium-sized task, you open the quota panel and see that more than 90% of your weekly allowance is gone, but the panel only tells you “95% used.” It does not tell you what that number is worth in money, what quota base it refers to, or how much headroom is left in the shorter windows.

    Take a full implementation task that clones an arcade game. The usage came out as:

    Metric Measured value
    Input tokens 22.9M
    Output tokens 213K
    Cache hit rate 95%
    Weekly quota consumed ~95%

    The only clue the platform gives you is “95% of weekly quota consumed.” To judge whether this task was expensive and whether the plan is worth it, you need a reverse calculation: infer the quota base from “usage + ratio,” then infer the effective unit price from the quota base. In essence, you are turning an opaque bundled allowance back into a cost model you can compare, compute, and budget.

    Two preconditions must hold, or the conclusions will be distorted:

    1. The baseline must be clean. Only when the measurement period has just started (for example, counting begins immediately after the weekly usage resets to zero) does “95% consumed” equal “95% of the quota consumed.” If there is already historical usage in the period, the ratio reflects a cumulative value, and the inferred base will be systematically overestimated.
    2. The pricing basis must match the official one. Input, output, cache read, and cache write are four distinct price items in many billing systems. Mixing them will directly throw off the amount.

    2. Step 1: Convert Token Usage into a Cost

    2.1 The general form of the billing model

    Most large-model services use a structure of “separate pricing for input/output plus a cache-hit discount.” Let:

    • p_in: unit price for input that misses the cache (CNY / 1M tokens)
    • p_out: unit price for output (CNY / 1M tokens)
    • d: cache-hit discount factor (0 < d < 1; the common approach bills the hit portion at a small fraction of the input price)

    Then the cost of one task is:

    1. Cost = In × (1 - h) × p_in + In × h × p_in × d + Out × p_out

    where In is the total input tokens, h is the cache hit rate, and Out is the output tokens. This can be merged into a more intuitive form:

    1. Cost = In × p_in × (1 - h × (1 - d)) + Out × p_out

    The term 1 - h × (1 - d) in parentheses is the cache cost-folding factor. It translates “hit rate”—a number that looks like a pure performance metric—directly into a cost factor.

    2.2 Inferring the quota base from the measured ratio

    The quota base (the amount corresponding to the weekly quota) is just one step away:

    1. Quota_week = Cost_task / used_ratio

    If the bill for this task is known to be 87.7 CNY and the ratio is 95%, then the weekly quota is about 87.7 / 0.95 ≈ 92.3 CNY. The 87.7 CNY itself can also be computed from the billing formula above—as long as you have the officially published price table, plug in In = 22.9M, Out = 213K, h = 95%, and you get it. No “internal information” is required.

    Conversely, if you only know the ratio and not the unit price, you can do a parameter back-solve to estimate the order of magnitude. Assume p_out = 3 × p_in, d = 0.1, and let p_in = x:

    1. 87.7 = 22.9 × (1 - 0.95 × 0.9) × x + 0.213 × 3x
    2. = 22.9 × 0.145 × x + 0.639x
    3. = 3.9595x
    4. → x ≈ 22.2 CNY / 1M input tokens

    The point of this step is this: with a single bill that includes a ratio, you can back out the order of magnitude of the service’s effective price, and from then on convert every subsequent task into a comparable amount.

    2.3 A reusable conversion script

    1. from dataclasses import dataclass
    2. @dataclass
    3. class Price:
    4. p_in: float # CNY / 1M input tokens (cache miss)
    5. p_out: float # CNY / 1M output tokens
    6. cache_discount: float = 0.10 # Cache-hit discount factor
    7. def cost(in_tokens: int, out_tokens: int, hit: float, price: Price) -> float:
    8. """Convert token usage into a cost. in_tokens/out_tokens are in tokens."""
    9. assert 0.0 <= hit <= 1.0, "hit rate must be in [0, 1]"
    10. m_in, m_out = in_tokens / 1e6, out_tokens / 1e6
    11. cached, uncached = m_in * hit, m_in * (1 - hit)
    12. return uncached * price.p_in \
    13. + cached * price.p_in * price.cache_discount \
    14. + m_out * price.p_out
    15. def infer_quota(spent: float, used_ratio: float) -> float:
    16. """Infer the quota base from 'amount spent + used ratio'. Requires a clean baseline."""
    17. if not 0 < used_ratio <= 1:
    18. raise ValueError("used_ratio must be in (0, 1]")
    19. return spent / used_ratio
    20. def cache_fold(hit: float, discount: float = 0.10) -> float:
    21. """Cache-folding factor: the fraction of input-side cost retained."""
    22. return 1 - hit * (1 - discount)

    3. Step 2: Multi-Tier Quota Estimation and Cross-Validation

    AI coding plans are usually not a single allowance but multiple nested tiers, commonly three:

    1. A short rolling-window quota (e.g., a usage cap within a few hours), used to suppress bursts of activity;
    2. A weekly quota, used to constrain total consumption over a calendar week or a rolling 7 days;
    3. A monthly quota, used to constrain the full-month total.

    To go from the weekly quota to the monthly quota, the most direct conversion is by day ratio: Monthly ≈ Weekly × 30 / 7 ≈ Weekly × 4.3. In the example above, the weekly quota is 92.3 CNY, which corresponds to a monthly quota of about 370–395 CNY—the order of magnitude matches perfectly.

    The short-window quota, however, cannot be split evenly by day. If you estimate it as “weekly quota × 20%,” then 92.3 × 20% ≈ 18.5 CNY, consistent with the common design where an hourly-scale window makes up only a small part of the full-period quota. Here the difference between rolling and fixed windows must be emphasized:

    • Under a fixed window (e.g., reset at 00:00 each day), usage can be tracked by slicing it along calendar days;
    • Under a rolling window (e.g., “any consecutive 5 hours”), the quota is continuously sliding, so if you keep a high-consumption pace, you can repeatedly hit the short-window ceiling even when plenty of weekly quota remains.

    So when doing capacity planning, the short-window quota determines your peak throughput capacity, while the weekly/monthly quota determines your total available workload. The two cannot substitute for each other.

    Consistency check checklist

    Check item Method Common cause of failure
    Week ↔ Month Monthly / Weekly ≈ 4.0 ~ 4.3 Month counted by calendar days, includes bonus credits or tiered discounts
    Week ↔ Short window Short-window / Weekly falls in a reasonable range Different rolling-window definitions, different peak/off-peak coefficients
    Bill ↔ Quota Σ Bills ≈ Quota × Used ratio Cache writes not counted, thinking tokens not included, bonus credits applied
    Usage ↔ Panel Panel token count = input + output + cache The metric includes system prompts or tool returns

    4. Step 3: Sensitivity Analysis—The Three Variables That Really Decide the Bill

    After inferring the quota, the more valuable question is “will the next task be more expensive?” Perturbing one variable at a time for the same task yields clear conclusions.

    Fix In = 22.9M, Out = 213K, p_out = 3 p_in, d = 0.1, and observe with p_in as the unit of 1:

    Cache hit rate h Input-side factor Input-side relative cost Note
    0% 1.000 100% No cache, full input price
    90% 0.190 19% Already saved ~80%
    95% 0.145 14.5% Measured scenario
    99% 0.109 10.9% Long context reused stably
    99.9% 0.100 10.0% Near the theoretical floor d

    Conclusion 1: Raising the hit rate from 90% to 99% cuts input-side cost by another ~43% (0.190 → 0.109), but the absolute gain narrows—because the theoretical floor is locked by the discount factor d, and no matter how high the hit rate goes, input cost can never fall below d times the input price. So the optimization focus should shift from “stacking up hit rate” to “reducing the total volume of useless input.”

    Conclusion 2: The output side is a far bigger lever than the input side. In this example, output tokens are only 0.93% of input tokens, but because the output unit price is usually several times the input price, they contribute about 16% of the total cost. This means getting the model to write less, edit less, and rewrite less delivers more immediate results than optimizing context reuse.

    Conclusion 3: Total input volume is a linear amplifier. 22.9M input tokens for a single medium-sized task shows that agent-style multi-turn tool calls repeatedly feed the same context into the model, so the cumulative input volume far exceeds the “conversation length” you see with your own eyes. Capping the number of turns per task and compressing history in time is the first lever for suppressing the bill.

    5. The Overlooked Second Cost Dimension: Throughput

    The decode throughput of the same class of task can differ by several times across models. In measured comparisons, one model ran at about 145 tokens/s and another at about 48 tokens/s—a gap of nearly 3x.

    Throughput affects more than just “how fast it feels”; it indirectly shapes the cost structure:

    1. Higher probability of hitting the short-window ceiling. For the same output volume, running 3x slower means occupying the window for about 3x longer, making it easier to trigger rate limiting inside a rolling short window and forcing retries—and retried tokens usually count toward the bill too.
    2. A cliff in the interactive experience. In agent scenarios the user watches tool calls and code diffs, and 48 tokens/s turns “reading code” into waiting, lowering effective output and raising the cost per unit of output.
    3. Cost per unit of output is the correct metric. When comparing two models side by side, bill amount / completed feature points (or lines of code) is the comparable measure; comparing only unit price or only speed leads to wrong conclusions.

    A pragmatic evaluation method is to look at three metrics together: effective price per 1M tokens, decode throughput, and short-window headroom. Together they determine “for the same task, how much I pay, how long I wait, and whether I get rate limited.”

    6. How the Pricing Model Affects the Conclusions

    The same usage under different pricing models can produce bills that differ by an order of magnitude:

    • Pure pay-as-you-go: bill = token usage × unit price, fully linear, the easiest to infer and the easiest to lose control of.
    • Time-of-use (peak/off-peak) pricing: the same task can cost nearly twice as much in an off-peak period as in a peak one. When doing the inference, you must confirm the actual time zone and time slot the task fell into; otherwise the “unit price” you back out is a blended value.
    • Subscription amortization: converting a subscription fee into an effective unit price using the allowance inside the plan is often significantly lower than a pay-as-you-go bill—because plan pricing usually already includes a large volume discount. But the cost is a hard quota ceiling: exceeding it cuts you off, and unused quota is not refundable.
    • Historical price changes: the same task completed before and after a price change cannot be compared directly. To judge “is it expensive right now,” you must recompute historical usage using the current effective price table.

    In the example above, a comparable task on a low-tier model before a price hike cost under 3 CNY; on another tier at time-of-use rates it ran about 6.5–13 CNY; while on a high-tier model it was on the order of 87 CNY. The same 70–90M input volume produced bills that differ because of the price tier, not the efficiency—a point most easily misread when choosing a tool.

    7. Error Sources and How to Avoid Them

    How much you can trust the reverse-engineered quota depends on whether you have ruled out these confounders:

    1. A dirty baseline: there is already consumption in the period, so the ratio is a cumulative value.
    2. Bonus credits and discount offsets: the panel shows a “converted consumption” that is not equivalent to a standard-price bill.
    3. Cache writes not billed separately: some systems charge a higher price for the initial cache write; ignoring it underestimates cost.
    4. The accounting basis for thinking/reasoning tokens: whether they count as input and whether they are priced separately varies by provider.
    5. Tool return content counted as input: reading files, fetching web pages, and running tests all turn their returns into the next turn’s input, and these often cannot hit the cache.
    6. Retries and failed calls: consumption from timeout retries is usually billed as normal.
    7. Mixing rolling and fixed windows: this skews the short-window quota inference.
    8. Comparing unit prices across model tiers directly: with different price tiers, comparing unit prices is meaningless; you should compare “cost per unit of output.”

    8. A Practical, Ready-to-Apply Checklist

    • Establish a usage baseline: at the start of each measurement period, record the panel’s zeroed state; only then do the ratios carry meaning.
    • Compute once, store a copy: convert your task into a cost once using the official price table, and build a personal/team effective-unit-price card.
    • Build a three-tier quota table: convert the weekly, monthly, and short-window quotas each into “how many comparable tasks can be done,” for scheduling rather than staring at percentages.
    • Watch two leading indicators: short-window headroom (whether you will get rate limited) and output-token growth rate (the slope of your bill).
    • Evaluate by output: use “cost to complete one feature point” as a unified measure for both tool selection and budgeting.
    • Recompute periodically: after price changes, plan changes, or cache-policy changes, all historical inferences become void and must be rerun with the new price table.

    9. Summary

    Starting from a panel that only says “95% used,” dividing the bill amount by the used ratio lets you infer the weekly quota; applying day ratios and window proportions gets you the monthly and short-window quotas. Then Cost = In × p_in × (1 - h(1-d)) + Out × p_out converts any single task into a monetary amount, and the entire plan’s cost structure becomes computable, comparable, and budgetable. What truly decides the bill is not the single number of hit rate, but the product relationship between two terms: “total input × cache-folding factor” and “output volume × output premium”; and decode throughput influences the final cost indirectly through the probability of hitting the short-window ceiling. Quantify these three things, and tool selection and budgeting stop depending on a “gut feeling of whether it’s expensive” and become engineering decisions backed by concrete numbers.