Controlling token cost
Agent costs surprise people because the shape is unintuitive. Understanding where the money goes makes most of it avoidable.
Why it grows superlinearly
Every turn resends the entire conversation. Turn ten includes turns one through nine.
A twenty turn conversation does not cost twenty times a single turn. It costs closer to the sum of one, two, three and so on, because the input grows each time. Long sessions are where budgets go.
Output is several times the price of input
Across providers, output tokens cost roughly three to five times input tokens.
This means a verbose model that explains its reasoning at length costs far more than the token count of your prompt suggests. Asking for concise output is a genuine cost control, not just a style preference.
The changes that actually move the number
Prompt caching. The single biggest win for repeated context. Cached reads typically cost around a tenth of normal input. If you send the same system prompt and documents on every request, caching pays for itself almost immediately.
Shorter sessions. Start fresh when a task is done. This cuts cost and improves quality at the same time, which is rare.
Fewer connected tools. Every tool schema is resent every turn. Ten unused MCP servers is a permanent tax.
Right sized models. Not everything needs the frontier model. Classification, extraction, and formatting are handled well by small models at a fraction of the price. Route by task.
Batch anything not interactive. Batch APIs are commonly half price for work that can wait.
Trim tool output. A test run piped through tail instead of dumped whole. See managing tool output.
Measure before optimising
Log tokens per conversation, then look at the distribution rather than the mean.
Costs are almost always dominated by a small number of very long conversations. The average conversation is fine; the tail is what you are paying for. Optimising the average is wasted effort.
Set limits that actually stop things
Providers offer spend limits and alerts. Set them, because a runaway loop can spend a lot before anyone notices, particularly overnight.
Also cap turns per task in your harness. An agent stuck retrying the same failing command will keep paying for it until something stops it.
Estimating before you build
Work out tokens per call, calls per day, and price per million, and you have a monthly figure. The token cost calculator does this across models, and the ordering is often surprising.
Estimate before committing to a model. Switching later means re-validating all your prompts.
Watch for pricing changes
Providers change prices, and introductory rates expire. Anything you priced six months ago deserves a re-check.
This is why the pricing data on this site carries a checked date. Treat any pricing table, including ours, as a starting point rather than a guarantee.