Tiered Pricing and API Operations for Large Language Model Services

    This article explains how to design tiered billing for LLM services, covering free tiers, subscriptions, and pay-as-you-go APIs. It details billing models with token-based metering and code examples, rate limiting with token buckets, quota management, authentication, usage tracking and reconciliation, capacity control strategies, and a pre-launch checklist for operating a paid model service reliably.

    1. Why Service Operations Should Combine Free and Paid Tiers

    Once LLM capabilities move from experimentation to production services, the first challenge a team faces is usually not model quality, but how to match costs with supply. Inference consumes compute, and compute has a clear unit cost. A completely free service will see costs grow linearly with users. Charging from day one, however, makes it hard for developers to evaluate the service and build usage habits.

    As a result, most services adopt a tiered design: basic capabilities are open to everyone to lower the barrier to trying the product, while advanced capabilities are offered through subscriptions or pay-as-you-go billing to cover real costs. This combination serves three core goals: control the cost per request, tie payment to actual usage, and reserve sufficient capacity for paying users.

    2. Three Common Monetization Models

    1. Free basic features

    The free tier typically limits input length per request, daily call volume, or concurrency. Its purpose is to let users evaluate the service, not to carry production workloads. Free-tier limits should be documented and surfaced through explicit error codes rather than silent degradation.

    2. Membership subscriptions

    Subscriptions suit individual users and small teams. A fixed monthly or annual fee buys a quota and priority queuing. The hard part is defining the quota. If quotas are counted by number of requests, the cost difference between long-text requests and short Q&A gets flattened. A better approach is to convert quotas into a unified unit, such as token counts or compute credits.

    3. Pay-as-you-go open APIs

    APIs for developers and enterprises are usually billed on actual usage. Billing accuracy matters more than the price itself because it directly affects user trust. The billing system must record the input volume, output volume, model type, and timestamp of every call, and support daily or monthly reconciliation.

    All three models can coexist. Individual users subscribe, application developers use the API, and the free tier absorbs new users. The key is ensuring every user always knows which tier they belong to and how much quota remains.

    3. Key Points in Billing Model Design

    3.1 Choose a Unified Metering Unit

    The metering unit determines billing fairness. Counting input and output tokens separately is a common choice because inference cost correlates roughly with both lengths. Output is usually priced higher per unit than input, since generation requires step-by-step computation.

    3.2 Billing Function Example

    The following example shows the basic logic of pricing input and output separately. The unit prices are hypothetical values for demonstration; actual values should be determined from your own cost accounting.

    1. def calc_cost(input_tokens: int, output_tokens: int,
    2. price_in_per_k: float, price_out_per_k: float) -> float:
    3. """Calculate the cost of a single call based on per-1K-token prices, in yuan."""
    4. if input_tokens < 0 or output_tokens < 0:
    5. raise ValueError("token counts cannot be negative")
    6. cost_in = input_tokens / 1000 * price_in_per_k
    7. cost_out = output_tokens / 1000 * price_out_per_k
    8. return round(cost_in + cost_out, 6)

    Three implementation details deserve attention. First, monetary calculations should use fixed-point or decimal types to avoid accumulating floating-point errors. Second, unit prices should be read from a configuration center with effective timestamps recorded, so historical bills can be recomputed. Third, output volume is only known after the call completes, so billing events are typically written asynchronously after the response finishes.

    3.3 Separate Pre-Authorization from Settlement

    For pay-as-you-go requests, the system generally pre-authorizes first—confirming the balance can cover the maximum possible cost of the request—then settles based on actual usage after the request completes, refunding any overcharge. The pre-authorized amount can be estimated from the maximum output length. This prevents balance overdrafts without rejecting legitimate requests due to overly conservative estimates.

    4. Rate Limiting and Quota Control

    Rate limiting and quotas are two different mechanisms. Rate limiting controls request rate per unit of time to protect service stability; quotas control total usage within a billing cycle to enforce commercial rules. They should be implemented separately and enforced uniformly at the gateway layer.

    4.1 Token Bucket Rate Limiting

    The token bucket is a widely used rate-limiting algorithm. It allows short bursts while keeping the long-term average rate within a configured value.

    1. import time
    2. class TokenBucket:
    3. def __init__(self, capacity: float, refill_rate: float):
    4. self.capacity = capacity # maximum bucket capacity
    5. self.refill_rate = refill_rate # tokens refilled per second
    6. self.level = capacity # currently available tokens
    7. self.last_ts = time.monotonic()
    8. def allow(self, cost: float = 1.0) -> bool:
    9. now = time.monotonic()
    10. elapsed = now - self.last_ts
    11. self.level = min(self.capacity, self.level + elapsed * self.refill_rate)
    12. self.last_ts = now
    13. if self.level >= cost:
    14. self.level -= cost
    15. return True
    16. return False

    In production, bucket state must be stored in shared storage; otherwise, multiple gateway instances cannot see the same user’s request volume. Buckets can be created per user ID and per endpoint, with different capacities and refill rates for different tiers.

    4.2 Quota Validation

    Quota validation happens before a request reaches the model. The typical flow is:

    1. Parse the access credential to identify the user and their tier.
    2. Query usage and remaining quota for the current billing cycle.
    3. Estimate the maximum cost of this request and compare it with the remaining quota.
    4. If quota is insufficient, return a clear error code with the remaining quota and reset time.
    5. If quota is sufficient, allow the request and record the pre-authorized amount.

    Error responses should distinguish two cases: transient rate limiting uses HTTP 429 with a retry interval, while exhausted quota should explain that the user needs to upgrade or wait for the next cycle. Mixing the two leaves users unable to tell whether to retry or pay.

    5. Authentication and Tiered Permissions

    API access credentials should be individually revocable, support scoped permissions, and be bindable to specific projects or applications. Never hardcode credentials in clients or code repositories; inject them through environment variables or a secrets management service.

    Tiered permissions typically cover three aspects: the list of accessible models, the maximum length per request, and concurrency limits. Centralizing these parameters in plan configurations lets you adjust commercial policy without changing code.

    6. Usage Tracking and Bill Reconciliation

    Billing problems usually originate in the data pipeline. A recommended practice is to write billing events to an independent event stream, then let downstream jobs aggregate them into daily and monthly reports.

    Key requirements include:

    • Every billing event carries a unique identifier so duplicate deliveries never cause double charging.
    • Event records include request time, model identifier, input volume, output volume, cost, and the associated plan.
    • Aggregated results are periodically sampled and reconciled against raw events, with alerts on discrepancies.
    • For failed requests, whether they are billed must be clearly defined and documented.

    General-purpose cloud capabilities—message queues, object storage, and monitoring/alerting—can handle event delivery, detail archiving, and anomaly detection respectively. For example, on Baidu AI Cloud, billing events can be written asynchronously to storage through a message queue, with scheduled jobs generating reconciliation reports. When selecting technologies, prioritize your team’s existing stack and evaluate operational costs.

    7. Capacity Management and Admission Policies

    Model service capacity usually has an upper bound. When demand exceeds supply, common responses include:

    • Gradual rollout: Release access to new users proportionally while observing cost and stability.
    • Queuing: Requests beyond the concurrency limit enter a queue and receive an estimated wait time.
    • Pausing new registrations: Temporarily close new subscriptions for a tier when capacity is tight, while maintaining service quality for existing users.

    Pausing new registrations is an operational decision. It should be announced in advance, with the scope of impact and recovery conditions explained, and existing subscribers’ renewal and usage rights preserved. Engineering teams should implement these policies as configurable switches rather than ad-hoc code changes.

    8. Pre-Launch Checklist

    Before officially enabling pay-as-you-go billing, verify each of the following:

    1. Billing prices, quota conversion rules, and free-tier limits are documented with version numbers.
    2. The billing function passes unit tests covering zero usage, oversized inputs, and abnormal inputs.
    3. Pre-authorization and settlement flows are fully tested under timeout, retry, and partial-failure scenarios.
    4. Rate-limiting parameters are validated in a load-testing environment, and 429 responses with retry intervals behave as expected.
    5. Billing details can be queried by user, date, and model.
    6. Anomalous-usage alerts are configured, including per-user spikes and abnormally expensive single requests.
    7. The credential revocation process has been rehearsed, and new requests are rejected within an acceptable time after revocation.
    8. Terms of service and refund policies have passed legal review.

    9. Conclusion

    The essence of tiered pricing is keeping cost, quota, and price aligned. The free tier lowers the barrier to evaluation, subscriptions provide predictable usage capacity, and pay-as-you-go covers high-frequency and production scenarios. The technical priorities are a unified metering unit, risk control through pre-authorization and settlement, separating rate limiting from commercial rules via token buckets and quotas, and ensuring billing accuracy through a reliable event pipeline. With these pieces designed properly, a service can balance user growth against cost control.