Prompt caching cut the bill for a 30-step agent run 6.6x: $3.38 → $0.51
The model remembers nothing, so at each of 30 steps the agent re-sends the tools, the rules and the entire history. It's like forwarding a colleague the whole chat with every new message. In a hypothetical example, the model read 1.63 million tokens even though the last request weighed only 96 300. Without caching the task costs $3.38; with caching it costs $0.51, which is 6.6x cheaper. Keep the unchanging parts at the start of the request and the new parts at the end, or the cache won't kick in.
AI-processed from Habr AI; edited by Hamidun News
Picture a support agent that goes to the knowledge base and the CRM 30 times in a row. The model remembers nothing between calls, so at every step the code around it (called the harness) re-sends everything: tool descriptions, rules and the full history of steps. A token is a chunk of text: the unit in which the model reads and in which the money is counted.
In a hypothetical example from the first part of the series "AI Engineering for Those Breaking In," the model read 1.63 million tokens over 30 steps, even though no single request exceeded 96 300. Without caching the task costs $3.
38; with prompt caching it costs $0.51, which is 6.6x cheaper.
If you build or pay for agents, this arithmetic directly affects your budget.
What an AI engineer does and why the model "remembers nothing"
On hh.ru, as of October 28, 2026, there are 1 458 job postings mentioning "AI agent," 1 261 mentioning LLM, 520 mentioning RAG and 245 mentioning MCP. "Prompt caching" appears in only 13 postings and tokens in 19. Companies want to build agents en masse, but they barely ask about cost.
Following Chip Huyen ("AI Engineering"), the author separates the roles. An ML engineer trains a model. An AI engineer takes a ready-made one, such as Claude or GPT, and builds a system around it: feeds in data, connects tools, checks the output and watches the cost. For this engineer, the model is an external service like a database, except that it answers in text and sometimes gets things wrong. According to the 2026 Stack Overflow survey, 73% of developers write code with assistants and agents every day.
The model itself executes nothing. It either answers in text or asks "call the function get_weather for Moscow," and your code runs the function. In Anthropic's documentation, the agent loop is an ordinary while loop: request, tool call, result, request again, until the model answers with text. Every request is assembled in the same order: tools, system prompt, history.
You extend an agent through MCP (an open standard for connecting tools and data), skills (folders with instructions; only a description of about 100 tokens sits in the context), subagents (helpers with their own context that return only the result) and hooks. A hook is your script tied to a harness event: it can block an action, ask a human or run a linter. The author's rule: a skill advises, a hook guarantees.
How much 30 agent steps cost
Sonnet 5.5 prices as of October 28: $2 per million input tokens and $10 per million output tokens. The scenario is hypothetical: 12 thousand tokens at the start of every request (tools and system prompt), 200 tokens for the first message, and at each step a 400-token model response and a 2 500-token tool result.
By the last step the request weighs 96 300 tokens, less than a tenth of the context window. But every step pays again for everything before it, so over 30 steps the model read 1.63 million tokens, 17 times more. The model's responses add up to about 12 thousand tokens, so nearly all the money goes to input. The total without caching is $3.38.
Language affects cost separately. The author ran a small measurement on three pairs of identical texts (documentation, prose, code), about 1 000 characters per language. On Sonnet 4.6 and Haiku 4.5, Russian took 1.6 times more tokens than English; on Sonnet 5.5, 1.27 times more. The cause is not Russian (402 tokens became 415) but English: it grew from 252 to 327 tokens because of a new way of splitting text. The sample is small; treat it as a rough guide, not a study.
How the cache delivers 6.6x and how not to break it
At step 30, the model has already read almost everything in the request at step 29: the same tools, the same prompt, the same history. The cache does not reprocess the repeated beginning and charges 5–10% of the price for it. You place a marker (up to four are allowed) showing how far into the request to save.
The next request hits the cache only if the beginning matches completely, down to the character. The cache lives for 5 minutes, and each hit extends its lifetime; for an extra fee you can keep it for an hour. The minimum for new Claude models is 512 tokens; if a request is shorter, there is no error, the cache simply doesn't turn on.
With caching, the same requests cost $0.51 instead of $3.38. Breaking it is easy: changing a tool description invalidates the whole request, while web search or the current time in the system prompt invalidate the prompt and the history. Changing tool_choice or adding an image wipes out the history.
What to do in practice: start with a single request, and prefer a chain over an agent as long as the steps can be written out in code. Keep the unchanging parts at the start, don't change the set of tools mid-session, and don't put dates or random IDs at the beginning. Check the usage field: if cache_read_input_tokens is almost always zero, the cache isn't working. Hand noisy work to subagents, move long instructions into skills, and make mandatory checks hooks. Give the agent a way to check itself, such as tests, a build or a browser; otherwise it will declare "done" too early.
Caveat: the calculation is hypothetical, and real savings depend on the length of the task, the pauses between requests and the stability of the beginning of the request. In the second part of the series, the author will cover reliability, including idempotency and durable execution; in the third, the difference between a chain and an agent, using a support agent as the example.
- Nov 6, 2026AI Agent Reply Costs Vary 100x: From 0.94 ₽ to 121.57 ₽ per Message
- Nov 6, 2026Devin Review 2.0 cuts code review costs by 82%: a PR now costs $0.25–0.75
- Nov 6, 2026ChatGPT and Claude silently picked a side in 6 of 6 test conflicts to get a green CI
- Nov 6, 2026Keystone plugin teaches Claude Code to set up an LLM gateway: 8 skills, keys kept out of chat
Key Questions Answered
What an AI engineer does and why the model "remembers nothing"?
On hh.ru, as of October 28, 2026, there are 1 458 job postings mentioning "AI agent," 1 261 mentioning LLM, 520 mentioning RAG and 245 mentioning MCP. "Prompt caching" appears in only 13 postings and tokens in 19. Companies want to build agents en masse, but they barely ask about cost. Following Chip Huyen ("AI Engineering"), the author separates the roles. An ML engineer trains a model.
How much 30 agent steps cost?
Sonnet 5.5 prices as of October 28: $2 per million input tokens and $10 per million output tokens. The scenario is hypothetical: 12 thousand tokens at the start of every request (tools and system prompt), 200 tokens for the first message, and at each step a 400-token model response and a 2 500-token tool result. By the last step the request weighs 96 300 tokens, less than a tenth of the context window.
How the cache delivers 6.6x and how not to break it?
At step 30, the model has already read almost everything in the request at step 29: the same tools, the same prompt, the same history. The cache does not reprocess the repeated beginning and charges 5–10% of the price for it. You place a marker (up to four are allowed) showing how far into the request to save. The next request hits the cache only if the beginning matches completely, down to the character.
Test Frontier LLMs & Autonomous Agents in One Workspace
Run Claude Opus 5.5, GPT-6, Gemini 3.1, and DeepSeek side-by-side in Nomad AI (nomadnet.ai) — unified model routing, deep research, and multimodal workflows under one subscription.
The AI world, distilled — once a week
Seven stories that actually mattered, hand-picked. No noise, no reposts, no press releases.
Done! Check your inbox for a confirmation.