ByteCosts
coding-agent-session-cost-with-compression.mdx

AI Coding Agents

Coding Agent Session Cost With Compression

Estimate coding agent session cost with compression by pricing fresh input, cache reads, cache writes, and output separately across all requests. At the committed Claude Sonnet 5.5 and GPT-6.2 Sol rates, the worked warm-cache session falls from $0.31 to $0.21 when compression removes fresh input and preserves cache hits. If the same change forces a cache rebuild, the compressed session costs an estimated $0.45.

Set up the estimate from the committed rates

Use the charges that apply to your actual model and provider. The rate snapshot below comes from ByteCosts’ committed first-party pricing data checked November 30, 2026. Both models have the same rates in that snapshot, so the same assumed usage yields the same dollar estimate for each. Whether the models end up using the same token counts or completing the task in the same number of turns is a separate question for a live trial. ByteCosts pricing index

ModelFresh input per millionCache read per millionCache write per millionOutput per million
Claude Sonnet 5.5$2.00$0.10$2.50$10.00
GPT-6.2 Sol$2.00$0.10$2.50$10.00

The estimate assumes each input token belongs to exactly one priced bucket. If your API reports a total input field that includes cached tokens, use the breakdown to derive the fresh count before applying rates. Include cache writes only when the provider reports or bills them for the request path you chose. The table applies the committed rate fields for the modeled scenarios. Use the provider’s actual billing categories and charges when reconciling a real run.

Sum usage across every model request for the task, including intermediate tool calls. A file can be sent again on later turns, so the sum across calls can exceed the number of unique tokens in the transcript. For a session with multiple models, apply each model’s rates to its own requests before adding the costs. A request billed in a different tier or under a different contract needs the applicable rate for that request. How to calculate LLM API cost

Estimated session cost =
  (fresh input × input rate
   + cache reads × read rate
   + cache writes × write rate
   + output × output rate) ÷ 1,000,000

Compare cold input, warm reads, and a cache rebuild

Assume a coding agent diagnoses a failing test, reads the relevant implementation, makes a patch, and runs the checks. Across the uncompressed session, assume it sends 200,000 input tokens and generates 10,000 output tokens. For the compressed session, assume it sends 150,000 input tokens, generates the same output, and completes the same task. The compressor removes 50,000 tokens from fresh tool results and related input across all requests. These rounded counts are illustrative assumptions, and the table values are estimates calculated from them.

In the warm case, assume the provider can reuse 100,000 tokens of the prefix across the measured requests. In the rebuild case, assume the uncompressed run starts warm and the compression path rewrites the equivalent prefix, shifting that usage into cache writes. Treat the rebuild as an aggregate billed-usage scenario. A live session might write the new prefix on one turn and resume cache reads on later turns. Use the summed writes and reads for those requests to estimate that session.

Estimated sessionFresh inputCache readsCache writesOutputEstimated total per model
Cold, baseline200,0000010,000$0.50
Cold, compressed150,0000010,000$0.40
Warm, baseline100,000100,000010,000$0.31
Warm, compressed with prefix preserved50,000100,000010,000$0.21
Warm, compressed with cache rebuild50,0000100,00010,000$0.45

In the cold baseline, fresh input contributes $0.40 and output adds $0.10. Compression removes $0.10 of fresh input, for a $0.40 estimated total. Both cold rows model ordinary input without billed writes. If your cold start writes a prefix, move that portion to the write category and price it there.

In the warm baseline, the 100,000 fresh tokens cost $0.20, reads cost $0.01, and output costs $0.10. The warm compressed case lowers the fresh portion to $0.10 and keeps the read and output charges, for $0.21. In the rebuild case, the same 100,000 prefix tokens cost $0.25 as writes. Add $0.10 each for fresh input and output, for $0.45. The rebuild estimate exceeds the warm baseline by $0.14 even though total input falls. Context compression versus prompt caching

Check what happens when the removed tokens were already cheap

The table puts all removed tokens in the fresh bucket. In a real session, a tool may shrink content that would otherwise have been billed as a cache read. At the modeled rates, removing 50,000 fresh tokens saves an estimated $0.10. Removing 50,000 tokens that would all have been cache reads saves an estimated $0.005 if everything else is held fixed. That distinction can change which content you choose to transform.

The next question is how often the compressor changes the prefix. If the first compressed request pays for a write and several later requests read it back, spread the write over those requests when you compare complete sessions. If the compressor keeps changing cached content, you may pay for fresh input or writes repeatedly. Start the baseline and compressed comparison with equivalent cache conditions, and allow each setup to build its own prefix when the trial calls for it. Record the transition around the first transformation so you can explain the resulting mix.

