A coding agent doesn’t pay per task. It pays per step, and every step resends the whole conversation so far. That makes the cost of one run depend far more on how many steps it takes, and on how much of the context is cached, than on the price per token. This post builds the cost of one run from those parts, with numbers, and shows when a flat session beats paying per token.
For where the tokens inside each call come from (tool schemas, file reads, history), see where an agent loop’s tokens go. This post is about the arithmetic of a whole run.
How does context grow during an agent run?
Each call contains:
- a base context sent on every call: system prompt, tool definitions, rules files, a repo map;
- everything added by earlier steps: the model’s replies and tool calls, file contents and command output;
- the new instruction or tool result.
Call that base context B and the tokens each step adds g. Step 1 sends B. Step 2 sends B + g. Step n sends B + (n − 1) × g. Add those up and a run of n steps sends:
Total input = n × B + g × n × (n − 1) ÷ 2
The second term grows with the square of the step count. That is why long runs surprise people: the last step of a 60-step run is far bigger than the first, and every step in between pays for all the earlier ones again.
What does a worked run look like?
Take an agent with a 15,000-token base context (system prompt, a dozen tools and a repo map). Each step adds 3,000 tokens: one file or test log plus the model’s own reply. Each step writes 800 output tokens, reasoning included.
| Steps | Total input | Output | Largest single call |
|---|---|---|---|
| 10 | 285,000 | 8,000 | 42,000 |
| 30 | 1,755,000 | 24,000 | 102,000 |
| 60 | 6,210,000 | 48,000 | 192,000 |
Going from 30 to 60 steps doubles the work but multiplies input by about 3.5. Output only doubles. Input is 36 to 130 times output in these runs, which is why the input price, and the cached input price, matter most for agents.
The largest call also has to fit the context window. 192,000 tokens fits DeepSeek V4.1 Flash and GLM 5.3 (1,048,576 tokens each) and Qwen3.8 27B (262,144). It doesn’t fit Gemma 4 VL 26B (32,768): in this example the seventh call is already too big.
How much does caching change the bill?
Providers bill a repeated prompt prefix at a lower cached input rate. An agent that only appends to its history sends the same prefix every time plus a little more, so in the best case only the tokens added since the last call are new:
New input (best case) = B + (n − 1) × g
Everything else is a cache hit. The share of cached input rises as the run gets longer:
| Steps | New input, best case | Cached share |
|---|---|---|
| 10 | 42,000 | 85% |
| 30 | 102,000 | 94% |
| 60 | 192,000 | 97% |
Real agents rarely reach the best case, so it helps to price three cases. At BroadNet’s DeepSeek V4.1 Flash prices ($0.175 input, $0.0055 cached, $0.52 output per 1M tokens, published 2026-11-14), here is each run’s cost relative to the 30-step best case:
| Steps | Best-case cache | 80% cached | No cache |
|---|---|---|---|
| 10 | 0.33× | 0.39× | 1.37× |
| 30 | 1× | 2.07× | 8.11× |
| 60 | 2.33× | 6.84× | 28.2× |
Two things stand out. With no cache, a 60-step run costs 28 times a well-cached 30-step run. And caching matters more the longer the run gets. In the 30-step best case, output is about a third of the cost, new input under half and cached input under a quarter, so after caching, output is where the next saving is.
Caching is not something you switch on. It depends on the provider keeping the prefix and on your agent not changing it. OpenAI’s guide describes exact prefix matching with a minimum cacheable length. DeepSeek’s own API stores cache units at the end of each request’s input and output, so a follow-up that extends the previous request can hit. BroadNet’s pricing page says cached input needs no setup, and its docs report hits in usage.prompt_tokens_details.cached_tokens when the model provides them. BroadNet’s model catalogue lists DeepSeek V4.1 Flash among “models we never ran on our hardware”, and its Terms (§7.3) cover the model “when partner-hosted”, so on BroadNet it is served through a partner. Measure your hit rate rather than assuming DeepSeek’s own numbers. Write the prefix so it can cache: prompt structure for caching.
How do you estimate your own run?
This script reads current prices from BroadNet’s public pricing.json, so it never goes stale, and prints the token totals and cost per run for each cache case:
import json, urllib.request
PRICES = json.load(urllib.request.urlopen("https://inference.broadnet.ai/pricing.json"))
m = next(x for x in PRICES["models"] if x["id"] == "broadnet/deepseek-v4.1-flash")
p_in, p_cached, p_out = m["input_per_m"], m["cached_input_per_m"], m["output_per_m"]
def run_tokens(steps, base=15_000, growth=3_000, out_per_step=800, cache_rate=None):
total_in = steps * base + growth * steps * (steps - 1) // 2
if cache_rate is None: # best case: only new tokens miss
new_in = base + (steps - 1) * growth
else:
new_in = round(total_in * (1 - cache_rate))
return total_in, new_in, steps * out_per_step
def run_cost(total_in, new_in, out):
return ((new_in * p_in) + (total_in - new_in) * p_cached + out * p_out) / 1e6
for steps in (10, 30, 60):
for label, rate in (("best", None), ("80%", 0.8), ("none", 0.0)):
t, n, o = run_tokens(steps, cache_rate=rate)
print(f"{steps:>3} steps cache {label:>4} input {t:>9,} new {n:>9,} "
f"output {o:>6,} cost/run {run_cost(t, n, o):.4f} USD")
Replace the defaults with your own numbers. Don’t guess them; read them from one real run:
- Log
prompt_tokens,prompt_tokens_details.cached_tokensandcompletion_tokensfor every call, as in the agent token budget post. - B is the
prompt_tokensof the first call. g is the average increase inprompt_tokensfrom one call to the next. - Output per step is the average
completion_tokens. It includes reasoning tokens, which bill as output. - Your real cache rate is the sum of
cached_tokensdivided by the sum ofprompt_tokens.
The free agent run cost estimator runs the same calculation in your browser, so you can try other step counts, growth rates and cache rates without code.
What makes a run cost more than the estimate?
- Retries. A failed tool call or a 429 retry is another full-context call. Count them as steps.
- Changing the prefix. A timestamp in the system prompt, tools listed in a different order, or a rules file edited mid-run turns cached input back into new input from the change onward.
- Compaction. Summarising history shrinks the context, which cuts later input, but the new history has never been cached, so the next call pays the full input price. Compact rarely and in large steps; context management for long-running agents covers when.
- Big tool output. A 20,000-line test log added at step 5 rides along on every later step. In the formula, it adds 20,000 × (remaining steps) input tokens.
- Reasoning effort. High effort can multiply output per step. Set
reasoning_efforttolowfor routine edits. - Wandering. An agent that takes 60 steps for a 30-step task pays the square, not the double. A step cap is a cost cap. Ten ways to cut coding agent costs covers the levers.
When does a flat session beat per-token billing?
Turn cost per run into a monthly figure: monthly cost = cost per run × runs per month. Then compare it with a flat plan. On BroadNet, the plans cover DeepSeek V4.1 Flash with no token meter: Full Moon is $60 a month, Orbit $15 a week and Meteor $1 an hour, each per session.
Runs per month to break even = plan price ÷ cost per run.
Two things make this comparison less simple than it looks:
- Your cache rate sets the per-token side. With a high cache rate, per-token billing on Flash is cheap and you need many runs to pass $60. With a poor one, you pass it quickly. The flat-rate post shows the break-even as a monthly volume: about 917 million input and 46 million output tokens at 80% cached (the break-even math).
- Time sets the flat side’s ceiling. A session runs one request at a time. If one call takes 20 seconds on average (prefill, about 800 output tokens at about 100 tokens per second, plus tool time), a 30-step run takes about 10 minutes. One session then fits at most about six runs an hour. More parallel agents need more sessions.
For short bursts, Meteor works the same way at a smaller scale: if six runs fit in an hour, each costs $1 ÷ 6. Compare that with the script’s per-token cost for one run. To try your own volumes, use the flat-rate vs per-token calculator.
| Your pattern | Usually cheaper |
|---|---|
| A few short runs a day | Per token |
| Long runs with poor caching | Flat session |
| Agents running most of the working day | Flat session |
| Several agents in parallel, all day | One flat session per agent |
| Needs native tool calling on BroadNet | Per token on GLM 5.3 or Qwen3.8 27B |
Where BroadNet Inference fits
BroadNet reports cached and reasoning tokens in the usage block, so you can measure every number above from your own runs. DeepSeek V4.1 Flash has a low cached-input price and a 1,048,576-token context, and the unlimited plans remove its token meter; how sessions work.
Check one limit first. BroadNet’s docs list tool calling only for GLM 5.3 and Qwen3.8 27B, and neither is on a flat plan. Agents that edit through text, such as Aider, don’t need native tool calls. If yours does, test DeepSeek V4.1 Flash with your agent before you buy a plan, or budget GLM or Qwen per token. And if your agent runs only now and then, paying per token will usually cost less than any flat plan.
