Engineering Practices for Handling Hundreds of Trillions of LLM API Tokens per Week
As LLM API usage reaches hundreds of trillions of tokens per week, token throughput becomes a core capacity metric. This article explains how to design and operate large-scale LLM API services through layered architecture, token-based admission control, inference scheduling, continuous batching, caching, usage metering, observability, cost management, and security governance.
Engineering Practices for Handling Hundreds of Trillions of LLM API Tokens per Week
1. What Usage Records Reveal: Token Throughput Is Becoming the Core Capacity Metric
Public API aggregation data shows that the weekly usage of a leading individual model has reached the hundreds-of-trillions-of-tokens level. In some cases, the usage of a single model has exceeded the combined usage of several other models on the rankings. Models in regional markets have also maintained leading usage levels for multiple consecutive weeks.
Regardless of the specific data source, the engineering implication is the same: LLM API services have entered a large-scale phase in which token throughput is a core capacity metric.
Traditional web services commonly use QPS, concurrent connections, and P95 latency to measure capacity. LLM APIs require a more complex capacity model. One request may contain only a few dozen tokens or tens of thousands of tokens in a long context. Input and output tokens may have different processing costs. Streaming responses keep connections open for longer periods. When multiple tenants share inference resources, the system must also manage quota fairness and traffic bursts.
A weekly volume of hundreds of trillions of tokens means that the service must address four problems at the same time:
- High throughput
- Low latency
- Controlled costs
- Stable operations
These challenges cannot be solved through single-machine inference optimization alone.
Therefore, large-scale LLM API engineering should not focus only on growing request volume. It should be broken down into several interconnected areas, including access governance, inference scheduling, cache reuse, usage metering, observability, and security and compliance.
2. Layered Architecture: Turning Usage Volume into a Governable Request Path
For high concurrency, multiple tenants, and long-tail requests, an LLM API service can be divided into five layers, each with clearly defined responsibilities.
Access layer: Handles authentication, key management, tenant identification, request validation, quota checks, rate limiting, circuit breaking, and routing. Requests that exceed quotas or contain invalid formats should be rejected as early as possible to prevent them from consuming inference capacity.
Scheduling layer: Selects inference instances based on model version, context length, priority, tenant tier, and current queue depth. It should support canary releases, model routing, and overload protection.
Inference layer: Executes model inference and supports common optimization techniques such as continuous batching, KV-cache reuse, quantization, and parallel acceleration. This layer should expose metrics such as queue depth, token throughput, and GPU memory utilization.
Caching and reuse layer: Caches reusable content, including frequently repeated requests, system-prompt prefixes, and retrieval-augmented generation contexts. Cache design must distinguish between result caching and prefix caching, with appropriate expiration policies for each.
Data and operations layer: Provides token metering, logging, auditing, monitoring, alerting, cost accounting, and capacity planning. In cloud environments such as Baidu AI Cloud, general-purpose services for object storage, log management, monitoring and alerting, and container platforms can support these capabilities. Specific choices should depend on the team’s existing environment and compliance requirements.
With this layered design, usage growth is no longer treated as a problem for the inference cluster alone. It becomes a system-level engineering challenge that can be managed separately across the access, scheduling, caching, and operations layers.
3. Rate Limiting and Quotas: Moving from QPS Control to Token Budgets
QPS-only rate limiting can create significant distortion. A short request and a long-context request may consume inference resources at very different levels, sometimes by an order of magnitude.
A more appropriate strategy combines:
- QPS rate limiting
- Token budgets
- Concurrency control
Key mechanisms include:
- Tenant-level quotas: Set token budgets by day, hour, or minute to prevent a single tenant’s traffic burst from consuming shared resources.
- Request-level estimation: Estimate resource requirements from the input message length and maximum output token count. Requests that exceed limits can be rejected or downgraded before entering the inference layer.
- Priority queues: Separate interactive requests from batch workloads. Batch jobs can wait in a queue and use idle capacity.
- Fairness policies: When multiple tenants share model instances, use weighted fair queuing to prevent a large tenant from occupying the queue indefinitely.
Example pseudocode:
def admit_request(request, tenant):if not rate_limiter.allow(tenant.id, request.qps):return {"code": 429, "reason": "qps_exceeded"}estimated = estimate_tokens(request.messages) + request.max_output_tokensif estimated > tenant.max_request_tokens:return {"code": 413, "reason": "request_too_large"}if not token_budget.try_consume(tenant.id, estimated):return {"code": 429, "reason": "token_budget_exceeded"}if queue.depth(tenant.priority) > tenant.max_queue_depth:return {"code": 503, "reason": "queue_overload"}return {"code": 200, "admit": True, "estimated_tokens": estimated}
The key principle is not the exact code structure. It is moving resource-consumption checks to the access layer. For streaming output, the service should continue metering actual output tokens during generation and reconcile the budget after the request completes. This prevents estimation errors from accumulating over time.
4. Inference Scheduling and Batching: Exchange Throughput for Cost Efficiency While Protecting User Experience
At hundreds of trillions of tokens per week, inference cost optimization must shift from an individual-request perspective to a queue-level perspective. Common approaches include continuous batching, dynamic batch sizing, separating short and long requests, and model routing.
The core idea of continuous batching is to avoid waiting for a fixed batch to fill. New requests are continuously admitted during inference, while completed sequences are removed from the batch. This can improve hardware utilization, but it also requires the system to handle differences in sequence length, GPU memory fragmentation, and timeout control.
Example pseudocode:
def build_next_batch(waiting_queue, max_batch_tokens, max_wait_ms):batch = []used = 0deadline = now_ms() + max_wait_mswhile waiting_queue and used < max_batch_tokens:req = waiting_queue.peek()cost = estimate_tokens(req.messages) + req.max_output_tokensif batch and used + cost > max_batch_tokens:breakbatch.append(waiting_queue.pop())used += costif batch and (used >= max_batch_tokens or now_ms() >= deadline):return batchreturn []
The service should also adopt tiered scheduling policies:
- Short-context, latency-sensitive requests should use a fast lane with smaller batches.
- Long-context requests and offline jobs should enter a batch-processing lane.
- Cost-sensitive workloads can use smaller models or compressed prompts.
Model routing should not be based solely on model names. It should dynamically consider task type, quality evaluation results, and the tenant’s SLA requirements.
5. Caching, Metering, and Observability: Making Large-Scale Services Operable
High-volume services need an operational loop that is observable, measurable, and financially accountable. Recommended metrics include:
- Access layer: Request volume, rejection rate, rate-limit hit rate, and authentication failure rate
- Inference layer: Input and output token throughput, queue depth, batch-size distribution, P95/P99 time to first token, and P99 completion latency
- Resource layer: Compute utilization, GPU memory utilization, cache hit rate, and instance health
- Cost layer: Token consumption by tenant, token cost by model, and the number of tokens saved through caching
- Quality layer: Timeout rate, truncation rate, retry rate, and abnormal output ratio
A simplified capacity-planning formula is:
Required inference capacity ≈ Peak token throughput × Safety factor ÷ Effective token throughput per instance
The safety factor should account for traffic bursts, the proportion of long-context requests, and failure redundancy.
For systems handling hundreds of trillions of tokens per week, daytime peaks and nighttime batch workloads should be modeled separately. Capacity decisions based on a single average value can easily lead to underprovisioning or inefficient resource allocation.
Caching strategies should also be chosen according to the request pattern:
- Result caching is suitable for highly deterministic requests.
- Prefix caching is suitable for system prompts and fixed knowledge contexts.
- Semantic caching requires caution and must define similarity thresholds and expiration policies.
Every cache hit should record the number of tokens saved. Otherwise, a high cache-hit rate may look positive while producing little or no actual cost reduction.
6. Reliability and Security Governance: Baseline Capabilities for Scale
The larger the request volume, the greater the potential impact of a failure. At minimum, reliability design should include:
- Multi-tenant isolation: Isolate quotas, queues, logs, and keys by tenant to prevent failures from spreading.
- Circuit breaking and degradation: When queues become too deep or error rates increase, automatically fall back to a smaller model, shorten the maximum output length, or return a queueing notice.
- Canary releases for model versions: Roll out new models by tenant or traffic percentage, while preserving rapid rollback capabilities.
- Input and output security: Perform content moderation, sensitive-information detection, and audit logging at the access layer.
- Key and permission management: Rotate keys regularly, apply least-privilege access, and never record plaintext keys in logs.
- Cost circuit breaking: Trigger alerts and limits when token consumption by a tenant or business unit grows abnormally.
7. Implementation Checklist
For a large-scale LLM API service, a practical implementation sequence is:
- Establish token-level metering and tenant quotas.
- Add combined QPS and token-based rate limiting.
- Introduce continuous batching, short- and long-request separation, and prefix caching.
- Complete observability, cost accounting, canary releases, and security auditing.
For systems handling hundreds of trillions of tokens per week, the real competitive advantage is not limited to the model itself. It lies in whether the engineering platform can manage throughput, latency, cost, and stability at the same time.
