Wandererfield notes

Essays / cost / context

The Token Bill Nobody Budgets For

Week one of a project is cheap. Week four is not. The gap is not the model getting worse, it is the context getting fatter, and almost nobody prices it in.

Here is a real pair of invoices from the same project, four weeks apart.

Week one: 1.9 million input tokens, 84 thousand output tokens, about $14.

Week four: 7.4 million input tokens, 310 thousand output tokens, about $52.

The work did not grow fourfold. The number of features shipped per week actually went down, because week four was integration week. The sessions just carried more history, more tool schemas, more retrieved context, and more retries. Nobody had budgeted for any of that, because the estimate was built from a single happy-path conversation.

Where the tokens actually go

I instrumented the loop for two weeks. The split, averaged over 140 sessions:

  • System prompt and tool schemas: 11,000 tokens per call, before anything is said. Constant, invisible, and paid on every turn.
  • Conversation history: grows from 2,000 to 60,000+ tokens over a working session. This is the big one, and it is the one people under-estimate because it is gradual.
  • Retrieved files and search results: spiky. A single over-broad search can dump 20,000 tokens you will never read.
  • Retries and loop-backs: the invisible multiplier. Every failed tool call replays the whole context when you retry naively.

The uncomfortable finding: 78% of the bill was context that the model had already seen, repeated because the conversation kept it.

Caching helps, but not the way the pricing page suggests

The published "up to 90% off cached input" number assumes a workload with a stable, long prefix and few edits. My first two weeks looked nothing like that: I edited the system prompt four times a day, added tools mid-session, and let history grow unbounded. My measured cache hit rate was 23%.

After I froze the prefix, the hit rate went to 61%, and the effective input cost dropped about a third. Not 90%. A third, which is still the single best return on an afternoon of plumbing I have ever gotten.

What changed:

  1. Freeze the top of the prompt. System instructions, tool definitions, project conventions, in that order, never edited mid-project. Variants go at the bottom, after the cached block.
  2. Prune at boundaries, not randomly. Cut history when a step finishes, not when the budget alarm fires. A summary of the finished step costs 300 tokens and replaces 12,000.
  3. Never retry the same way twice. If a tool call failed, retry with a shorter context and the error text, not with the full transcript that produced the failure.

Per outcome, not per call

The metric I now track is cost per accepted change, not cost per call. It moves in the opposite direction from the invoice, which is useful.

Example from the same project: week one, $14 for nine accepted changes, about $1.55 each. Week four, $52 for thirty-one accepted changes, about $1.68 each. The invoice quadrupled. The unit cost went up 8%. That is a story about volume, not about waste, and it changes what you do next.

If I had watched only the invoice, I would have optimized the wrong thing.

The 11,000-token tax. Tool schemas are the most under-priced thing in the stack. Twelve tools with rich argument schemas costs about as much as a short article, on every single turn, even when no tool is called. If your cache hit rate is good this is cheap. If it is bad, your tools are eating your budget while you think the model is slow.

What "expensive" actually means

A session that costs $4 and produces a rejected pull request is expensive. A session that costs $40 and replaces a day of integration work is cheap. The number is meaningless without the denominator.

So: count accepted changes. Divide. Then decide whether the context strategy was the problem or whether the work was simply big.

What to steal

  • Log tokens per turn, split into prefix, history, retrieval, output. One afternoon of work; it makes everything else visible.
  • Freeze the prompt prefix. Put variants below the cached block.
  • Prune when a step ends, not when the alarm fires.
  • Track cost per accepted change. Report that number, not the invoice, when someone asks whether the agent is worth it.
Thanks for reading. If it helped, send it to one person.