Only the system prompt carries a cache mark.
Inside one question the tool loop calls the model again after every tool round, and each call resends the question, the model's earlier tool requests and every tool result so far. None of that part is marked, so it is never read from the cache and is paid at the full input price on every round.
- What to change
- Also mark the newest message: at send time, add cache_control {type: 'ephemeral'} to the last content block of the last message (or set the request-level automatic cache_control). Keep the stored history unchanged. Update the budget meter to count cache writes and reads at the same time (see the notes).
- Why it matters
- Each tool round extends the previous request byte for byte, so with a mark on the newest message the next round reads everything before its new tool results from cache at 0.1x the input price instead of paying full price again.
- Estimate
- about 1.2M prompt tokens per 1,000 calls not served from cache (estimate)
What the estimate assumes
3 model calls per question (two tool rounds and the answer, as route.ts:13 and :33 describe); about 10k uncached input tokens per question, inferred from the 5-7 cents per question in route.ts:33 at the prices in lib/budget/pricing.ts; tool rounds of about 3k tokens each; the 3.5k-token tools and system head is already cached. A heavy question (README.md:80, about 40k input) loses proportionally more.