AI Agent Cost: Where the Money Goes in an Agent Run and 5 Ways to Cut It
AI Agent Cost: Where the Money Goes in an Agent Run and 5 Ways to Cut It
A 20-turn agent run that reads about 59,000 tokens of material gets billed for 656,000 input tokens. Nothing on that invoice is wrong. It's how a stateless model API works, and once you see the shape of it you'll never price an agent job off the rate card again. So let's build one run on paper, price it against a live public price sheet, and see where the money actually goes. Then five ways to cut it, and why I think cost is becoming the skill that separates people who demo agents from people who get paid to run them.
The Price Sheet
Every price below comes from Anthropic's published pricing page, so you can check each one. I'll use Claude Sonnet 5, the mid-tier workhorse: $2 per million input tokens and $10 per million output tokens. A cache hit bills at 0.1x the input price, a 5-minute cache write at 1.25x, a 1-hour write at 2x. The Batch API takes 50% off both directions.
Two details in the same docs make the rest of this post work:
- The context windows page describes progressive token accumulation: each turn's input contains all previous conversation history plus the new message, and earlier turns are preserved completely.
- The pricing page says tool use is billed on everything sent, including tool definitions, tool calls, and tool results.
Put plainly, an agent loop pays for its entire past on every step.
One Run, Priced Turn by Turn
Here's a plausible research agent. These are my assumptions, not anyone's production numbers, so swap in your own:
- A fixed prefix of
6,200tokens: system prompt, tool definitions, and the task. - Each turn, the model writes about
300tokens, a short plan and a tool call. - Each tool call returns about
2,500tokens, which is the pricing page's own estimate for an average fetched web page. - Every turn adds
2,800tokens to the history, and every turn resends all of it.
| 10 turns | 20 turns | 40 turns | |
|---|---|---|---|
| Tokens in the final context | 31,400 | 59,400 | 115,400 |
| Input tokens billed across the run | 188,000 | 656,000 | 2,432,000 |
| Billed input vs final context | 6x | 11x | 21x |
| Cost, no caching | $0.41 | $1.37 | $4.98 |
| Output's share of that cost | 7% | 4% | 2% |
| Cost, with prompt caching | $0.14 | $0.33 | $0.87 |
Three things jump out:
Output is a rounding error. Output costs five times more per token than input on this model, and it's still 4% of the bill at 20 turns. Telling an agent to be terse feels like cost control. It barely moves the number.
Cost grows with the square of the run. Going from 20 to 40 turns multiplies the uncached cost by 3.6, because every new turn resends a longer history than the one before. Your price per token is linear. Your price per task isn't.
The growth term is tool results. The prefix is fixed. What compounds is every page, file, and search result the agent pulls in and then carries forward for the rest of the run.
5 Ways to Cut AI Agent Cost
1. Cache the Prefix, and Keep It Still
Caching takes the 20-turn run from $1.37 to $0.33, which is 76% off. The docs say a 5-minute write pays for itself after one cache read, and a 1-hour write after two.
Two details decide whether you actually get that:
- Cache prefixes are built in a fixed order: tools, then system, then messages. So anything that changes near the top (a timestamp in the system prompt, a reshuffled tool list) turns everything after it into a fresh write.
- The cache lifetime is measured from the start of the request, so a response that takes four minutes to stream leaves about one minute for the next request to reuse it. Slow steps and long pauses quietly break caching. That's what the 1-hour option is for.
2. Put Less Into the History
Tool results are the term that compounds, so the cheapest token is the one you never fetch. Return the three relevant paragraphs, not the whole page. Cap fetch sizes. Clear old tool results once they've been used, and summarize long histories instead of dragging them along. Both of those are documented platform features now: context editing and compaction.
There's a quality argument too. The context windows page says it directly: "As token count grows, accuracy and recall degrade." The bloated run usually isn't just the expensive one. It's the worse one.
3. Load Only the Tools the Job Needs
Tool definitions ride along on every request. The pricing page puts the browser use toolset at about 6,600 input tokens per request and the computer use toolset at about 4,500. Across 20 uncached turns, the browser definitions alone come to 132,000 input tokens before a single page is read. Give each job the smallest tool surface that can finish it.
4. Split Long Runs into Short Ones
The square law cuts both ways. Two 20-turn runs cost $2.74 uncached. One 40-turn run costs $4.98. If a job has natural phases, end each one with a short written handoff and start the next run from that brief instead of from 59,000 tokens of transcript. You pay for the brief once, not for the whole history on every turn.
5. Batch What Isn't Urgent, and Match the Model to the Step
Work that doesn't need an answer in seconds (overnight classification, bulk enrichment, eval suites) can go through the Batch API at half price, and the docs say that discount stacks with caching. Then route steps by difficulty. The pricing page's own advice is Haiku for simple tasks, Sonnet for most production work, and Opus for the hardest reasoning. A run that sends a date-parsing step to the top model is paying for judgment it never used.
One trap when you compare rate cards: the same page notes that Claude 4.7 and later models use a newer tokenizer that produces about 30% more tokens for the same text. A lower price per token isn't automatically a cheaper task. Measure tasks, not tokens.
Every API response reports input, cache read, and cache write tokens in its usage field, so log it per step and you'll know where the money goes instead of guessing.
Where This Is Heading
Per-token prices keep falling. The same page records that a scheduled price increase for Sonnet 5 was cancelled and its launch price made standard. Runs keep getting longer at the same time: current models take a million tokens of context at standard pricing and can write 128,000 tokens in a single response. Put those together and the rate card stops deciding what an agent costs. The architecture decides.
Two developers on the same model at the same price can land 4x apart on the same job, purely on caching, tool surface, and run length. That makes cost an operations discipline, not a procurement one. The person who can say "this job costs 33 cents a run, here's where it goes, and here's what happens at 40 turns" gets trusted with the budget. The person who can't gets their agent switched off the first time an invoice surprises someone. And as businesses shift from buying software to paying for work that gets done, knowing the unit cost of a task is what lets you price that work at all.
Learn It on a Job That Already Exists
The fastest way to get good at this math is to do it on a real job instead of a toy loop. That's the idea behind the Agent Ops Club, which teaches agent operations as a trade. Its eight AI Employees are on GitHub under the MIT license. Free to hire. Yours to run.
The free tier includes those eight employees, the Hire Your First AI Employee walkthrough, the first two Masterclass modules in full, the public trainings calendar, and Agent Ops Chat at three messages a day. No card required.
To be straight about the bridge: the club won't hand you a cheaper model. It gives you real jobs to run and a place to learn the operating side of them. So the next step is to start free, hire your first employee with the walkthrough, and ask it this post's five questions: what's in the prefix, what goes into the history, which tools it loads, how long it runs, and what could wait for a batch.
Want to compare notes with other builders first? There are 335,000+ of them in Vibe Coding is Life: come find us on Facebook.
Comments
No comments yet. Start the discussion.