Sub topic 7
How providers price tokens
This chapter assumes you can read basic Python, have called an LLM through a chat or completion API, and are comfortable with simple arithmetic and unit conversion. It covers how a provider turns token counts into a bill. Later chapters cover reading usage data and estimating whole conversations.
The basic model
Providers bill by the token, not by the request, the minute, or the word. Each call has two metered quantities:
- Input tokens: everything you send. This includes the system prompt, the conversation history, and the new user message.
- Output tokens: everything the model generates in reply.
Prices are quoted in dollars per million tokens. A listing might read "$3 per million input, $15 per million output". Those numbers are placeholders in this chapter, not real rates. Check your provider's current price page before you plan a budget.
The formula for one call is:
cost = (input_tokens × input_price + output_tokens × output_price) / 1,000,000Why output costs more
Output tokens usually cost several times more than input tokens. A ratio of 3x to 5x is common. The model reads the whole input in one parallel pass. It produces output one token at a time, and each new token needs another pass through the model. Generation therefore uses more compute per token, and providers pass that on in the price.
This has a practical effect. A long answer can cost more than a long prompt, even when the prompt has many more tokens.
Worked example
Take a call with 2,000 input tokens and 500 output tokens. Use the placeholder prices of $3 per million input and $15 per million output.
- Input: 2,000 × 3 = 6,000
- Output: 500 × 15 = 7,500
- Sum: 13,500
- Divide by 1,000,000: 0.0135
The call costs $0.0135. Output is only 20% of the tokens (500 of 2,500) but 55.6% of the cost (7,500 of 13,500).
The same arithmetic in Python:
def estimate_cost(input_tokens, output_tokens,
input_price_per_million, output_price_per_million):
return (
input_tokens * input_price_per_million
+ output_tokens * output_price_per_million
) / 1_000_000
# Placeholder prices in dollars per million tokens, not real rates.
cost = estimate_cost(2000, 500, 3.0, 15.0)
print(f"${cost:.4f}") # $0.0135Price differences between models
Providers sell several models at different price points. A small, fast model can cost a small fraction of a large one per token. The large model may do better on hard tasks. Model choice is often the biggest single lever on your bill, and a later chapter returns to it.
| Factor | Effect on price |
|---|---|
| Model size or tier | Larger models cost more per token |
| Direction | Output tokens cost more than input tokens |
| Volume of tokens | Cost scales linearly with the count |
| Caching or batch options | Some providers discount these; terms vary |
Common errors
- Mixing up units. Prices are per million tokens. Dividing by 1,000 instead of 1,000,000 gives a result 1,000 times too high.
- Using one price for both directions. Applying the input price to output tokens underestimates the bill.
- Ignoring the output limit. If you set a high maximum output, a long reply can cost more than you planned. Budget with the maximum, then compare with what you actually see.
- Forgetting history. Every turn resends earlier messages as input, and you pay for them again each time.
- Treating the numbers as stable. Prices change and differ by model and provider. Keep them in configuration, not hard-coded across your codebase.
Exercise
Exercise
A call sends 10,000 input tokens and receives 1,000 output tokens. The placeholder prices are $2 per million input tokens and $10 per million output tokens. What is the cost of the call, and what share of it comes from output?
Show answer
Input: 10,000 × 2 = 20,000. Output: 1,000 × 10 = 10,000. Total: 30,000 / 1,000,000 = $0.03. Output accounts for 10,000 / 30,000, which is one third (about 33%) of the cost, even though it is only 1,000 of 11,000 tokens (about 9%).
Exercise
Why does a provider usually charge more per output token than per input token?
Show answer
The model processes input tokens together in one pass, but it generates output one token at a time, with a further pass for each token. Generation therefore costs more compute per token, and the price reflects that.