Sub topic 9
Cost and latency trade-offs
This chapter assumes you can call an LLM API from Python, know what input and output tokens are, and have read the earlier chapters on reasoning tokens and effort settings. It covers what extra thinking costs in money and waiting time, how to estimate both before you ship, and which levers reduce them.
Where the extra cost comes from
A reasoning model produces two kinds of output before you see anything useful: reasoning tokens, then the visible answer. Providers bill both at the output-token rate. Output tokens are usually priced several times higher than input tokens, so a response that is mostly hidden reasoning can cost far more than the same prompt sent to a standard chat model.
The cost of one request is:
cost = input_tokens * input_price + (reasoning_tokens + answer_tokens) * output_priceThree consequences follow from this formula.
- The prompt you write is a small part of the bill. A 300-token question can produce 6,000 reasoning tokens.
- You cannot know the reasoning-token count in advance. It depends on the problem, the model and the effort setting. You can only read it afterwards from the usage fields.
- The reasoning tokens are billed even when you never see them. Some APIs return only a summary of the reasoning, or nothing. The charge is for the tokens the model generated, not for the text you received.
Check your provider's documentation for the exact billing rule. For example, Anthropic models with extended thinking may return a summarized thinking block, while billing is based on the full thinking tokens generated.
Where the extra latency comes from
A language model generates tokens one after another. Each token needs one forward pass, so generation time grows roughly linearly with the number of tokens produced. If the model decodes at 80 tokens per second, 6,000 reasoning tokens add about 75 seconds before the answer even starts.
Latency has three parts:
- Fixed overhead. Network, queueing and reading your input (prefill). This is usually well under a second for short prompts.
- Thinking time. Reasoning tokens divided by decoding speed. This is the part you control with effort or a budget.
- Answer time. Visible answer tokens divided by decoding speed.
Time to first visible token is overhead plus thinking time. With a standard chat model, streaming hides latency because text starts appearing almost immediately. With a reasoning model, the user may see nothing for the whole thinking phase, unless your API streams reasoning summaries.
A worked estimate
You can build a small estimator and run it before any real traffic. The prices and speed below are placeholders. Replace them with your provider's current numbers and your measured decoding speed.
from dataclasses import dataclass
@dataclass
class Prices:
input_per_million: float
output_per_million: float
def request_cost(input_tokens, reasoning_tokens, answer_tokens, prices):
"""Dollar cost of one request. Reasoning tokens are billed as output."""
output_tokens = reasoning_tokens + answer_tokens
return (
input_tokens * prices.input_per_million
+ output_tokens * prices.output_per_million
) / 1_000_000
def latency(reasoning_tokens, answer_tokens, tokens_per_second, overhead=0.5):
"""Return (seconds to first visible token, seconds to finish)."""
first_visible = overhead + reasoning_tokens / tokens_per_second
total = first_visible + answer_tokens / tokens_per_second
return first_visible, total
prices = Prices(input_per_million=1.0, output_per_million=4.0) # placeholder prices
speed = 80 # tokens per second, placeholder
input_tokens, answer_tokens = 300, 150
# Assumed reasoning-token counts for the same task at three effort levels.
scenarios = {"low": 400, "medium": 1500, "high": 6000}
for effort, reasoning in scenarios.items():
cost = request_cost(input_tokens, reasoning, answer_tokens, prices)
first, total = latency(reasoning, answer_tokens, speed)
print(
f"{effort:>6}: ${cost:.4f} per request, "
f"first token {first:.1f}s, done {total:.1f}s, "
f"${cost * 100_000:,.0f} per 100k requests"
)The output:
| Effort | Reasoning tokens | Cost per request | First visible token | Finished | Cost per 100,000 requests |
|---|---|---|---|---|---|
| low | 400 | $0.0025 | 5.5 s | 7.4 s | $250 |
| medium | 1,500 | $0.0069 | 19.2 s | 21.1 s | $690 |
| high | 6,000 | $0.0249 | 75.5 s | 77.4 s | $2,490 |
Moving from low to high multiplies cost by about 10 and waiting time by about 10. The input and the answer are identical in all three rows. Only the hidden reasoning changed.
Reasoning counts vary between requests
The scenario table uses one number per effort level. In practice the count is a distribution. Two requests with identical settings can use very different numbers of reasoning tokens, because the model spends more tokens on problems it finds harder.
This matters for planning:
- Budget on the tail, not the average. If most requests use 1,000 reasoning tokens and a few use 12,000, your p95 latency and your worst-case cost are set by the tail.
- Effort is a hint, not a guarantee. An effort level shifts the typical amount of thinking. A thinking budget is a target the model is trained to respect, and providers describe it as approximate. Neither is a strict cap on quality or time. A hard cap comes from the output token limit, covered in the output limits chapter.
- Measure per request. Log the reasoning-token count for every call. The usage object in the OpenAI example (
output_tokens_details.reasoning_tokens) and the usage fields in other APIs make this cheap.
Costs that multiply the base figure
The per-request numbers above understate real spending in four common situations.
- Retries. If a request hits the output limit during reasoning and returns no answer, you paid for all of those tokens and got nothing. Retrying doubles the cost of that request.
- Multi-step workflows. A pipeline with five model calls pays the reasoning cost five times, and the latencies add up when the calls run in sequence. Agents that call tools in a loop often re-think at every step.
- Long conversations. Each turn resends earlier messages as input. Whether previous reasoning is kept in the context depends on the API. Where it is kept, it adds input tokens on later turns. Check how your provider handles reasoning items or thinking blocks between turns.
- Concurrency limits. A request that takes 75 seconds holds a connection and a rate-limit slot for 75 seconds. Throughput per worker drops by the same factor as latency.
Levers for reducing cost and latency
Apply these in roughly this order, from least to most effort.
- Lower the effort or budget. This is the direct lever. Test one step down before anything else.
- Do not use reasoning for easy requests. Classification, extraction, rewriting and simple lookups rarely benefit from long thinking. A standard model is cheaper and answers sooner.
- Route by difficulty. Send easy requests to low effort or a standard model, and send hard ones to high effort. A cheap classifier, or a simple rule, can pick the route. Routing adds its own cost and a failure mode: a wrong route to the cheap path produces a wrong answer.
- Cap the output. Set a maximum output token value that bounds the worst case. Leave enough room for reasoning plus the answer, or you get truncated responses.
- Shorten the visible answer. Asking for a one-line answer cuts answer tokens, but this saves little when reasoning dominates. Check the usage split first.
- Stream and show progress. If the API offers reasoning summaries, display them. A user watching progress tolerates a wait better than one looking at a blank screen. Streaming does not reduce total time or cost.
- Run non-urgent work in batch. If your provider offers a discounted batch interface, move offline jobs such as evaluations and bulk labeling there.
- Cache repeated input. Prompt caching discounts the input side only. It helps when you resend a long shared prefix, but it does not reduce reasoning tokens.
Cost per correct answer
A fair comparison divides spending by the number of right answers. Suppose you ran 200 test cases at two settings:
| Setting | Accuracy | Cost per request | Cost per correct answer |
|---|---|---|---|
| low | 70% | $0.0025 | $0.0036 |
| high | 92% | $0.0249 | $0.0271 |
Here low effort is about 7.5 times cheaper per correct answer, but it also fails 30% of the time. Whether that is acceptable depends on what a failure costs. If a wrong answer is cheap to detect and retry, low effort wins. If a wrong answer goes to a customer, high effort may be worth the price. The accuracy figures here are illustrative. You measure your own with the comparison loop from the evaluation chapter.
Common mistakes
- Reading only the visible text length. A 100-word answer can hide thousands of billed tokens. Always read the usage fields.
- Testing latency on short prompts only. Reasoning time depends on problem difficulty, so benchmark with realistic hard cases.
- Using one global effort setting. Different features in the same product often need different settings.
- Ignoring time to first token. For interactive use, the pause before the first visible token matters more than total time.
- Setting a thinking budget close to the output limit. On APIs where the limit must exceed the budget, leaving almost no room for the answer produces truncated or empty replies.
Exercise
A reasoning model costs $2 per million input tokens and $8 per million output tokens, and decodes at 100 tokens per second. A request has 500 input tokens, uses 3,000 reasoning tokens, and returns a 200-token answer. Ignoring fixed overhead, what does the request cost, and how long until the first visible token appears? If you lower effort so reasoning drops to 600 tokens, what are the new cost and time to first visible token?
Show answer
First request: input cost = 500 × $2 / 1,000,000 = $0.001. Output tokens = 3,000 + 200 = 3,200, so output cost = 3,200 × $8 / 1,000,000 = $0.0256. Total = $0.0266. Time to first visible token = 3,000 / 100 = 30 seconds. Lower effort: output tokens = 600 + 200 = 800, so output cost = $0.0064 and total = $0.0074. Time to first visible token = 600 / 100 = 6 seconds. The cost falls by about 72% and the wait falls by 80%, but you must still measure whether accuracy on your task stays acceptable.
Exercise
Your service shows a user nothing until the final answer arrives, and users complain about waiting 40 seconds. Name two changes that reduce the perceived or actual wait, and say which one lowers cost.
Show answer
Showing streamed reasoning summaries (where the API provides them) reduces perceived wait without changing cost or total time. Lowering the effort level or thinking budget reduces actual wait and also lowers cost, because fewer reasoning tokens are generated and billed. Routing easy requests to a standard model has the same effect for those requests.