- Published on
Coding agent costs through a local router: what 2,564 requests showed
- Authors
- Name
- Mattia Peretti
- @mattperetti
For three weeks, every request my coding agent made went through one local endpoint.
I expected the logs to tell me which model was expensive. What they showed was more useful. The price of the model mattered less than how much of the prompt the provider had already seen.
The router is 9router, an open-source proxy that runs on localhost and exposes an OpenAI-compatible API. The agent is OpenCode. Between October 23 and November 9, the router logged 2,564 requests across six provider connections, and it keeps daily usage in a local SQLite file. Everything below comes from that file and from the log of one compression tool the router runs.
One thing to know before the numbers: every dollar figure here is 9router's estimate at API list prices. Almost all my traffic runs on flat subscriptions, so these figures are not my bill. They show what the same traffic would cost on pay-as-you-go APIs, which is still the fairest way to compare one route with another.
One endpoint, six providers
The idea is simple. OpenCode talks to one URL, and 9router decides where each request goes. Models are grouped under one name, a combo, and each combo gets a routing strategy. 9router offers four:
- Fallback: tries the models in order, moving on when one fails.
- Round Robin: rotates the models across requests to spread the load.
- Smart Router: asks a small decision model which model fits the request, before generating.
- Fusion: queries every model in parallel and lets a judge merge the answers, so every request bills all of them.
I use two combos, both on Round Robin. coding-hard rotates DeepSeek V4 Pro between two subscriptions, Cline Pass and OpenCode Go, with a 1M token context. coding-light rotates DeepSeek V4 Flash across Cline Pass, the free OpenCode tier and OpenCode Go, with 330k of context. OpenRouter and a local Ollama install sit behind the same endpoint, and for a short while so did a Claude subscription.

Before settling on this, I tried Smart Router over a set of OpenRouter models. Letting a small model pick the right one for each task is an appealing idea. In my case the cost was too high, and I went back to rotating a few fixed models.
The setup took an evening, mostly spent on three errors that are easy to misread:
- OpenCode does not list the models of an OpenAI-compatible endpoint. You declare each one in its config.
- When 9router gets a model name that matches no combo, it treats it as an OpenAI model. The result is
No active credentials for provider: openai, even if you never configured OpenAI. - OpenCode uses a separate
small_modelfor side tasks such as session titles. Leave it unset and it may pick a provider you never configured, which can fail with a 401 while your main model works fine.
The upside of the router showed up later. Switching providers became a config change in one place, and the usage table became the first honest picture of where tokens went.
Coding agents mostly read
Across the 2,564 requests, the router counted about 240 million input tokens and 1.3 million output tokens. That is 184 tokens read for every token written.
An average request sent around 94,000 tokens and got back about 500. Each step of an agent loop resends the conversation, the open files and the tool results, so the prompt keeps growing while the answer stays short.
This changes what to look at on a price page. For this kind of work, the output price is almost irrelevant. The input price matters, and the cached input price matters most, because most of each prompt is identical to the one before it.
The numbers per model make the point:
- DeepSeek V4 Pro through
opencode-go: 1,090 requests, 94% of input tokens served from cache, about $0.0035 per request. - Claude Sonnet 5.5 through a Claude subscription: 12 requests, 4% from cache, about $0.12 per request.
That is a 35x gap per request, but the Claude side is too small to prove much. Part of the gap is the model's list price. A large part is that the Sonnet calls were one-off requests that never reused a cached prompt.
There is a reason the sample is small. 9router can connect a Claude subscription through its OAuth login, and its dashboard flags that route with a risk notice: the subscription session is not licensed for proxy or router use, and the account may be restricted or banned. I tried it briefly anyway. After a handful of requests, the provider replied that from then on, requests of this kind would be charged to usage credits instead of the subscription. I stopped there. If you want Claude behind a router, the supported path is an API key.

The free model was not the cheap one
The common assumption is that a smaller, cheaper or free model is the frugal choice. My logs disagree, at least for agent loops.
The free DeepSeek V4.1 Flash tier handled 333 requests. Only 42% of its input came from cache. Measured per million input tokens, its estimated cost was about $0.083, against $0.036 for the larger Pro model at 94% cache. The bigger model cost less than half as much per token read.
Two caveats keep this honest. First, these are list-price estimates, and the free tier shows it best: it has a cost attached even though nobody paid it. Second, the Flash requests were not the same tasks as the Pro ones. Still, the direction held across providers: the routes with high cache hit rates came out cheap, whatever the model.
Round Robin adds a twist. It sends consecutive steps of one session to different providers, and each provider keeps its own cache, so in theory rotation costs cache hits. On the Pro combo it did not show in the numbers: both routes stayed at 93 to 94%. I don't know yet why the free Flash tier fell to 42%.
In practice, the number to check before adding a provider to a combo is its cache hit rate, more than its headline price.
Token savers: compress what the agent reads
With input dominating the bill, the next lever is to send fewer tokens in the first place. 9router has a Token Saver panel for this, and it counts as much as the choice of provider. It bundles four tools, each working on a different part of the request.

RTK compresses tool output before it reaches the model: the results of git, grep, ls, tree and log commands, which make up a large share of an agent's prompt. 9router says it cuts 60 to 90% of the input tokens those commands produce. Headroom compresses the whole prompt before routing, with optional extras for code (compression based on the syntax tree) and for prose and agent traces (a small ML model that adds about 1 GB of dependencies).
The other two work on the answer. Caveman adds a system prompt that asks for terse replies, which 9router says cuts output tokens by about 65%. Ponytail pushes the model toward minimal code: reuse the standard library, prefer deleting to adding.
Headroom is the only one I have numbers for, because it keeps its own log. Over 2,861 requests, it attempted to compress 223.6 million tokens and saved 31.3 million of them: 14%. It also reported an average latency of 462 ms.
Whether that trade is worth it depends on the route. On a provider that already serves 94% of the prompt from cache, cutting tokens saves little money, and the extra half second shows up on every step of the loop. On routes with poor caching, 14% is real money.
The 184 to 1 ratio also puts the output savers in perspective. Cutting output by two thirds barely moves a bill where output is half a percent of the tokens. What it can change is speed, since every token the model writes is a token you wait for.
One practical note on Headroom: the first install failed on Python 3.15, because a dependency builds with PyO3, which supported Python up to 3.14 at the time. Installing it with Python 3.12 worked.
What the logs changed
The local models are the part I expected to use most and used least. Ollama answered 17 of the 2,564 requests. I wrote about why in What breaks when you run local LLMs for coding agents: memory limits and tool call parsing got in the way long before model quality did.
The bigger change is how I read pricing now. For coding agents, the question to ask a provider is how well it caches a long, growing prompt. At list prices, these three weeks would have cost $25.75, and flat subscriptions covered almost all of it. On pay-as-you-go APIs, most of the difference between the cheap routes and the expensive ones would come down to that single number.