Why Your Agent Bill Exploded: The Quadratic Cost of Context Windows

Warm-Reaction-456 · reddit · 2026-08-11

A developer breaks down why a client's Agent API bill surged 9x: the quadratic cost of context windows. In an agent loop, every turn resends the entire history, meaning early tokens get billed repeatedly. Doubling the run length roughly quadruples the reading cost.

The Black Hole

Logs showed a typical run carried a 14k token base, with 11k just for tool schemas. A 38k token search result was reread 26 times, generating a massive bill. Reasoning is nearly free; re-reading is the real cost.

Optimizations

Post-optimization, the average run now bills 6 tokens for every unique token added, down from 18.

Original post →

More from coding & agent

coding & agent channel →