ByteCosts
model-routing-vs-context-compression.mdx

AI Coding Agents

Model Routing vs Context Compression

Model routing lowers a coding agent’s cost when an eligible cheaper model can handle a turn. Context compression lowers cost by reducing the input the agent sends, provided the remaining context is sufficient and cache behavior stays favorable. Use both when a smaller request works on the selected model and the combined policy lowers total cost per accepted task.

Identify the change before measuring savings

A coding agent can vary the price it pays for a token and the number of tokens it sends. Routing selects a model or provider for a request. Compression changes the content supplied to the model, for example by trimming a repetitive test log or returning a smaller representation of structured output. A gateway can offer both capabilities through the same endpoint. Measure them independently so you can tell which change affected the charge and which affected the result.

ApproachWhat changesWhat to record
Model routingThe model and its rates, and potentially the provider and billing pathSelected model, served model, eligible tool capabilities, usage and cost for every attempt
Context compressionThe input a model receives and may need to recoverFresh and cached input, exact details retained, recovery calls, and total input over the task
Tool pruningThe tool definitions exposed to the modelWhich definitions were removed, what can still run, and usage on subsequent requests
Intervention in repeated failuresThe agent’s next action or number of attemptsIntervention cost, repeated failures, and whether the eventual result passed

Estimate the bill by multiplying each usage category by its applicable per-million rate and dividing by a million. Add fresh input, cache reads, cache writes where billed, and generated output for each request. Then sum across every request the task incurred. Routing changes which rates enter the equation and can change the usage pattern. Compression changes the amount and sometimes the pricing category of input. Extra attempts can alter both sides of the comparison. Coding agent session cost with compression

Route by what a turn needs to accomplish

Start with a capability and quality rule. A turn that extracts a known field from structured output can have a straightforward acceptance check. A turn that must diagnose a failing change across several packages may need longer context, better tool use, or more reliable reasoning. Establish which models meet each workload’s requirements before sorting candidates by cost. If the cheaper model returns an unusable answer, its initial expense still belongs to the task.

OmniRoute’s README describes a gateway that gives coding tools one endpoint, documents routing through combos and an Auto option, and advertises quota-aware fallback. It also lists compression as a separate feature. That is a useful distinction when reviewing a gateway configuration. A fallback that moves a call to another provider can keep work moving and may change the rate or quota used. Read the route outcome before assigning the charge to the model or account you originally requested. OmniRoute review

Use a fixed rule for the first trial, with workloads and acceptance checks selected in advance. If you plan to escalate on bad answers, define what fails the check and which model handles the next attempt. If you route on provider availability, record provider errors and model switches separately. For each attempt, capture whether a call incurred spend and which model produced the accepted result. Route LLM requests by workload

Compress at the point where redundant input enters

Pick the layer that can see the relevant material. RTK describes its default shell compressor as filtering supported commands before their output reaches the agent. That fits a workflow where the model repeatedly sees long successful test output alongside one actionable failure. The main model can stay the same while the tool result shrinks. Optional RTK pipelines and its separate proxy broaden the scope, so record which features are active before calling the trial shell-only. RTK

Headroom can act later as a proxy on provider-bound messages. Its README describes a router that picks compressors by content type and a recovery mechanism that retains originals locally. A mixed workload with repeated logs, JSON, and file content gives that approach more opportunities to act. Check the recovery path when exact text is necessary. A shorter tool result is useful when the model can diagnose the failure from what remains or retrieve details without excessive new work. Headroom

Cache behavior is part of either trial when the provider offers discounted reads. If a stable prefix stays intact and compression affects only new data, billable fresh input can decline while cache reuse continues. If a transformation changes a previously reused prefix, fresh or write charges may rise even with a shorter request. If routing changes model or provider, measure the cache volumes on that route instead of assuming the original usage mix transfers. In both cases, compare billed categories for later turns as well as the first transformed request.

Account for tools that cut wasted work through other mechanisms

TokenEconomizer’s README describes repository-specific micro-skills, tool pruning, and a loop guard. Those address rediscovery, tool definitions, and repeated failures. A learned instruction can reduce unnecessary exploration, a pruned tool list can reduce startup input on supported hosts, and a redirect can change the number of requests needed. Its own proposer and judge can use model calls, which the project says it includes in its cost reports. Include those side calls in the task ledger. TokenEconomizer review

For example, suppose the agent keeps invoking the wrong test command. Routing can change the model that faces the error. A shell compressor can shrink the result of each failed attempt. A repository instruction that teaches the correct command can remove the repeated attempts altogether. The evidence you want differs for each option. Check the served model for routing, the input after filtering for compression, and the command sequence and success of the test for the instruction.

