0:01 A coding agent that takes 50 steps to fix a bug can cost about $6. Let it take 100 steps, and it isn't $12. It's $22. Twice the steps, more than three times the bill. And most of that money buys nothing new. It pays for the model to read the same text again, on every step. But the same 50 steps can cost 80 cents.
0:30 Same model, same steps, same text. One setting, and one habit. Across a team, every day, that's the gap between an agent you can afford to leave running, and one that gets switched off. So where does an agent's money actually go? And how do you stop it running away?
0:59 What you pay for
Here's the plan. What you pay for. Why the bill grows so fast. Caching, which makes the repeats cheap. And budgets, which make it stop. So what exactly are you paying for? Tokens. The pieces of text the model reads, and writes. Reading is called input, and writing is called output. They're priced per million tokens. On Anthropic's list, Claude Sonnet 5.5 costs $2 per million tokens in, and $10 per million out.
1:36 That's five times more for writing, because the model writes one token per trip. And it's five times on every Claude model on the list. Thinking counts as writing. Every token of it is billed as output, even the part the app never shows you. So a one-line answer after a long think can cost more than a page of text. So you'd guess writing is most of the bill. In an agent, it's the other way round.
2:06 Take the sales agent's four laps, from the episode on context. On every lap, it read the whole form: the instructions, the tools, the question, and every result so far. That adds up to about 128,000 tokens read, and only about 160 written. So even at a fifth of the price, reading is over 99% of the bill. The whole run costs about 26 cents.
2:35 And that isn't just our run. The team behind the Manus agent says its agents read about 100 tokens for every one they write.
2:47 How fast does that add up?
So how fast does that add up? The sales agent read its big result only once, on its last lap. Real jobs keep going. Manus says a typical task for its agent takes about 50 tool calls. And on every one, the whole form goes back in. So take a coding agent, fixing a bug in 50 steps. Each step is one trip to the model. It reads the whole form, and writes a tool call.
3:17 Your code runs the tool, and the result goes on the end of the form. Say the instructions and tools come to 10,000 tokens. And each step adds 2,000 more: 500 the model wrote, and 1,500 from the tool. Those are round numbers we picked, not measured ones. Step one reads 10,000 tokens. Step two, 12,000. Step 50 reads 108,000, then stops asking for tools, and the run ends.
3:48 Stand each step's form next to the last, and you get a staircase. What you pay for is the whole staircase. Add up every step, and the model read nearly 3 million tokens. But the job itself is only about 100,000 tokens long. You paid to read it about 27 times. At Sonnet's price, that's about $6. Almost all of it for reading. Now let it take 100 steps.
4:18 The staircase is twice as wide, and its top step is nearly twice as tall. So the area under it is nearly four times as big. In dollars, $22, not $12. This is called quadratic growth. The bill grows with the square of the number of steps. Every step pays for every step before it. And a team of agents means a staircase for each one. Anthropic's numbers work out to a team using nearly four times the tokens of a single agent.
4:51 At that rate, our $6 run would cost over $20. Anthropic's own advice: save it for work that's worth it.
5:03 Do you really have to pay full price, to read the same text again?
So do you really have to pay full price, to read the same text again? Put two steps side by side. Step 50 starts with everything from step 49, word for word. Only the last 2,000 tokens are new. Reading isn't free for the provider either. Every token goes through the model's dials. But when a request starts exactly like one it has just read, the provider can keep that work, and skip it.
5:33 This is called prompt caching. The start that matches is called the prefix. And reading it back from the cache is called a cache hit. On Sonnet, a cache hit costs a twentieth of the normal price. Storing it the first time costs a quarter extra. And it's faster. In a test Anthropic ran in 2024, a long prompt started answering in 2.4 seconds, not 11.5.
6:03 It doesn't store the answer. The model still writes a fresh one. It only skips re-reading the start. Back to the 50 steps. With caching, each step stores its 2,000 new tokens, and reads the rest from the cache. $6 becomes 80 cents. On Claude, you switch it on with one setting. OpenAI and Google switch it on for you, with similar discounts. A few catches. There's a minimum length, but an agent's form is far past it.
6:37 And on Claude, the cache lives about five minutes, reset each time it's used. Pause for longer, say, waiting on a person, and the next step misses the cache. It has to store the whole form again, at 25 times the price of a hit. Or buy an hour, at twice the price to store. The biggest catch: the match has to be exact, from the very first token. Change one token near the top, and everything after it is read fresh, and stored again.
7:12 So what breaks it? A timestamp at the top, down to the second. Editing or reordering the tool list in the middle of a run. Switching models halfway, since each model keeps its own cache. And editing an old step, even just to trim it. So here's the habit. Keep the start of the form fixed: instructions and tools first, new things, even new instructions, only at the end. And never rewrite what you've already sent.
7:43 The share of input read from the cache is called the cache hit rate. Anthropic's own coding-agent team treats a low one as an incident, like an outage.
7:58 Does caching fix the bill?
So does caching fix the bill? It makes the staircase cheap. It doesn't stop it growing. With caching, 200 steps cost about what 50 cost without it. $6, again. And a run that never finishes never stops costing. Remember how the loop ends. The model stops asking for tools, or your code stops it. A budget is how your code decides when.
8:27 It's a few limits. A maximum number of steps. A token budget for the whole run. A dollar cap. And a time limit. Anthropic's toolkit for building agents, the Claude Agent SDK, has a step limit and a dollar cap built in. Both are off, unless you set them. Every reply says how many tokens it used. So after each step, your code adds up the cost, counts the steps, and checks the clock.
8:57 Cross any line, and the loop stops. Or, on Claude, tell the model its budget, so it wraps up first. And one trap. The maximum length you set for one reply doesn't cap the run. Every step gets its own. Then make the steps cheaper. Send easy jobs to a smaller model, the routing from the episode on patterns. On prompts up to 100,000 tokens, Claude Haiku 5.5's list price is a twentieth of Sonnet's.
9:29 Pick it when the job starts, though. Switching mid-run throws away the cache. When the form gets long, compaction, from the episode on context, swaps the old steps for a short summary. The staircase drops back down, and climbs again from there. And for work that can wait, there's the batch API. It takes a pile of requests, and answers within a day, usually within the hour, at half price. It's no use inside a loop.
9:59 But every region's sales summary, overnight? Half price.
10:07 Where does an agent's money go?
So where does an agent's money go? Mostly into reading. The same form, read again on every step, a little longer each time. Every step pays for every step before it. Caching makes the repeats cheap, as long as the start stays exactly the same. And budgets stop the run, before it runs away. Let a run go on long enough, though, and money isn't the only thing that piles up.
10:37 Small mistakes do too. Next: step fourteen, and why long runs fall apart.