BroadRouter
Get started

10 ways to cut coding agent LLM costs, with estimated savings

By the BroadNet Inference team · 6 min read · Published

Most spend is input resent every turn. Keep the prompt prefix stable so it caches, name files, trim tool output, lower reasoning effort, cap loops and retries, and route easy steps to cheaper models. On DeepSeek V4.1 Flash, cached input costs about 3% of new input. Past about 917 million input tokens a month, a $60 flat plan is cheaper.

A coding agent’s bill grows in a way chat bills don’t. Every turn resends the system prompt, the tool list, the files it has read and the conversation so far. By turn 30, one request can carry hundreds of thousands of input tokens, most of them repeats. The ten tactics below target where those tokens go. Each has an estimated saving with the math shown, using BroadNet Inference prices synced 2026-11-14. Your numbers will differ, so measure before and after.

Where does a coding agent’s money go?

Three meters, in order of size for most agents:

  1. Input, resent every turn. Mostly cacheable.
  2. Output, including reasoning tokens you never see.
  3. Waste: retries, loops that make no progress, and context nobody needed.

Read prompt_tokens, prompt_tokens_details.cached_tokens and completion_tokens for a day of real work before changing anything. Where an agent loop’s tokens go shows how to break them down.

Which tactics save the most?

# Tactic What it cuts Estimated saving
1 Keep the prompt prefix stable New input Input bill down by half or more
2 Name files instead of letting the agent search Exploration turns Fewer turns, fewer resends
3 Trim tool output Input on every later turn Scales with log size
4 Lower reasoning effort on routine steps Hidden output Depends on task mix
5 Cap steps per task Runaway loops Puts a ceiling on the worst case
6 Cap and log retries Duplicate requests Each avoided retry is a full request
7 Start a fresh session per task Stale history Shorter context per turn
8 Route easy steps to a cheaper model Price per token Large on routed steps
9 Summarise rarely, append often Cache misses Keeps tactic 1 working
10 Switch to a flat plan past break-even The token meter $5.40 a month in our example

1. Keep the prompt prefix stable so it is cached

Cached input on DeepSeek V4.1 Flash costs $0.0055 per 1M; new input costs $0.175, about 32 times more. Order prompts as system prompt, tools, files, history, new message. Never put a timestamp at the top. Cursor reported in September 2026 that harness changes, including a system prompt about two-thirds shorter and tools loaded only when needed, cut users’ token costs by 7%. How to structure prompts so the prefix caches.

Estimated saving. Take 1,000M input tokens a month. At 50% cache hits you pay new-input price on 500M; at 80% you pay it on 200M. Including the cached part, the input bill falls by about 56%. How to raise your cache rate, or try your own numbers in the prompt caching calculator.

2. Tell the agent which files matter

A vague task (“fix the login bug”) sends the agent searching: listing directories, opening files, reading them into context. Each file it opens is then resent on every later turn. Name the files and the expected change. Keep a short project map in the repository that the agent reads first.

Estimated saving. If a 40,000-token file is read on turn 3 of a 30-turn task, it is resent about 27 times: over a million input tokens for one file. Not reading it saves all of that.

3. Trim tool output before it enters the context

Test runners, build logs and git diff can return tens of thousands of tokens. Show the agent the last 100 lines of a log or only the failing tests. Most agent tools let you set an output limit for commands.

Estimated saving. Same math as tactic 2: every token you trim is saved once per remaining turn.

4. Lower reasoning effort on routine steps

DeepSeek V4.1 Flash and GLM 5.3 think before they answer, and the thinking is billed as output. Set reasoning_effort: "low" for renames, formatting and small edits. Keep max_tokens high enough to finish, or you pay for thinking and get an empty reply. Reasoning token costs.

Estimated saving. Measure completion_tokens_details.reasoning_tokens before and after on the same 20 tasks. The saving is the drop times the output price ($0.52 per 1M).

5. Cap steps per task

An agent that cannot fix a test can loop for 100 turns, each one larger than the last. Set a maximum number of turns per task, and stop when the same tool call repeats three times. A step cap turns an unbounded cost into a bounded one.

6. Cap and log retries

A retried request is a new inference, billed again on a per-token key. Retry 429 and 5xx with backoff and a fixed limit; do not retry other 4xx errors such as 400 or 422. Errors and retries.

7. Start a fresh session for each task

History from the last task is dead weight on the next one. A new session per task keeps the context small. This does not conflict with caching: the system prompt and tools still form a shared, cacheable prefix.

8. Route easy steps to a cheaper model

Not every step needs the same model. Commit messages, changelog lines and simple classification can go to Gemma 4 VL 26B at $0.10 input and $0.22 output per 1M. If you use GLM 5.3 for tool-heavy steps, route the rest to DeepSeek V4.1 Flash: GLM 5.3’s output costs about 6.7 times more. GLM 5.3 vs DeepSeek V4.1 Flash.

Caution. Measure cost per finished task. A cheaper model that needs twice the turns can cost more.

9. Summarise rarely, and append the rest

When an agent compresses its history, it rewrites the prompt and the cache starts over. Summarise only when the context is close to its limit, in one large step, then append again. This keeps tactic 1 working.

10. Switch to a flat plan once you pass break-even

Per-token billing rewards small usage. A full-time agent is not small. In BroadNet’s worked example, a full-time coding agent (1,000M input at 80% cache, 50M output) costs $65.40 a month per token; an always-on agent costs $196.20. A Full Moon session is $60 a month with no token meter, one request at a time. At that point tactics 1 to 9 still save time, but no longer money. Check your own volumes with the flat-rate vs per-token calculator, or read the break-even math and running parallel agents on a flat rate.

How do you measure whether a tactic worked?

  1. Pick 20 representative tasks from your backlog.
  2. Run them with your current setup and log tokens per task.
  3. Apply one tactic at a time and rerun.
  4. Compare cost per finished task, not cost per request.

For apps that are not coding agents, the same levers in a general order are in how to reduce LLM API costs.

Setup guides for common agents: Aider, Cline, Zoo Code, the fork of the now shut-down Roo Code and OpenCode.

Where BroadNet Inference fits

BroadNet gives coding agents a cheap cached-input rate on DeepSeek V4.1 Flash and, for heavy use, unlimited sessions from $60 a month, on an OpenAI-compatible endpoint that these agents already support. It does not run closed frontier models, so if your agent needs one for its hardest steps, keep that model on its own vendor and send the bulk of turns here. See the plans.

Questions

Why are coding agents so expensive to run?

They resend the system prompt, tool definitions, file contents and history on every turn, so input tokens grow with each step. Reasoning adds hidden output on top.

What is the single biggest way to cut coding agent costs?

Keep the start of the prompt identical between turns so it is billed as cached input. On DeepSeek V4.1 Flash cached input costs $0.0055 per 1M against $0.175.

Is a cheaper model always cheaper for a coding agent?

No. A weaker model that takes more steps, or fails and retries, can cost more in total. Measure cost per finished task, not per token.

When is a flat-rate plan cheaper for a coding agent?

For DeepSeek V4.1 Flash, at about 917 million input and 46 million output tokens a month with 80% cache hits. A full-time agent usually crosses that.

How do I stop a coding agent from looping and burning tokens?

Cap the number of turns per task, stop when the same tool call repeats three times, and cap retries on 429 and 5xx errors. A step cap turns an unbounded cost into a bounded one.

Read as MarkdownAsk ChatGPTAsk ClaudeAsk Perplexity