In the example, output accounts for $0.10 in every row. If a recovery step prompts the model to generate new tool arguments or repeat an explanation, add that output charge along with the new input. Compare the additional cost with the $0.10 saved in the warm compression row. If the recovery and extra turns consume that amount, the estimated dollar advantage disappears. The task can still benefit if compression lets it fit inside the available context window and complete at all.

Separate a smaller request from a cheaper completed task

The independent tokbench pilot, with N=1 per arm, gives a concrete example of the difference. Its Headroom path reported 342K tokens removed within the transformed run, checked against provider usage. The Headroom run still used 3.24M input tokens versus 2.28M for the native run and took 237 model turns versus 180. Those runs used a different provider and models from the worked estimate, and the pilot’s main comparison did not include prompt-cache discounts. Those numbers describe that pilot’s run paths. They do not supply the compression ratio or cache assumptions in the table. tokbench pilot

A compressor’s local meter can explain which messages it shortened. The provider record can tell you which priced usage buckets moved. The acceptance check tells you what the session bought. Keep all of those records when possible. If a run with compression spends less per request but takes more turns, inspect whether the added turns recovered omitted details, repeated earlier reasoning, or handled an unrelated retry. Those categories help you diagnose the difference without assigning all run-to-run variation to the compressor. Independent middleware benchmark

For an acceptance check on this scenario, require the same failing test to reproduce, the same target behavior to be fixed, and the same validation to pass. If an optimized run answers with a plausible guess and skips reproducing the failure, mark the outcome accordingly. A cheaper rejected task still belongs in the numerator when you compare spend per accepted task.

Turn your transcript into a before-and-after bill

Use one row per provider request. Record its task ID, attempt, provider, actual model, and separate fresh input, cache-read, cache-write, and output counts. When a tool reports a local estimate, keep that alongside provider usage and label the source. If your agent launches an auxiliary model, such as a summarizer, add rows for those requests too. Put any separately charged services or tools on the same task ledger. The token formula estimates model usage charges, and the task ledger captures the other spending attributable to the result.

For a fair comparison, start each run from the same repository snapshot and use the same model, task prompt, and acceptance checks. Run one comparison from a fresh cache state and another that reflects your routine follow-up work. If investigating a cache miss, preserve the individual rows around the transformation. The difference in fresh and cached usage can show whether you changed what was sent, changed what qualified for a discount, or both.

When your report only provides total input and total output, compute a clearly labeled range from possible billing mixes or defer the dollar comparison until you have the breakdown. Uncertain allocation can overwhelm a small expected saving. Track turns and elapsed time while you wait for billing data, since a tool that repeatedly sends the agent back for originals can still be expensive to operate.

Finally, group comparable accepted tasks by workload. Divide the total cost of all attempts in that group by the number of accepted results. If none pass, report the spend and the acceptance count without calculating a ratio. Keep the modeled example for planning and use reconciled charges for rollout decisions. That preserves the distinction between a plausible scenario and savings your own sessions achieved. How to measure coding agent token savings

Use the same ledger when the session spans a handoff

A coding task can have a cheap first session and an expensive follow-up if the second agent has to reconstruct the first agent’s work. Keep the same task ID when a review or repair follows the original run. Charge the first session for producing the handoff and charge the second for consuming it. A smaller handoff can reduce fresh input, while a handoff that omits the failing case can send the second agent back through the original test and read loop. Accept the task only once the combined work satisfies the original checks.

When comparing models, rerun the estimate with each model’s actual usage mix before drawing a conclusion from the equal rate rows. For example, one model may recover an omitted assertion by fetching a stored result, while another may rerun the suite. Both paths can finish successfully, yet the requests carry different histories and output. The equal prices in the example mean each corresponding token bucket has equal unit cost. The amount in each bucket still comes from the trace.

For routine budgeting, save the warm, cold, and rebuild scenarios so you can update only the pricing or usage assumptions that change. Record how often each scenario actually occurs in your workload before blending them into a single forecast. Frequent warm runs and occasional rebuilds can produce the same average input count as a different mix while yielding different charges.

Keep the date of the rate snapshot with each estimate. When you compare two historical runs, price both using the same rates if the question is about changes in usage. When the question is what was actually paid, use the rates and billing rules in effect for each run. Those comparisons can lead to different conclusions if prices changed between sessions.

Sources

How this note was produced

Drafted with AI assistance from committed ByteCosts pricing snapshots and deterministic cost formulas. Figures are grounded in the linked sources (last updated 2026-11-30). Read our editorial & automation policy, inspect the methodology, or report a discrepancy.

Coding Agent Session Cost With Compression. ByteCosts. Updated 2026-11-30. https://bytecosts.com/blog/coding-agent-session-cost-with-compression/

Sources