Self-Hosted LLM Inference Cost per Token: How to Calculate It and Compare Against API Pricing
Whether pay-per-token LLM API pricing loses money is a common debate—but the answer depends entirely on how inference costs are calculated. This article breaks down self-hosted cost per token with verifiable formulas, lists the cost items that are often overlooked, and shows how to make an apples-to-apples comparison against API quotes, helping you decide when self-hosting makes sense. All figures are illustrative assumptions and should be replaced with your own data before use.
Whether pay-per-token LLM API pricing loses money is a frequent topic of debate. What’s often missing from that debate is a shared premise: how exactly inference costs are calculated. This article breaks down self-hosted costs by the inference pipeline, provides verifiable formulas, and points out which costs are commonly overlooked. All hardware prices, electricity rates, and throughput figures are illustrative assumptions and do not represent any vendor’s actual data.
1. Distinguish the Two Pricing Models
Individual subscriptions and enterprise API calls follow different pricing logic. Personal subscriptions are usually a fixed monthly fee with usage caps, often designed to acquire users and build habits. APIs, by contrast, charge per token consumed, with prices directly tied to the inference cost of each call. When discussing whether API pricing is unprofitable, the analysis should focus only on the API segment.
Developers can get a feel for costs through live usage displays. Many coding tools show the token count of the current conversation and its dollar equivalent in real time. These numbers help estimate how many tokens a given type of task consumes and provide a reference point for the cost calculations below.
2. Calculating Self-Hosted Cost per Token
The calculation has three steps: fixed hardware costs, then power and hosting, then capacity.
Step 1: Hardware. Assume one inference node consists of 8 high-end AI accelerators with a total purchase price of $550,000. This is an example value—replace it with actual quotes. With straight-line depreciation over 5 years, monthly depreciation is roughly $550,000 ÷ 60 ≈ $9,167.
Step 2: Electricity. Assume the node’s full-load power draw is 10 kW, running 720 hours per month, consuming 7,200 kWh. At $0.10 per kWh, electricity costs $720. With a data center PUE (power usage effectiveness) of 1.3, the actual electricity cost is about $720 × 1.3 ≈ $936. Rack rental, bandwidth, and cooling must be added separately.
Step 3: Capacity. The monthly token output formula is:
Monthly tokens = Number of cards × Effective per-card throughput (tokens/s) × 3600 × 24 × 30 × Average utilization
Assuming an effective throughput of 1,500 tokens/s per card and 50% average utilization: 8 × 1500 × 86400 × 30 × 0.5 ≈ 15.552 billion tokens. Effective throughput must be measured with your target model, inference engine, and realistic batch sizes—you cannot simply use vendor-specified figures.
Adding depreciation and electricity gives roughly $9,167 + $936 = $10,103 per month. Unit cost: $10,103 ÷ 15,552 (million tokens) ≈ $0.65 per million tokens.
Utilization has a major impact. At 25% utilization, the unit cost is about $1.30 per million tokens—nearly double. At 100% utilization, it drops to roughly $0.32 per million tokens. The cost advantage of self-hosting depends on sustained high load; at low utilization, that advantage shrinks considerably.
3. Commonly Overlooked Costs
The calculation above only covers hardware and electricity for inference. The following costs are not included and must be added in a complete accounting:
- Operations staff: model deployment, monitoring, incident response, and version upgrades.
- Software and licensing: inference frameworks, monitoring, and security components.
- Disaster recovery and backup: redundant nodes are needed to keep the service available during failures.
- Idle capacity: hardware still depreciates and consumes power during low-demand periods.
- Network egress and compliance: bandwidth billing, security audits, and data compliance costs.
- Hardware obsolescence: new accelerator generations improve quickly, and older cards may depreciate faster than expected.
If you use open-source model weights, you don’t need to amortize model training costs. However, self-hosters still bear the engineering effort of evaluation, tuning, and adapting the model to their business.
4. Making an Apples-to-Apples Comparison with API Pricing
API quotes cannot be compared directly against self-hosted unit costs without aligning the scope first. Record the following information:
- Provider, model name, and version
- Date the quote was collected, since prices change frequently
- Input and output prices, per million tokens
- Cached-input pricing, if available
- Batch discounts, if available
- Context length, which affects per-call token consumption
Many providers price input and output separately, so compute a weighted unit price based on your workload’s input/output ratio:
Weighted price = Input share × Input price + Output share × Output price
Only by comparing this weighted price against your self-hosted unit cost can you reach a meaningful conclusion. Note that this comparison only reflects the inference cost relationship. It says nothing about whether the API provider is profitable overall, since providers also bear training, R&D, staffing, and sales expenses.
5. When to Consider Self-Hosting
The decision method is to compare your monthly API spend against total monthly self-hosting costs:
Total monthly self-hosting cost = Depreciation + Power and hosting + Allocated ops staff + Software + Disaster recovery + Idle capacity costs
Self-hosting is worth serious evaluation when API spending consistently exceeds this figure, workloads are stable, and utilization can be kept high over the long term. For smaller-scale operations or teams still iterating rapidly, calling APIs directly offers more flexibility with lower fixed investment.
A hybrid approach is also common: run the stable baseline load on a self-hosted cluster and burst to APIs during traffic peaks. This amortizes fixed costs while retaining elasticity.
6. Conclusion
Under a narrow accounting that only includes inference hardware depreciation and electricity—assuming full capacity and high utilization—self-hosted cost per token can be lower than some API quotes. This result cannot be extended to conclusions about whether API providers are profitable overall, since training, R&D, staffing, and marketing are all outside the calculation. Before making a decision, redo the math with actual quotes, measured throughput, and a complete cost list.
