When developers compare LLM APIs, almost everyone sorts by two columns: fresh input price and output price per 1M tokens. For one-shot chat prompts, that table works. For autonomous coding and pentest agents, it predicts the wrong winner almost every time.
The real token ratio of an agent loop
In a multi-turn harness (Claude Code, Codex CLI, OpenCode, Strix, PentAGI), every step sends:
- The full system prompt and tool schema definitions
- The conversation and tool-call history up to turn
N - A tiny slice of new tokens (the latest command stdout or file diff)
Across a real 14-minute Claude Code session we measured and published (full token breakdown), 96.5% of all input tokens were prefix cache hits. Fresh input and generated output together were a small fraction of the total context processed.
Two pricing models on the exact same 95%-cached loop
Compare two backends serving 10M total input tokens (9.5M cached, 0.5M fresh) and 100K output tokens in a sustained tool loop:
| Component | Uncached-focused pricing ($0.80 / $0.40 cached / $1.50) | Cache-optimized pricing ($0.33 / $0.009 cached / $1.32) |
|---|---|---|
Cached input (9.5M) | $3.80 | $0.0855 |
Fresh input (0.5M) | $0.40 | $0.1650 |
Output (0.1M) | $0.15 | $0.1320 |
| Session total | $4.35 | $0.3825 |
On the same workload, prefix cache read pricing swings the bill by more than 11x - even though the fresh-input prices only differed by 2.4x.
Three engineering details that keep cache hit rates above 90%
- Keep the prefix byte-identical. Injecting a changing timestamp or random UUID at the top of the system prompt invalidates the entire KV prefix on turn 1. Put volatile state at the end of the message array.
- Use sticky session routing across replicas. Round-robin load balancing across stateless GPU workers turns a 95% cache hit rate into a 25% hit rate on a 4-node pool. Route sessions by prefix affinity while draining warm caches gracefully before restarts.
- Never trade tenant isolation for cache hits. Shared prefix caches without cryptographic tenant separation risk cross-account timing or prefix side channels. Enforcing a mandatory per-org HMAC
cache_saltin the gateway keeps cache hits high per tenant while guaranteeing zero cross-org KV reuse, paired with a hard 30-minute idle KV eviction timer.
If you run authorized security harnesses or long-horizon coding agents on abliterated AI models, benchmark your actual session bill with cache hits turned on rather than comparing uncached list prices. You can inspect live agent-loop cost breakdowns with our agent cost calculator or read the Nodecode Cyber v1 specs.

