Guide to Reverse Engineering Subscription Quotas and Cost Modeling

    This article explores a general methodology for evaluating subscription-based service quotas by analyzing unrounded floating-point ratios. It details mathematical tools like continued fractions and the Stern-Brocot tree for recovering rational numbers, building quota consumption models based on token weights and multipliers, and establishing a comprehensive cost evaluation workflow. The guide helps users make rational subscription decisions while outlining engineering best practices for service providers to prevent implicit information leakage.

    Guide to Reverse Engineering Subscription Quotas and Cost Modeling

    Note: This article discusses a general methodology for evaluating subscription quotas. The prices, quotas, and ratios mentioned are masked or hypothetical examples used solely to illustrate the calculation process. They do not represent the actual billing rules of any specific commercial product. When using any subscription service, always refer to the Terms of Service and official documentation. Malicious probing or bypassing rate limits to obtain data is not recommended.

    1. The Origin of the Problem: Why Unrounded Floats Leak Quotas

    Subscription-based services typically describe usage in units such as “compute points,” “request counts,” or “message limits.” To display remaining quotas, usage ratios, or reset progress, APIs often return a decimal number. If this decimal is not rounded but returns the raw ratio directly, its mantissa may retain information about the original rational number.

    For example, a ratio that should ideally be 449/2750 has a decimal approximation of:

    1. 0.16327272727272727

    In double-precision floating-point representation, it might appear as:

    1. 0.16327272727272726

    The discrepancy at the end originates from the binary representation error of IEEE 754 floating-point numbers. For an average user, this is merely a display precision issue. However, for cost analysis, it implies that: as long as you obtain multiple sets of ratio data with a stable numerator/denominator structure, it is possible to reverse-engineer the denominator, thereby estimating the quota limit, window allowance, and tier multipliers.

    The root causes of this type of information leakage generally fall into three categories:

    1. The server returns an unrounded ratio value directly;
    2. The ratio is calculated directly from “used amount / total quota,” where the denominator is the internal quota;
    3. Multiple data sets share the same denominator or an integer multiple of it, forming cross-verifiable constraints.

    From an engineering perspective, this does not necessarily constitute a severe security vulnerability, but it does reduce the ambiguity of pricing strategies. For service providers, returning rounded values, interval values, or standardized rate-limit headers is more robust. For users, understanding the underlying principles facilitates a more rational evaluation of subscription costs.

    2. From Float to Rational Number: Continued Fractions and Stern-Brocot Trees

    To recover the original fraction from a floating-point number, the core technique is “rational approximation”: finding the closest fraction among those whose denominator does not exceed a certain upper limit. Common methods include continued fraction expansion, Stern-Brocot tree search, and approximation algorithms based on maximum denominator constraints.

    Using Python as an example, the standard library’s Fraction can directly perform rational approximation with a maximum denominator constraint:

    1. from fractions import Fraction
    2. def rational_approx(x: float, max_den: int = 10**6):
    3. f = Fraction(x).limit_denominator(max_den)
    4. return f.numerator, f.denominator
    5. x = 0.16327272727272726
    6. print(rational_approx(x, 10**6))
    7. # Example output: (449, 2750)

    The illustrative logic for continued fraction expansion is as follows:

    1. def continued_fraction(x: float, n: int = 20):
    2. a = []
    3. for _ in range(n):
    4. i = int(x)
    5. a.append(i)
    6. frac = x - i
    7. if frac < 1e-15:
    8. break
    9. x = 1.0 / frac
    10. return a
    11. print(continued_fraction(0.16327272727272726))

    Each convergent of a continued fraction is an approximation of the original rational number. The Stern-Brocot tree can be understood as a binary search within the space of fractions: starting from 0/1 and 1/0, it progressively approaches the target value using mediants. The two are mathematically equivalent, differing only in implementation.

    When actually reverse-engineering, you should not rely on a single floating-point number. A more reliable approach is:

    1. Collect multiple sets of ratio data, such as remaining ratios at different usage levels;
    2. Find candidate fractions for each data set separately;
    3. Check if the denominators are identical, are integer multiples of each other, or have a divisibility relationship with known window quotas;
    4. Use least squares or divisibility constraints for cross-validation;
    5. Perform sensitivity analysis on candidate results to exclude “overfitted fractions” caused by floating-point noise.

    If multiple independent samples point to the same denominator, or if a stable integer multiple relationship exists between denominators, the credibility of the reverse-engineered result significantly increases.

    3. Quota Model: Points, Model Multipliers, and Input/Output Weights

    Subscription quotas are usually not simple “request counts” but weighted points determined by model type, input length, and output length. A general consumption model can be defined as:

    1. Single consumption = Input token count * Model weight
    2. + Output token count * Model weight * Output ratio

    Where:

    • Model weight differentiates high-cost, medium-cost, and low-cost models;
    • Output ratio represents the price multiplier of output tokens relative to input tokens;
    • Different models may share the same point system but have different weights.

    For example, suppose that in a certain system, a high-cost model is about 1.67 times that of a medium-cost model, and a low-cost model is about 5 times that of a medium-cost model; additionally, output tokens are 5 times the cost of input tokens. Consequently, for requests of the same length, if the output proportion is high, point consumption will accelerate noticeably.

    Subscription tiers are typically subject to “dual constraints”:

    1. Short-period rolling windows, such as available points per 5 hours;
    2. Long-period caps, such as available points per week.

    Therefore, the actual available quota is not simply a single number, but rather:

    1. Effective quota = min(short window quota constraint, weekly cap constraint)

    If the short window quota is high but the weekly cap is low, it is suitable for short bursts; if the short window quota is low but the weekly cap is high, it is suitable for steady, continuous use. To evaluate whether a subscription is “cheap,” you must combine it with your own usage patterns rather than just looking at the advertised multipliers.

    4. Masked Case Study: Calculating True Tier Multipliers

    Assume there are three tiers with prices of P, 5P, and 20P respectively. The following values are for methodology illustration only:

    • Low tier: 550,000 points per 5 hours, weekly cap of 5,000,000 points;
    • Mid tier: 3,300,000 points per 5 hours, weekly cap of 41,666,670 points.

    First, calculate the quota multipliers:

    1. 5-hour quota multiplier = 330 / 55 = 6
    2. Weekly cap multiplier = 4166.67 / 500 ≈ 8.33334

    Next, calculate the relative price multiplier: the Mid tier price is 5 times that of the Low tier. Thus, the quota multiplier per unit of currency is:

    1. 5-hour quota multiplier per unit currency = 6 / 5 = 1.2
    2. Weekly cap multiplier per unit currency = 8.33334 / 5 ≈ 1.66667

    This means: if looking only at the 5-hour window, the “points per unit of currency” for the Mid tier relative to the Low tier is about 1.2 times; if looking at the weekly cap, it is about 1.6667 times. The advertised “5x usage” may correspond to the price multiplier or a specific window, but the actual multipliers differ across windows.

    Furthermore, you can define a comprehensive cost-effectiveness metric for a tier:

    1. Quota per unit currency = Effective point quota / Price
    2. Relative cost-effectiveness = (Quota_B / Price_B) / (Quota_A / Price_A)

    However, this formula is only suitable for rough comparisons. A more refined model requires incorporating your personal workload:

    1. def monthly_score(input_tokens, output_tokens, model_weight, output_ratio=5):
    2. return input_tokens * model_weight + output_tokens * model_weight * output_ratio
    3. # Assume in one month:
    4. # High-cost model: 1,000,000 input tokens, 200,000 output tokens, weight 1.67
    5. # Medium-cost model: 3,000,000 input tokens, 600,000 output tokens, weight 1.0
    6. score = (
    7. monthly_score(1_000_000, 200_000, 1.67)
    8. + monthly_score(3_000_000, 600_000, 1.0)
    9. )
    10. print(score)

    By matching your personal monthly point consumption against the weekly caps and 5-hour windows of various tiers, you can determine whether it is “sufficient” or “wasteful.”

    5. Complete Workflow for Subscription Cost-Benefit Evaluation

    It is recommended to evaluate using the following steps:

    1. Collect Constraints: Record prices, short window quotas, weekly caps, reset rules, model weights, output ratios, and whether team sharing is supported.
    2. Translate Workload: Calculate your own or your team’s input tokens, output tokens, model mix ratio, cache hit rate, and failure retry rate.
    3. Calculate Point Demand: Use the weighted formula to estimate peak 5-hour demand and weekly demand.
    4. Calculate Effective Quota: Calculate the short window satisfaction and weekly cap satisfaction separately, and take the smaller value.
    5. Perform Sensitivity Analysis: Assume the output proportion increases by 20% and the high-cost model proportion increases by 30%, then observe the change in point demand.
    6. Compare Quota per Unit Currency: Do not just look at the total quota; examine the “remaining quota after satisfying your own workload / price.”
    7. Verify Stability: Observe multiple consecutive cycles continuously to avoid being misled by a single burst of traffic.

    A simple evaluation table can include: tier, price, 5-hour quota, weekly quota, estimated peak demand, estimated weekly demand, satisfaction status, quota per unit currency, and risk notes. For team users, concurrent rate limits, member sharing, and permission management must also be considered.

    6. Engineering and Compliance Best Practices

    For service providers, it is recommended to:

    • Apply fixed decimal rounding or interval-based display when returning ratios externally;
    • Use fixed-point or decimal types to calculate billing ratios, avoiding the exposure of internal rational numbers through binary floating-point remainders;
    • Adopt standardized fields for rate-limit headers, remaining quotas, and reset times to reduce implicit information leakage;
    • Audit and rate-limit abnormally high-frequency probing, without inadvertently blocking legitimate cost analysis.

    For users, it is recommended to:

    • Only passively observe through normal API endpoints, without bypassing rate limits or maliciously constructing requests;
    • Treat reverse-engineered results as estimates rather than official commitments;
    • Cross-validate with multiple data sets to avoid mistaking floating-point noise for the true denominator;
    • Comply with the Terms of Service, and do not use probing results for attacks, resale, or misleading promotion.

    In broader cloud resource cost governance, a similar methodology of “quota modeling — workload translation — sensitivity analysis” is equally applicable. For instance, in general cloud resource management on platforms like Baidu AI Cloud, you can also first establish a resource consumption model, and then combine it with monitoring alerts and budget thresholds for capacity planning, rather than making decisions based solely on a single price or advertised multiplier.

    7. Conclusion

    Unrounded floating-point numbers can leak quotas because the ratio value often conceals the rational number structure of “used amount / total quota.” Continued fractions and the Stern-Brocot tree provide mathematical tools for recovering fractions from floating-point approximations. Meanwhile, points, model multipliers, input/output weights, and dual-window constraints jointly determine the true available quota of a subscription.

    To determine whether a subscription is cheap, you cannot merely look at the advertised “multiple of usage.” Instead, you should build your own workload model, calculate the quota per unit currency, short window satisfaction, and weekly cap satisfaction, and perform sensitivity analysis. For service providers, standardizing rounding and standardizing rate-limit information are more robust engineering practices. For users, rational modeling and compliant observation are the keys to long-term cost reduction.