Polycracker Guides · Token Measurement
How to Test LLM Token Usage (Input vs Output)
Provider dashboards tell you how much you spent—not why a single agent turn burned forty thousand prompt tokens. This guide shows how to separate input from output tokens, replay the same workload before and after tuning, and use Polydyno as an open-source dynamometer so finance and engineering agree on the numbers.
Why input and output must be measured separately
Every completion API call charges two counters. Input tokens are everything the model reads: system prompts, tool schemas, retrieved documents, prior turns, and pasted source files. Output tokens are what the model generates: assistant text, reasoning traces where exposed, and structured tool arguments. Optimizing only one side misses the real bill. A coding agent with a modest two-hundred-token reply can still attach eighteen thousand tokens of repository context on the input side.
Teams that merge both numbers into a single “tokens per request” metric routinely misallocate effort. They prune assistant verbosity while leaving MCP tool dumps and unbounded chat history untouched. Separate measurement makes the fix obvious: attack the lane that actually dominates spend for your workload profile.
Baseline instrumentation without production risk
Start with a fixed harness: three to five representative tasks your agents run daily (refactor a module, write a test
file, triage a ticket). Capture the raw request body your client sends—not an aggregated monthly graph. Log
usage.prompt_tokens and usage.completion_tokens (or the vendor-equivalent fields) on every
call, tagged by workflow name and turn index.
Run the harness twice: stock (current IDE integration, default context gathering) and tuned (after you apply AST pruning, history caps, or a signed map from The Tuning House via Polycracker ECU). Keep temperature, model version, and task wording identical. The delta between runs is your shred rate—this is what Polydyno automates when you strap a profile to the bench.
{
"workflow": "fix-flaky-test",
"turn": 2,
"model": "gpt-4.1",
"usage": {
"prompt_tokens": 14280,
"completion_tokens": 412,
"total_tokens": 14692
},
"input_ratio": 0.972
}
Worked example: ten-turn coding agent
Consider a ten-turn session fixing integration tests. Output stays disciplined—roughly four hundred tokens per turn—but input grows because each turn re-sends the full file tree snippet and prior diffs. Below is a simplified per-turn table (token counts rounded from a real Polydyno profile).
| Turn | Input tokens | Output tokens | Input share | Cumulative input |
|---|---|---|---|---|
| 1 | 4,200 | 380 | 92% | 4,200 |
| 2 | 6,100 | 410 | 94% | 10,300 |
| 3 | 7,850 | 395 | 95% | 18,150 |
| 4 | 9,400 | 420 | 96% | 27,550 |
| 5 | 11,200 | 405 | 97% | 38,750 |
After turn five the session has consumed 38,750 input tokens versus only 2,010 output tokens. At blended input pricing of $2.50 per million and output at $10 per million, input already costs about $0.097 while output adds merely $0.020. The optimization target is unmistakably the prompt payload, not shorter answers.
Translating tokens into monthly burn
Once you have per-task averages, extrapolate with simple arithmetic—avoid hiding assumptions in spreadsheets. Multiply average input and output per successful task by daily task volume and working days. Add a twenty percent buffer for failed or retried turns (see our guide on stopping AI agent thrashing).
| Metric | Stock agent | After ECU tune | Change |
|---|---|---|---|
| Avg input / task | 18,400 | 5,900 | −68% |
| Avg output / task | 520 | 505 | −3% |
| Tasks / day (team) | 120 | 120 | — |
| Monthly input tokens | 55.2M | 17.7M | −37.5M |
| Est. monthly API cost | $25,000 | $8,000 | −$17,000 |
These figures mirror the head-to-head lanes on the Polycracker overview. Your absolute dollars differ by model list price, but the ratio between stock and tuned input should be reproducible when the harness is fixed.
Using Polydyno as the dynamometer
Dashboards aggregate; dynamometers isolate. Polydyno runs adversarial and drift profiles
against your prompt pipeline so you can publish shred percentages with invariant checks (tests still pass, types still
line up). Wire it into CI as a gate: fail the build if input tokens per profile exceed the signed ceiling in your
tune.jwt map from The Tuning House.
A minimal Polydyno invocation records both sides of the meter. Store artifacts next to release tags so finance can audit a quarter later without re-running live models.
# Example profile summary (polydyno report excerpt)
profile: react-repo-medium
turns: 8
prompt_tokens_total: 47200
completion_tokens_total: 3840
prompt_tokens_per_turn_avg: 5900
shred_vs_baseline: 67.8%
invariants_passed: 14/14
What to capture in every test run
Consistency beats exotic analytics. For each run, archive: (1) frozen model ID and API version; (2) hashed system prompt; (3) serialized messages array byte length and tokenizer count; (4) list of tools/MCP servers attached; (5) turn index; (6) prompt and completion token counts; (7) wall-clock latency. When input spikes, diff (3) and (4) against the prior turn— that is where MCP and tool schema bloat usually appears.
If you route traffic through Polycracker ECU on 127.0.0.1:8000, enable its request
trace mode to see pre- and post-prune token estimates on the same HTTP call. You get an instant A/B without changing your IDE plugin.
Acceptance criteria before you roll out a tune
- Median input tokens per profile drops at least thirty percent with zero failed invariants on Polydyno.
- Output tokens stay within five percent of baseline (so you are not “saving” by starving answers).
- p95 latency improves or holds flat—input shrink should not explode re-fetch loops.
- Finance signs off on extrapolated monthly savings using your real task volume table.
When those gates pass, promote the map to production seats and keep weekly Polydyno runs to catch drift. Context habits regress quietly when engineers add new MCP tools or paste monorepo READMEs into chats.
Common measurement mistakes
Counting only the final turn. Multi-turn agents charge input on every turn; summing the last request understates burn by an order of magnitude. Ignoring cached prompt discounts. Some providers bill cached prefixes differently; tag those lines so you do not confuse cache hits with structural shred. Mixing models in one baseline. Tokenizers differ; compare like for like. Testing on toy repos. Run against the messiest internal service you have—optimizing hello-world gives false confidence.
For the remediation playbook once you have trustworthy numbers, continue with how to decrease LLM token usage fifty to seventy percent.
Shadow mode and production sampling
You do not need to block developers on day one. Run Polycracker ECU in shadow mode: compute post-prune token estimates and log deltas while still forwarding the stock payload upstream. Compare shadow numbers to billed usage in the provider console weekly. When median estimated shred matches Polydyno benchmarks, flip the active prune bit for that workflow.profile slice.
Sample production traffic at low rates—one in fifty agent sessions is enough for large teams—tagging session IDs with cost center and repo. Store aggregates in the same artifact bucket as Polydyno runs so auditors trace a dollar figure back to a specific message array and tool manifest. Shadow mode also surfaces outliers: one internal wiki MCP tool might add six thousand definition tokens while everything else looks healthy.
Reporting cadence executives actually read
Publish a single-page monthly scorecard: median input tokens per task type, p95 input, output share percentage, shred vs
baseline, and top three bloat sources (usually chat history, MCP schemas, and unscoped file attachments). Pair it with one
Polydyno invariant screenshot and a link to your active tune.jwt version in The Tuning House. Finance cares about
trend and confidence interval, not tokenizer trivia—keep narrative plain, numbers sourced, and methodology linked back to this
guide.