Pruning deserves a separate test when a tool looks unused because your task set is narrow. Include a case that actually requires the tool and confirm there is a way to make it available when needed. Also compare warm sessions before and after the tool list changes. TokenEconomizer’s README explicitly describes delaying changes to avoid paying for a prompt cache rebuild on an active session. TokenEconomizer

Calculate the independent and combined effects

Assume a task uses 100,000 fresh input tokens and 10,000 output tokens. Compression reduces fresh input to 50,000 tokens. Assume equivalent accepted results, unchanged output, no discounted reads or writes, and no extra calls in any row. At ByteCosts’ committed rates checked November 30, 2026, Claude Sonnet 5.5 costs $2 per million input tokens and $10 per million output tokens. Claude Haiku 5.5 costs $0.10 and $0.50 per million respectively. These are estimates for assumed usage. The table does not measure either model’s coding ability. ByteCosts pricing index

Estimated configurationModelFresh inputOutputEstimated cost
BaselineClaude Sonnet 5.5100,00010,000$0.30
Compression aloneClaude Sonnet 5.550,00010,000$0.20
Routing aloneClaude Haiku 5.5100,00010,000$0.015
Routing and compressionClaude Haiku 5.550,00010,000$0.010

For the compressed Sonnet row, the formula is 50,000 × $2 plus 10,000 × $10, divided by 1,000,000. For the combined Haiku row it is 50,000 × $0.10 plus 10,000 × $0.50, divided by 1,000,000. The same input reduction saves an estimated $0.10 on the Sonnet route and $0.005 on the Haiku route. The discounts apply to the rates and volumes in each run, so adding the baseline-dollar savings from each individual policy would overstate the combined effect.

If Haiku’s first response fails and you subsequently pay for the same full uncompressed Sonnet attempt in the table, the route alone costs an estimated $0.315 for that task. If a compressed attempt needs another call to recover a detail, price the new request and output before comparing the rows. Keep the cache assumptions as explicit as the routing and recovery assumptions when adapting the estimate to a real bill.

Test the combination against fixed-model baselines

Run the same representative tasks through a fixed model with ordinary context, the same model with compression, the routing policy without compression, and the routing policy with compression. Preserve the starting repository, prompt, and acceptance tests. Use comparable cache conditions for paired runs, and include routine resume paths if that is where your sessions accumulate cost. Evaluate the tasks individually before aggregating, because a routing rule that helps report formatting may have a very different effect on implementation.

On each request, record the workload, actual model and provider, whether a transform ran, the usage fields, and the outcome. Track retrieval, provider failover, and quality escalation as distinct events. When provider billing data is incomplete, keep that uncertainty visible. An open OmniRoute issue title reports cached-token usage recorded as unknown on a Codex conversion path despite the upstream supplying it. In a similar setup, compare gateway telemetry with provider records before calculating fresh-input charges. OmniRoute cached usage issue

Check for interactions by including an exact-detail follow-up in the experiment. A cheaper model might solve a task from the raw log and struggle with the compressed one. The reduced request might also work on both models if it preserves the failing assertion and its path. If your routing policy uses requested context size to choose among eligible models, record whether that decision saw the original size or the transformed size. Then verify which model actually served the request. The order can affect eligibility and the cost of a fallback.

Pick routing first when your existing requests are already focused and a cheaper model passes the workload’s checks. Pick compression first when the current model is needed for the job and excessive tool output dominates fresh input. Combine them after both settings are observable and the combined run produces accepted work at a lower total cost. Divide spend across all attempts by the number of accepted tasks, and also compare latency and acceptance rate. That calculation gives a team a decision it can revisit when models, prices, or the shape of the workload change. Cost per accepted task

Choose a rollout boundary around a known workload

Start with a workflow whose result is easy to validate, such as naming the failing test and citing the relevant error. A route to a cheaper model can be evaluated against that exact check. A compression rule can be evaluated by whether it preserves the exact assertion and path. Keep the baseline available until the combined workflow has passed both checks, including a case where the raw output is needed for a follow-up.

When a task changes from extraction to diagnosis, let the new requirement govern the next call. The model that selected a failure from a log may need to hand off to a model that can reason over a larger source excerpt. Preserve the relevant evidence at the handoff and include both calls in cost per accepted task. A model switch that requires another copy of the log may be appropriate if it improves acceptance enough to pay for the added request.

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.

Model Routing vs Context Compression. ByteCosts. Updated 2026-11-30. https://bytecosts.com/blog/model-routing-vs-context-compression/

Sources