AI agents · intermediate · About 10 minutes
The agent bill that grew 5 times in a month
A coding agent's monthly bill went from $1,200 to $6,700 while the number of tasks rose by a fifth. Find where the money went before you cut the wrong thing.
You look after the team's AI coding agent and its budget.
What happened
Your team uses an AI coding agent to fix failing tests. It reads the code, runs the tests, edits files and runs the tests again until they pass.
The agent's line on the bill was $1,200 in August and $6,700 in September. The team ran about 20% more tasks in September. The model and its price did not change. Finance would like an explanation and a plan by Friday.
The incident is made up. How things work in it is real, with sources at the end.
The evidence
Everything you need is here. Read it before you decide.
| August | September | |
|---|---|---|
| Turns (model calls) per task | 12 | 40 |
| Conversation size at the first turn | 20,000 tokens | 20,000 tokens |
| Conversation size at the last turn | 50,000 tokens | 120,000 tokens |
| Input tokens processed, whole task | 420,000 | 2,800,000 |
| Output tokens written, whole task | 50,000 | 60,000 |
| Input tokens read from cache | 0 | 0 |
The team's price is $3 per million input tokens and $15 per million output tokens.
To help the agent debug, someone changed its setup to paste the full output of every test run into the conversation, not just the failures. A test run prints about 2,500 tokens.
while not done:
reply = client.messages.create(
model=MODEL,
system=AGENT_INSTRUCTIONS, # same text every turn
tools=TOOLS, # same text every turn
messages=conversation, # everything so far, sent again
)
conversation.append(reply)
conversation.append(run_tools(reply)) # test output goes in hereYour decisions
Decision 1 of 2
Decision 1
Where did the money go?
Decision 2
What do you change first?
What went wrong
An agentAgentA model that uses tools in a loop, deciding each next step from what the last one returned, until the task is done. is a model calling tools in a loop, and the model keeps nothing between calls. To continue, each turn sends the instructions, the tool definitions and the whole conversation so far. So the bill does not follow the size of the conversation. It follows the size of the conversation added up over every turn.
That is why the bill grew so fast. In August a task took 12 turns and topped out at 50,000 tokensTokenThe small piece of text a language model reads and writes, often part of a word. Prices, limits and the context window are all counted in tokens.. In September the full test output made the conversation grow faster, the agent took more turns to sift through it, and each of those turns resent everything before it. Anthropic gives the same shape for a 40-turn task: about 2.8 million input tokens processed, though the conversation never passes 120,000.
Two levers work on this directly. Keep the conversation small, because every token you add is paid for again on every later turn. And cache what repeats: with prompt caching, the unchanged start of the request is read at 0.1 times the normal input price, after a first write that costs 1.25 times for the default 5-minute cache.
Keep these
- An agent pays for its whole conversation on every turn. Cost grows with turns times size.
- Before cutting a bill, split it into input and output, and check input first for an agent.
- Trim what goes into the conversation, and cache the parts that never change.
The ideas behind it
LessonSame price per token, smaller bill: what a job costsSources
Where each fact comes from
This page was last checked against these sources on 14 October 2026.
- 1What a task costs on Opus 5.5
Anthropic · 14 October 2026
A task that grows from 20,000 to 120,000 tokens over 40 turns processes about 2.8 million input tokens, though the conversation never grows past 120,000. Each turn sends the conversation so far.
- 2Prompt caching
Anthropic, Claude API documentation · 14 October 2026
Prompt caching covers the prompt in the order tools, system, then messages, up to a marked point. The default cache lifetime is 5 minutes. A 5-minute cache write costs 1.25 times the base input price and a cache read 0.1 times.
- 3Building effective agents
Anthropic · 14 October 2026
An agent is a model using tools in a loop, based on feedback from its environment.