An agent loop does not cost one call multiplied by the number of turns, and the difference is not small. The API is stateless, so every turn re-sends everything before it — the system prompt, the tool definitions, and every message and tool result so far. Turn eight sends everything turns one through seven sent, plus what they produced. That makes the cost grow with the square of the conversation rather than with its length, which is why loops that seem cheap in testing are not. This walks the loop turn by turn, applies caching where caching applies, and says which turn overflows the window.
Features
Every turn priced separately, with the history it re-sends
Caching applied to the fixed prefix only, which is the honest model
The same loop priced without caching, for comparison
Counts the tokens re-sent purely because the API is stateless
Says which turn overflows the context window
Batch pricing as a toggle
A per-turn bar chart, so the growth is visible
Rates carrying the date they were checked
How to use the Agent Loop Cost Estimator
Pick a model and how many turns you expect
Enter the fixed prefix, the output and the tool result sizes
Set a realistic cache hit rate
Read the total, the saving, and where it overflows
Example
Input
8 turns, 4K prefix, 1.5K tool results
Output
Turn 8 sends 19.4K tokens — turn 1 sent 4.5K
The growth is the history, not the work.
Common errors & troubleshooting
My real bill is higher than this. — Tool results are usually the culprit — they are the largest and least predictable input. Try the size of your worst tool result rather than a typical one.
The cache saving looks too good. — Only the fixed prefix is treated as cacheable, which is already the conservative assumption. If your prefix changes between turns, set the hit rate lower.
It says the window overflows. — The conversation outgrows the model before the loop finishes. Compaction, context editing, or smaller tool results are the fixes, in that order of effect.
How do I know my token sizes? — Measure one real turn with the token counter and use those figures. The shape of the answer matters more than the precision.
Frequently asked questions
Why does an agent loop cost more than the same work in one call?
Because the whole conversation is re-sent every turn. Ten turns is not ten calls' worth of input — it is the sum of a growing conversation, which is why the cost curve bends upward.
What drives the cost most?
Tool result size, usually by a distance. Output tokens are priced higher per token but there are far fewer of them; a verbose tool that returns a page of JSON each turn is what turns a cheap loop into an expensive one.
Is the cache hit rate realistic at 90%?
For a stable system prompt and a fixed tool list, yes. If your prefix contains anything per-request, it is closer to zero — the cache planner is the tool for finding out which you have.
Should I use batch pricing?
Only if the work is not interactive. It halves the bill and gives up the ability to react, which suits evaluation runs and bulk processing rather than an agent someone is waiting on.
How accurate is this?
It is a model, not a quote. It gets the shape right — the growth, the cache effect, the overflow point — from figures you supply. Published rates change, so the date they were checked is shown next to them.
Related tools
Prompt Cache Planner — Order the blocks of a request so the cacheable prefix is as long as possible.
Context Window Planner — Budget a context window across prompt, tools, history and the reply.
Batch Request Builder — Turn a table of rows into a batch job, with unique ids per request.
LLM API Cost Calculator — Estimate GPT, Claude and Gemini API costs from token counts, with custom price overrides.
SSE Stream Viewer — Paste a raw streaming response and get the text, tool calls and usage back.
Token Counter — Count tokens for GPT, Claude and Gemini live — exact OpenAI counts plus Claude/Gemini estimates.
More AI & Agents tools
Skill Builder — Write a SKILL.md with the frontmatter checked as you type.
Skill Linter — Paste a SKILL.md and see what stops it being matched to a task.
Subagent Builder — Build a subagent definition file with its tools and model set.
Slash Command Builder — Build a custom slash command, with arguments and a tool allow-list.