How the math works
An agent works in a loop: the model reads the task, calls a tool, reads the result, and decides what to do next. Every call re-sends the conversation so far, so the input grows each step.
- Input at step i = starting context + (i − 1) × context added per step
- Total input for n steps = n × start + added × n(n − 1) / 2
- Cost = Σ over steps of (new input × input price + cached input × cache-read price + output × output price), × (1 + retries), × the batch discount if used
Where a provider charges more above a prompt length (a long-context tier), that step is priced at the higher rate. Where it charges to write to the cache, new input is priced at the cache-write rate when caching is on.
Worked example: a 12-step research task on Claude Sonnet 5.5
Start with 6,000 tokens of instructions and tools, add 2,500 tokens of search results and pages each step, and write 500 tokens per step. Over 12 steps that is 237,000 input tokens and 6,000 output tokens. At $2.00 per million input and $10.00 per million output, the task costs $0.534. With prompt caching serving 70% of the repeated input, it costs $0.311.