How to Reduce Claude Sonnet 4.5 Token Costs in Agents
Claude Sonnet 4.5 is already the value pick, but an unmanaged agent loop can still cost more than it should. The culprit is almost always repeated context: every turn re-sends the whole conversation and all prior tool results. Fixing that cuts costs by 60-90% on long sessions.
How does prompt caching help?
Anthropic’s prompt caching stores a prefix of the conversation and bills reused tokens at roughly a tenth of the normal input rate. You mark a cache breakpoint after your system prompt and the stable part of the context. On a 30-turn agent session, most turns reuse that prefix, so the bulk of input tokens becomes cache reads instead of full-price tokens.
How do you trim tool results?
Tool outputs are the silent budget killer. A single git log or directory listing can be thousands of tokens, and it gets re-sent every subsequent turn unless you manage it.
- Truncate large outputs before appending them to history.
- Summarize long results into a few lines once they are no longer needed.
- Drop raw file dumps after the model has acted on them.
In one common harness, this alone halved per-session cost.
What settings bound the bill?
Three config values do the heavy lifting:
max_tokens— cap output; Sonnet tends to over-explain, and output is the pricier direction.- Max turns — stop the loop at 15-25 rather than letting it run until it “feels done.”
- Context window budget — track cumulative tokens and compact history past a threshold.
Pair these with the same hybrid routing used elsewhere: keep minimax-m2 as a cheap workhorse for simple turns and call Sonnet only where quality matters.
What is a realistic saving?
An unmanaged 30-turn session on a mid-sized repo can hit 400k-800k input tokens. With caching on the stable prefix and tool-result trimming, the billable fresh input can drop below 100k. On Sonnet’s input rate, that is the difference between a few dollars and well under a dollar for the same work.
What do you give up?
Caching adds a little latency on the first turn and code complexity in your harness. Trimming tool results risks cutting a detail the model later needs — keep the last relevant result intact. Neither change touches model choice, so answer quality on the actual task is unaffected.
Quick Summary
- Prompt caching bills reused prefix tokens at roughly a tenth of input price.
- Trim or summarize large tool outputs before appending them.
- Cap
max_tokens, set 15-25 max turns, compact long history. - A 30-turn session can drop from 400k-800k fresh input tokens to under 100k.
- Adds modest harness complexity; task quality stays the same.
Last updated September 2026.
