LLM API Costs: Why Token Consumption Matters More Than Unit Price

    Comparing per-million-token prices is only half the picture when choosing an LLM API. This article explains how token-based billing works, which factors inflate token consumption—fixed context, multi-turn conversations, and output length—and provides a reusable estimation method with sample calculations and Python code to compare providers on total cost per task rather than unit price alone.

    LLM API Costs: Why Token Consumption Matters More Than Unit Price

    Why Comparing Unit Prices Alone Leads to Wrong Choices

    When selecting an LLM service, many teams start by comparing each provider’s “price per million tokens.” That number is useful, but it’s only half of the bill. The total is calculated as:

    Total cost = input tokens × input price + output tokens × output price

    Example: Platform A’s unit price is half of Platform B’s, but completing the same batch of business requests consumes 4x the tokens. Then A’s total cost is 0.5 × 4 = 2x that of B. The cheaper-per-token option ends up more expensive.

    This article covers three things: how token billing works, which factors amplify consumption, and how to compare options using a reusable estimation method.

    The Basics of Token Billing

    A token is the unit models use to measure text. It’s neither a character nor a word. One Chinese character typically maps to 1–2 tokens, and an English word may map to one or more, depending on the model’s tokenizer. The proportion of code, punctuation, and technical terms also affects the result, so texts of the same length can differ significantly in token count. For estimation, use the platform’s tokenizer tool or the usage fields returned by the model—don’t convert by character count.

    A single API call is usually billed in two parts:

    • Input tokens: system prompt, user questions, conversation history, retrieved documents, tool call results, and so on.
    • Output tokens: the model’s generated response, including reasoning (if the model returns it), JSON, code, etc.

    Most platforms charge more for output than input, but the exact difference depends on each provider’s price list. At a 2x price ratio, output tokens that make up 20% of a call contribute roughly 33% of the total cost (0.2×2 ÷ (0.2×2 + 0.8)). Even a modest output share can account for a large cost share.

    In multi-turn conversations, each request typically resends previous history to the model. This repeated content is billed as input tokens. Only when the platform supports prompt caching and the repeated content meets the cache conditions will the matched portion be billed at a lower rate. Cache conditions usually include: the repeated portion sits at the beginning of the prompt, the content is byte-for-byte identical, and the cache is still valid. Whether caching is supported, how large the discount is, and the minimum cacheable length—all of these rules should be checked in the platform’s documentation.

    Three Factors That Amplify Consumption

    1. Fixed Context: Repaid on Every Call

    The longer the context, the more input each call carries. A customer service bot that needs to remember customer profiles, recent chat history, and product summaries can easily accumulate thousands of tokens of fixed context. Whether the user asks about shipping times or the return policy, this content is sent in full every time.

    2. Multi-Turn Conversations: Linear per Call, Quadratic per Session

    At turn t, the input includes the Q&A from the previous t−1 turns. If each turn adds 1,000 input tokens and 800 output tokens, then the 10th call carries 9 × 1,800 = 16,200 tokens of history, and the 20th call carries 19 × 1,800 = 34,200 tokens. Per-call input grows linearly with turn count, while cumulative input across the session grows roughly quadratically. Long conversations get expensive much faster than intuition suggests.

    3. Output Length: More Detail, Higher Cost

    Given the same “summarize this code” request, one model may output 200 words and another 500. Developers often ask the model to reason step by step and explain at length to get more reliable results, which significantly increases output tokens. Output length should be aligned with business needs—not just how much the model can write.

    A Worked Example: Comparing Two Options

    Suppose two options have the following prices (currency units per million tokens; figures are illustrative only):

    Item Option A Option B
    Input price 10 5
    Output price 30 15
    Fixed context 3,000 tokens 8,000 tokens
    New user input per turn 200 tokens 200 tokens
    Output per turn 300 tokens 300 tokens
    Conversation turns 8 8

    The calculation:

    • Fixed input per call: A = 3,000 + 200 = 3,200; B = 8,000 + 200 = 8,200.
    • Cumulative input over 8 turns = 8 × fixed input per call + (0+1+…+7) × (200+300). Since 0+1+…+7 = 28, that’s 28 × 500 = 14,000.
    • A’s cumulative input = 8 × 3,200 + 14,000 = 39,600 tokens; B’s = 8 × 8,200 + 14,000 = 79,600 tokens.
    • Both accumulate 8 × 300 = 2,400 output tokens.
    • A’s cost = 39,600 × 10 ÷ 10⁶ + 2,400 × 30 ÷ 10⁶ = 0.396 + 0.072 = 0.468.
    • B’s cost = 79,600 × 5 ÷ 10⁶ + 2,400 × 15 ÷ 10⁶ = 0.398 + 0.036 = 0.434.

    With these parameters, B’s total cost is slightly lower—about 93% of A’s. B’s unit price is half of A’s, but the extra 5,000 tokens of fixed context eat into that price advantage.

    The conclusion depends on the parameters. If B’s fixed context grows to 9,000 tokens, B’s cost becomes (8 × 9,200 + 14,000) × 5 ÷ 10⁶ + 0.036 = 0.438 + 0.036 = 0.474, exceeding A’s. The two options break even when B’s fixed context is roughly 8,850 tokens. Plug your own business’s real numbers into the calculation instead of borrowing someone else’s conclusion.

    Estimation Code

    1. def estimate_cost(
    2. price_in, # input price, per million tokens
    3. price_out, # output price, per million tokens
    4. fixed_ctx, # fixed context token count
    5. user_in, # new user input tokens per turn
    6. out_per_turn, # output tokens per turn
    7. turns, # number of conversation turns
    8. cache_hit=0.0, # fraction of input hitting cache, 0 to 1, estimated against total input
    9. cache_price=1.0, # billing factor for cached portion, e.g. 0.1 means billed at one-tenth
    10. retry_rate=0.0, # retry ratio, e.g. 0.05 means 5% extra calls
    11. ):
    12. total_in = 0
    13. for t in range(1, turns + 1):
    14. total_in += fixed_ctx + user_in + (t - 1) * (user_in + out_per_turn)
    15. total_out = turns * out_per_turn
    16. billable_in = total_in * (1 - cache_hit) + total_in * cache_hit * cache_price
    17. cost = (billable_in * price_in + total_out * price_out) / 1_000_000
    18. return cost * (1 + retry_rate)
    19. print(round(estimate_cost(10, 30, 3000, 200, 300, 8), 3)) # 0.468
    20. print(round(estimate_cost(5, 15, 8000, 200, 300, 8), 3)) # 0.434

    The cache-hit ratio here is a simplified parameter estimated against total input. The actual hit rate depends on the platform’s prefix rules and how requests are organized.

    The full formula:

    Cost = [input tokens × (1 − hit rate + hit rate × cache factor) × input price + output tokens × output price] ÷ 10⁶ × (1 + retry rate)

    How to Reduce Token Consumption

    1. Trim context. Use a rolling window that keeps only the most recent turns and replace older content with summaries. Key-information extraction keeps only entities, constraints, and unresolved issues. How much you can compress depends on how repetitive the history is—measure it with your own conversation data.
    2. Put static content first and keep it consistent. Place the system prompt and long documents at the beginning of the prompt, keep them byte-for-byte identical across requests to hit the prompt cache, and move dynamic content (current time, user ID) to the end.
    3. Use retrieval instead of concatenating everything. Retrieve relevant snippets from a knowledge base first, then insert them into the context—trading retrieval cost for a large volume of input tokens.
    4. Set max_tokens based on historical data. Start from a percentile of output length for similar tasks (e.g., P95), then adjust based on business feedback. Output habits vary widely across models and tasks; there is no universal fixed value.
    5. Eliminate wasteful calls. Answer common questions directly from a knowledge base or rules, reuse results for duplicate requests, and delegate simple classification to smaller models.
    6. Use structured output. Requiring the model to return only JSON or code blocks reduces explanatory text. But over-compression can omit conclusions or break the format, so validate with quality metrics.

    How to Evaluate Plans

    Unit price alone can’t tell you which plan is cheaper. Compare on “total cost to complete the same task.”

    1. Extract 10–20 representative samples covering short questions, long contexts, and multi-turn conversations.
    2. Define success criteria—for example, code passes tests, or the answer contains required fields.
    3. Run the same samples on each candidate plan and record the fields in the table below.
    4. Compute per-task cost, including failed retries.
    5. Convert manual review and rework hours into cost and include it in the total cost of ownership.
    Sample ID Task Type Input Tokens Output Tokens Calls Retries Passed Cost per Task
    01 Customer support Q&A
    02 Code generation

    A plan with a low unit price but frequent retries can end up more expensive than one with a higher unit price.

    Monitor Every Call

    After launch, log these fields for each call and periodically review consumption trends:

    • request_id: request identifier for tracing.
    • Model name and version.
    • Input tokens and output tokens.
    • Context tokens: length of the fixed context portion.
    • Cache-hit tokens.
    • Retry count.
    • Business task ID, and whether the result met the criteria.

    Do not log user privacy data or credentials—keep only the numbers and identifiers needed for analytics.

    Caveats

    • All prices in this article are illustrative; refer to each platform’s official price list.
    • Estimates are budget references, not final bills. Platforms may have minimum billing units, rate limits, regional pricing differences, and other rules.
    • Cache discounts, tokenization rules, and output lengths can all change with model versions—re-measure periodically with real data.
    • When reducing token consumption, monitor output quality at the same time to avoid sacrificing business outcomes for cost savings.