Field notes
Prompt caching, and the rest of the bill
Most agent bills are 70 percent repeated context. Caching is the cheapest engineering win available.
Nearly every agent bill I have audited had the same composition. Output tokens were a rounding error. Input tokens were the bill, and most of those input tokens were the same content being resent turn after turn.
That is good news, because repeated identical content is the cheapest thing in the world to optimize. Here is the order I work in, from highest return to lowest.
Step zero: know your composition
Before changing anything, break your token spend into four buckets: system and rules, tool definitions, retrieved material, and conversation history. Add output as a fifth for completeness.
Teams are consistently surprised. I have seen tool definitions alone account for a quarter of spend on an agent with too many tools. You cannot prioritize what you have not measured, and the measurement is one field in your span logging.
Step one: cache the stable prefix
Providers price cached input tokens far below fresh ones. The mechanic that matters is ordering: the cache works on a prefix, so everything stable must come first and everything volatile must come after.
- System prompt and rules. Identical every run.
- Tool definitions. Identical until you ship a change.
- Stable reference material. Policies, schemas, style guides.
- Few-shot examples, if you use them.
- Then, and only then, task state, retrieval, and history.
Verify with your provider's cache-hit metrics rather than by assumption. Log cached and uncached input tokens as separate fields so a regression is visible on a chart instead of on an invoice.
Step two: stop sending what you do not need
Caching makes repeated context cheap. Removing it makes it free, and usually improves quality at the same time.
- Trim tools per task. If a job type only uses four tools, do not ship twelve. Fewer options also means fewer wrong choices.
- Compress history past a threshold. Keep recent turns verbatim, replace older ones with a structured state summary of decisions and constraints.
- Rerank retrieval down to three to five passages. Retrieve widely, pass narrowly.
- Cap tool output. Return the top N plus an omitted count. Unbounded results are a cost and a quality problem at once.
The full reasoning behind these cuts is in context engineering is the whole job now.
Step three: route by difficulty
Using one frontier model for every call is the most common source of avoidable spend. Most agent turns are not hard.
- Small model. Classification, routing, formatting, yes-no decisions, short summarization of clean text.
- Best model. Structured extraction from messy input, drafting anything a customer will read, multi-step reasoning, code.
- Escalation path. Try small, validate the output against a schema, escalate on failure. This gives you cheap throughput with a quality floor.
Every route gets its own eval slice before it ships, per LLM evals that actually catch regressions. Routing without measurement is how quality quietly slides.
Step four: stop paying for repeated work
- Deduplicate identical requests. Agents call the same tool with the same arguments inside a single run more often than you would believe. A short-lived response cache removes it.
- Cache derived artifacts. If a document's extraction is deterministic, store it keyed on a content hash and never pay twice.
- Batch offline work. Anything not user-facing goes through batch endpoints where available, at a substantially lower rate.
- Kill loops early. A run that spins for thirty turns is pure waste. Turn caps and repeat detection are cost controls as much as reliability controls.
Eighty-one percent of their input tokens were a system prompt being resent, uncached, because a greeting with the user's first name sat above it.
The metric to actually watch
Total spend is a vanity metric. Track cost per successful outcome, split by job type. It captures the thing you care about, catches silent retry storms, and makes optimization arguments concrete. A change that halves cost per success without moving eval scores is unambiguously good. A change that halves cost and drops accuracy four points is a decision, not a win.
Pair it with a daily spend alert and a hard kill switch above it. AI systems fail expensively, and the failure is usually a loop rather than an outage.
A one-day plan
- Log cached and uncached input tokens separately by span.
- Reorder your prompt so every stable block sits before every volatile one. Verify cache hits.
- Trim the tool list per job type.
- Add history compression and cap tool output size.
- Route one obvious task class to a smaller model with eval coverage.
- Ship a cost-per-success chart and a daily spend alert.
That is a day of work and it typically removes most of the bill. If you want it done and verified against your own traces, cost review is part of the AI production readiness audit, and agent builds ship with caching and routing in place from the start.
Frequently asked
How does prompt caching reduce cost?
Providers charge much less for input tokens they can serve from a cache. Since an agent resends the same system prompt, tool definitions, and reference material on every turn, caching that stable prefix removes the largest repeated charge on your bill.
What should go in the cached prefix?
Anything identical across turns and runs, in this order: system prompt, tool definitions, stable reference material, then few-shot examples. Everything volatile goes after it. One changed byte early in the prefix invalidates everything after it.
Does model routing hurt quality?
Not if you route by task difficulty rather than by hope. Classification, routing, and formatting run fine on small models. Extraction, drafting, and multi-step reasoning need your best one. Measure each route with evals before shipping it.
What is a realistic cost reduction?
On agents built without cost discipline, 60 to 80 percent is a normal result from caching, context trimming, and routing combined, with no measurable quality loss. The first pass is usually the cheapest engineering work available.
Want this shipped in your stack?
The $1,000 AI audit gets you a ranked action plan in 48 hours.
90-minute live review of your workflows, agents, retrieval, permissions, evals, costs, and observability. Fee credits toward the build.

Written by
Alex Cinovoj, TechTide AI
Founder and CTO of TechTide AI, a Columbus, Ohio AI-automation agency, and co-host of the Automation Vibes podcast. 13 years of mixed IT across support, systems, cloud, architecture, and engineering, with the last 2 years on AI implementation. Lovable Champion and community leader, and has completed Anthropic Academy courses in Agent Engineering, Claude Code, MCP, and Context Engineering.
More on Production reality
AI agent security, what actually breaks
The breaches I get called into are never clever. An agent held a key it should never have held, and nobody was watching the log.
AI agent memory, what to persist
Most agent memory systems are a vector store and a hope. Memory is a schema problem first.
A RAG pipeline that survives real documents
Your retrieval is not bad. Your PDF parser gave the embedder a wall of ligatures and page furniture.