How to Calculate the Cost per Token for Self-Hosted Large Language Models

    A practical guide to calculating the per-token cost of self-hosted LLM inference. It explains how to account for hardware, power, operations, software, redundancy, throughput, utilization, and input/output pricing, then compares the result with usage-based API costs using break-even analysis.

    1. Why Measure Self-Hosted Deployment by Cost per Token

    The key question in a self-hosted deployment is whether the cost per unit of output can be lower than that of a usage-based service after the team takes on hardware and operational responsibilities.

    The right basis for comparison is the unit cost—not the purchase price of a server or its monthly lease fee. Monthly infrastructure cost represents only the total expense. Cost per token is what allows a direct comparison with usage-based pricing.

    2. What Makes Up the Cost?

    1. Hardware

    Purchased hardware is a one-time expense and should be amortized over its useful life, commonly three to five years, and allocated to each month. Leased hardware is charged by the month or by a specific usage period. These two models use different accounting methods, so both should be converted to a consistent monthly cost before comparison.

    2. Power and Data Center Costs

    Accelerators typically consume significant power. Electricity and cooling costs also vary with system load. Estimates should use actual power consumption multiplied by operating time and should include colocation or data center fees where applicable.

    3. Operations Staff

    Deployment, monitoring, version upgrades, and incident handling all require engineering resources. These costs should be converted into a monthly amount based on engineer-days or equivalent staffing costs.

    4. Software and Redundancy

    Inference services, monitoring, alerting, and other infrastructure components have ongoing maintenance costs. Production environments also commonly require standby or redundant nodes. Redundancy increases total cost and can reduce the effective service time available for serving requests.

    3. Throughput Determines Unit Cost

    Large-model inference involves two metrics that are easy to confuse.

    The first is per-request speed, measured in tokens per second. This is the generation speed experienced by an individual user.

    The second is total system throughput, measured as the total number of output tokens generated by the server per second. Online inference services often use scheduling techniques such as continuous batching to process multiple requests together. As concurrency increases, the speed of each individual request may decrease while total system throughput rises.

    For unit-cost calculations, use the total throughput under stable operating conditions rather than the peak speed of a single request. Estimating with per-request speed can significantly understate costs. Using the theoretical maximum system throughput can overstate actual capacity.

    A practical approach is to run load tests and record total throughput and time to first token at different concurrency levels. Then select the concurrency range that meets the target latency requirements and use its measured throughput as the basis for the calculation.

    4. Formula for Calculating Cost per Token

    The basic formula is:

    1. Cost per unit (CNY per million tokens)
    2. = Total monthly cost (CNY) ÷ Effective monthly output (million tokens)

    Effective monthly output is calculated as:

    1. Effective monthly output
    2. = Average total throughput (tokens/s)
    3. × Seconds per month
    4. × Average utilization

    Using a 30-day month:

    1. Seconds per month = 2,592,000

    The following example uses hypothetical figures for illustration only.

    Assume:

    • Total monthly cost: CNY 300,000
    • Average total throughput: 600 tokens/s

    Full utilization: 100%

    Monthly output is approximately 1.555 billion tokens, or 1,555 million tokens.

    1. Cost per million tokens
    2. = 300,000 ÷ 1,555
    3. ≈ CNY 193

    Average utilization: 60%

    Monthly output is approximately 933 million tokens, or 933 million tokens.

    1. Cost per million tokens
    2. = 300,000 ÷ 933
    3. ≈ CNY 321

    With the same hardware, reducing utilization from 100% to 60% increases the unit cost by approximately 66%. Utilization is one of the most frequently overlooked variables, yet it has one of the greatest effects on the result.

    5. Break-Even Analysis Against Usage-Based Pricing

    Let:

    • P = usage-based price in CNY per million tokens
    • C = monthly self-hosting cost in CNY

    The break-even monthly usage is:

    1. Break-even monthly usage (million tokens)
    2. = C ÷ P

    For example, if the monthly self-hosting cost is CNY 300,000 and the usage-based price is CNY 100 per million tokens:

    1. Break-even monthly usage
    2. = 300,000 ÷ 100
    3. = 3,000 million tokens

    That equals 3 billion tokens per month.

    If actual monthly usage is below this level, usage-based inference is generally more economical. If usage exceeds it, self-hosting may provide a cost advantage.

    Many services price input and output tokens separately, and prices may vary by plan. The calculation should therefore track input and output usage independently and use the prices that actually apply to the selected pricing plan.

    6. Common Mistakes

    1. Incorrect Unit Conversion

    One hundred million tokens equals 100 million-token units, not 10,000 million-token units. For example, 2 billion tokens should be converted to 2,000 million tokens.

    A unit conversion error can change the result by a factor of 100 and is one of the most common calculation mistakes.

    2. Counting Only Output Tokens

    Input tokens also consume compute resources and memory. If the pricing model charges for input, input and output usage must both be included in the calculation.

    3. Assuming Full Utilization

    Real-world traffic usually has peaks and valleys. Assuming 100% utilization will underestimate the unit cost. Use the average utilization derived from historical traffic instead.

    4. Ignoring Redundancy and Downtime

    Standby nodes, maintenance windows, and recovery time after failures all reduce the effective service time. These factors should be deducted when calculating the available production capacity.

    5. Ignoring Depreciation and Technology Refresh Cycles

    The residual value of purchased equipment is affected by the pace of technology changes. Setting the depreciation period too long will underestimate monthly costs, while setting it too short will overestimate them.

    7. Example Calculation Code

    The following language-independent example illustrates the calculation steps:

    1. monthly_cost = 300000 # Total monthly cost in CNY
    2. throughput = 600 # Average total throughput in tokens/s
    3. utilization = 0.6 # Average utilization
    4. seconds = 30 * 24 * 3600 # Seconds per month
    5. tokens_m = throughput * seconds * utilization / 1000000
    6. # Monthly output in million tokens
    7. unit_cost = monthly_cost / tokens_m
    8. # Cost per million tokens in CNY
    9. Output: monthly output tokens_m million tokens,
    10. unit cost unit_cost CNY per million tokens

    For an actual estimate, replace throughput and utilization with load-test and monitoring data. The monthly cost should also be broken down into hardware depreciation or leasing, power, operations, software, and redundancy.

    8. Conclusion and Selection Guidance

    Self-hosting provides greater control over data and allows deeper customization. However, its unit cost is likely to be lower than usage-based inference only when demand is stable, utilization is relatively high, and the team has the operational capability to run the infrastructure.

    A practical evaluation process is:

    1. Use real business traffic patterns to run load tests and measure total throughput at different concurrency levels.
    2. Calculate historical average utilization.
    3. Apply the measured throughput and utilization to the unit-cost formula.
    4. Compare the result with usage-based pricing item by item.
    5. Verify all units and pricing rules before drawing a conclusion.