Self-Hosting LLM Inference: A Practical Path from Quota Limits to Cost Control
This article explains how quota limits shape what a business can build on LLM APIs. It walks through a usage and cost model for comparing pay-as-you-go, subscription, and self-hosted inference. It also covers the main technical factors in self-hosting: VRAM planning, throughput techniques such as quantization and dynamic batching, and service packaging with rate limiting.
1. The Starting Point: Quota Limits Determine What Your Business Can Do
Many developers have run into this situation. Free or low-cost quotas are enough during the early stage of a project. Once the business grows, the quota is no longer enough. The cost, validity period, and scope of each pricing tier are not always clear. The quota problem is essentially a cost problem. It determines how many requests can be handled per unit of time, how much context a single task can consume, and whether features can launch and run stably.
To understand this, break “quota” into three measurable metrics:
- Request volume and concurrency: how many requests can be accepted per unit of time.
- Token throughput: how many input and output tokens can be processed per unit of time.
- Per-request latency: the time from when a user sends a request to when they receive the complete result.
These three metrics constrain each other. Higher concurrency usually increases latency per request. Longer context lengths reduce overall throughput. Therefore, when discussing quotas, first identify which metric the business values most.
2. Do the Math First: Build a Usage and Cost Model
Before deciding whether to self-host, estimate your actual usage and compare the costs of different options. You can estimate the monthly cost of pay-as-you-go calls with the following formula:
Monthly cost = monthly requests × average input tokens × input price + monthly requests × average output tokens × output price
Self-hosting costs include hardware depreciation or rental fees, electricity or data center fees, operations staff, and business losses caused by failures. The example below uses hypothetical prices and fees to demonstrate the calculation method. Use the official pricing and your real bills for the service you use when working with actual figures.
from dataclasses import dataclass@dataclassclass UsageProfile:requests_per_day: int # Average daily requestsavg_input_tokens: int # Average input tokens per requestavg_output_tokens: int # Average output tokens per requestdef monthly_tokens(profile: UsageProfile, days: int = 30) -> int:per_request = profile.avg_input_tokens + profile.avg_output_tokensreturn profile.requests_per_day * days * per_requestdef api_monthly_cost(profile: UsageProfile, price_per_million_tokens: float) -> float:# Assume input and output use the same price for simplicityreturn monthly_tokens(profile) / 1_000_000 * price_per_million_tokensdef self_host_monthly_cost(hardware: float, ops: float, power: float) -> float:return hardware + ops + powerdef break_even_tokens(self_host_cost: float, price_per_million_tokens: float) -> float:"""Monthly token volume at which self-hosting cost equals pay-as-you-go cost."""return self_host_cost / price_per_million_tokens * 1_000_000if __name__ == "__main__":profile = UsageProfile(requests_per_day=5000, avg_input_tokens=800, avg_output_tokens=400)price = 10.0 # Hypothetical value, 10 units per million tokensself_cost = self_host_monthly_cost(hardware=6000, ops=2000, power=500)print("Total monthly tokens:", monthly_tokens(profile))print("Pay-as-you-go monthly cost:", round(api_monthly_cost(profile, price), 2))print("Self-hosted monthly cost:", self_cost)print("Break-even monthly tokens:", round(break_even_tokens(self_cost, price)))
Under the assumptions above, the total monthly token volume is about 180 million, and pay-as-you-go cost is lower than self-hosting cost. The break-even point is about 850 million tokens per month. This result shows that self-hosting only pays off when usage is high enough and hardware utilization stays stable. For most early-stage projects, pay-as-you-go calls are usually cheaper.
3. Three Ways to Get Compute Capacity
| Dimension | Pay-as-you-go | Subscription or Quota | Self-Hosted Inference |
|---|---|---|---|
| Upfront cost | Low | Low | High |
| Cost predictability | Varies with usage | Depends on plan terms | Mostly fixed spending |
| Control | Low | Low | High |
| Operations burden | Small | Small | Large |
| Data retention | Depends on service terms | Depends on service terms | Fully controllable |
| Suitable stage | Prototypes and small to medium scale | Teams with stable usage | High throughput, strong privacy, or custom needs |
The right choice depends on your usage curve and business constraints. It should not depend on the short-term reaction to a single quota change.
4. Key Stages of a Self-Hosted Inference Service
4.1 VRAM Determines the Model Size You Can Deploy
You can roughly estimate the VRAM that model weights require as: parameter count × bytes per parameter. For a 7-billion-parameter model, FP16 uses 2 bytes per parameter, so the weights take about 14 GB. INT8 takes about 7 GB, and INT4 takes about 3.5 GB.
Actual deployment must also reserve space for the KV cache, activations, and runtime overhead. Higher concurrency and longer context increase KV cache usage. Therefore, hardware selection must consider model size, target concurrency, and maximum context length together.
4.2 Common Methods for Improving Throughput
- Quantization: lower weight precision to reduce VRAM usage and improve speed. Before launch, use your business evaluation set to confirm that the quality loss is acceptable.
- Dynamic batching: combine multiple requests into one computation to improve hardware utilization. The trade-off is that latency for individual requests may increase, so balance throughput against latency.
- Limiting maximum context length: prevent a few very long requests from filling the cache and affecting other requests.
- Prefix caching: reuse previously computed results for repeated system prompts to reduce redundant computation.
4.3 Service Packaging
Run the inference process in a container, and configure health checks and automatic restarts to keep the service available. Standardize the external interface on a common HTTP chat API format. This way, when clients switch backends, they only need to change the address and authentication information. They do not need to modify business logic.
Below is a simple token bucket rate limiter. You can use it to control the request rate for a single client or a single project:
import threadingimport timeclass TokenBucket:def __init__(self, rate_per_sec: float, capacity: int):self.rate = rate_per_sec # Tokens added per secondself.capacity = capacity # Maximum bucket capacity, i.e., the number of burst requests allowedself.tokens = float(capacity)self.updated = time.monotonic()self.lock = threading.Lock()def allow(self) -> bool:with self.lock:now = time.monotonic()elapsed = now - self.updatedself.tokens = min(self.capacity, self.tokens + elapsed * self.rate)self.updated = nowif self.tokens >= 1:self.tokens -= 1return Truereturn Falselimiter = TokenBucket(rate_per_sec=5, capacity=10)for i in range
