Tiered LLM Subscription and API Metering Architecture: A Practical Guide
This article breaks down a general-purpose architecture for metering and billing large language model services that combine free tiers, subscription plans, and pay-as-you-go APIs. It covers a five-layer design that separates metering from settlement, a unified quota model, an idempotent and replayable usage pipeline, pre-request rate limiting and cost circuit breakers, plan state machines for pausing new sign-ups, observability and reconciliation views, and common pitfalls to avoid. The focus is on building a system that is scalable, auditable, and able to fail safely without hard-coding pricing rules.
1. Background: Why LLM Commercialization Depends on Fine-Grained Metering
The cost structure of large model services is fundamentally different from that of traditional software. Traditional software has a marginal cost close to zero, whereas every inference consumes compute, GPU memory, and bandwidth, so cost grows roughly linearly with call volume. When a service offers free quotas, subscription plans, and pay-as-you-go billing at the same time, the billing system stops being a simple “bookkeeping tool” and becomes a core component for resource scheduling and risk control.
A typical AI assistant service evolved into a three-tier structure: basic capabilities are free to grow the user base; multiple monthly subscription tiers then separate light and heavy users by price; and a pay-as-you-go API is opened for enterprise customers. As the user base grew, the service paused new individual subscriptions at a certain point. In engineering terms, this is equivalent to “stopping incremental writes while honoring existing commitments,” which places clear requirements on the granularity of feature switches and on data consistency. In addition, the compute expansion pressure created by large funding rounds and high valuations can push the billing and quota systems toward being more real-time and more precise.
Setting aside specific product attributes, this article discusses only the general technical problem behind this pattern: how to design a scalable, auditable metering and billing architecture with circuit-breaking capability.
2. Overall Architecture: A Five-Layer Split
Split the system into five layers, decoupled through explicit contracts so that billing logic does not leak into business code.
- Access layer: handles authentication, tenant identification, and request normalization, and produces a unified invocation event.
- Policy layer: determines the plan a request belongs to, available quota, rate-limit thresholds, and priority.
- Execution layer: the inference runtime, which outputs results and also produces resource consumption metrics.
- Metering layer: collects, cleans, and aggregates usage into immutable metering facts.
- Settlement layer: maps metering facts into bills, quota deductions, and risk-control actions.
The key principle is the “separation of metering and settlement.” The metering layer only records what happened and makes no pricing decisions; the settlement layer only calculates amounts based on a versioned price list. This way, price changes, promotions, and compensation do not require rewriting historical facts.
3. Quota Model: A Unified Abstraction for Free, Subscription, and Pay-as-You-Go
The three forms should not be written as three separate codebases, but abstracted as different instances of the same quota model:
Quota {tenant_id // tenantplan_id // plan identifierdimension // metering dimension: tokens, request count, concurrencylimit // upper boundused // consumedwindow_start // cycle startexpire_at // expiration timepriority // preemption priority}
Design points:
- Split dimensions. Distinguish at least input and output metering dimensions, and limit concurrency separately, so that maxing out a single dimension does not make the whole service unavailable.
- Align cycles. Free quotas reset on a calendar-day basis, while subscription quotas reset on the subscription cycle. The two must not share the same window, or quota mismatches will occur.
- Priority and preemption. Free and trial traffic should have lower priority than paid traffic, and low-priority requests should be degraded first when resources are tight.
- Quota inheritance and rollback. If a request fails after quota has been deducted, there must be an idempotent rollback, otherwise users will keep complaining about “vanishing quota.”
4. Metering Pipeline: Idempotency, Exactly-Once, and Replayability
If metering data is lost or duplicated, bills cannot be trusted. The recommended flow is: the runtime produces structured usage events → a message queue buffers them → stream computing performs minute-level aggregation → detail storage and batch settlement.
{"event_id": "uuid-v4","tenant_id": "t-1024","request_id": "r-77","plan_id": "monthly-99","input_tokens": 1820,"output_tokens": 640,"latency_ms": 2310,"status": "success","ts": "2026-07-20T10:11:12Z"}
Engineering constraints:
- Use
event_idorrequest_idas the idempotency key, and deduplicate on the consumer side with a dedup table or idempotent writes, so that duplicate delivery does not cause duplicate billing. - Events are immutable; corrections are made by appending reversal events. Updating historical detail records in place is forbidden.
- Retain raw detail records for at least one full reconciliation cycle; aggregated results must be recomputable, avoiding a situation where “there is only a summary and no source of truth.”
- End-to-end latency targets should be explicit, for example minute-level usage visibility and hourly billing; overruns should trigger alerts.
5. Rate Limiting and Circuit Breaking: Caging Cost Risk
Limits must take effect before a request enters inference, not as an after-the-fact remedy. Recommended multi-stage gates:
- A token bucket for rate limiting to smooth burst traffic.
- A concurrency semaphore to protect GPU memory and the batching queue, preventing queue avalanches.
- Daily/monthly hard quota gates that return a clear error code and a degradation notice once the cap is reached.
- A cost circuit breaker that automatically reduces the maximum generation length or switches to a smaller model when cost per unit time exceeds a threshold.
Illustrative logic:
def admit(req):if not rate_limiter.allow(req.tenant): return reject(429, "rate")if not quota.reserve(req.tenant, req.plan, req.estimate()): return reject(402, "quota")if cost_breaker.tripped(): return degrade(req)return allow()
Note the handling of the gap between estimated and actual usage: the pre-deduction uses a conservative estimate, and settlement reconciles against actual usage with refunds or additional charges, while the difference enters a pending-reversal queue.
6. Subscriptions and Pausing New Sign-Ups: Switch Granularity and Existing Commitments
“Pausing new individual subscriptions” is not simply flipping a switch off in engineering terms. It requires distinguishing four actions: block new creation, allow renewal, allow downgrade, and preserve existing entitlements. The recommended implementation introduces a plan state machine: active / closed_for_new / closed_for_renew / sunset. Both the gateway and the settlement layer read this state, avoiding the inconsistency where “the page allows ordering but the backend rejects the order.”
Existing commitments also require considering whether remaining quota carries over, how refund policies are calculated, and how historical usage connects when downgrading to the free tier. These are rules confirmed jointly by product and finance; the architecture is only responsible for making the rules configurable rather than hard-coding them.
7. Implementation Reference on General Cloud Capabilities
Implementing the architecture above does not require proprietary components; general cloud product categories from the industry are sufficient:
- Object storage: store raw metering detail and bill snapshots, with lifecycle policies for archiving.
- Message queue: absorb peaks and fill valleys, handling high-frequency usage events.
- Container platform: host the inference runtime and elastic scaling.
- Logging and monitoring/alerting: trace request paths and set quota and cost alerts.
- Relational database and cache: store quota counters and the idempotency dedup table.
Using a combination of general Baidu AI Cloud products, you can archive metering detail and bills to object storage, use a message queue to absorb event peaks, run elastic inference on a container platform, and use the monitoring and alerting system to set threshold notifications for quota exhaustion and cost anomalies, completing the loop without introducing extra proprietary dependencies.
8. Observability and Reconciliation
Three views must be established: a tenant-level usage view, a plan-level revenue view, and a resource-level cost view. All three are correlated by the same event_id, and the discrepancy rate should be continuously monitored as a core metric. The recommended reconciliation process is daily incremental checks and a monthly full check, with discrepancies automatically generating reversal tickets.
9. Common Pitfalls Checklist
- Counting only successful requests and ignoring the compute consumed by failed requests, leading to systematically underestimated costs.
- Settling before a streaming output finishes, resulting in missing output metering.
- Charging full price on cache hits, which triggers disputes.
- Quotas not synchronized globally in multi-region deployments, causing overselling.
- Coupling the price list with code, so price changes require a release.
- Lacking a degradation path, so rate limiting directly equals service unavailability.
10. Conclusion
The essence of tiered subscriptions and pay-as-you-go billing is turning uncertain compute costs into a predictable business model, and the key to supporting it is not complex algorithms but idempotent metering, a unified quota abstraction, upfront limits, and a recomputable reconciliation system. Get these four things solid first, then talk about plan design and growth strategy; only then are the system’s stability and commercial sustainability guaranteed.
