Skip to content

devlog/token-math/output-tokens-are-eating-your-code-generation-budget-1095.md

Output Tokens Are Eating Your Code Generation Budget

The output multiplier behind every refactor you run

When you scan a model price card, your eye usually lands on the input number first, and for code generation that is exactly the wrong instinct.

Most coding prompts are input-light and output-heavy. You send a file excerpt and a one-line instruction, and the model returns a rewritten module, a generated test suite, or a formatted migration that runs well past two hundred lines.

Output tokens are typically priced several times higher than input tokens, and unlike a shared prompt prefix they cannot be amortized across turns. Every assistant message you request is billed again at the higher rate, in full.

That single ratio explains most surprise bills from agent runs. A session that feels cheap because the prompt is small can still get expensive when every step asks the model to speak at length, and agents take many steps.

Everything below follows from one habit: treat every token the model emits as a purchase, and ask whether that text is doing real work or just filling space.

Rewriting whole files when a patch would cost a fraction

The most common and most expensive mistake is asking the model to return a complete file for a change that touched eight lines. The output price of the untouched ninety percent is real money, and it arrives again in every response.

Whole-file output also taxes your own loop. Larger responses stream slower, take longer to review, and are more likely to introduce noise into regions that were already correct.

Make the contract explicit in your instructions and in the tooling around them.

  • Ask for unified diffs or edited regions instead of complete file contents whenever your tooling can apply patches.
  • Constrain the response to the functions or lines that actually changed, and state that unchanged code must not be repeated.
  • Split large refactors into several scoped requests so each response stays small and reviewable.
  • Disable automatic whole-file rewrites in your agent settings unless a file is genuinely being replaced.
  • Keep generated fixtures and vendored snippets out of the response path whenever the build can produce them.

A patch-shaped response is cheaper, easier to read in a terminal diff, and far less likely to break code that was never part of the task.

Verbose answers that restate the code you already have

The second expensive habit is letting the model narrate. A response that opens with a summary of what it is about to do, explains every unchanged line, and closes with a recap can easily double the output tokens of the actual patch.

Editor-first workflows make this worse, because reasoning text is printed straight into your terminal and still billed exactly like code.

  • Specify a terse style in the system prompt and state that summaries and closing recaps should be omitted.
  • Ask for code only when you do not need the explanation, and ask for a short rationale when you genuinely do.
  • Reject repeated restatements of the input, because echoing your file back is pure billed output.
  • Cap response length for mechanical tasks such as renaming, formatting, or converting syntax.
  • Save long-form explanations for the rare debugging session where the reasoning is the deliverable.

Read the first response of a session with an eye for filler, then encode what you dislike into the prompt so the habit dies at turn one instead of turn forty.

Cache writes that never pay for themselves

Cache reads and cache writes are part of the real token bill, so caching is a tool, not a free upgrade. A prompt prefix that changes on every call writes new cache entries and buys you exactly nothing on the next turn.

The fix is ordering and stability. Put the immutable system prompt and long-lived repository context first, and push volatile state such as timestamps, clipboard contents, and random identifiers to the end of the request.

  • Keep the system prompt byte-stable across calls so cache reads actually land on later turns.
  • Move dynamic values to the tail of the request so they cannot invalidate the cached prefix.
  • Avoid caching context that will only be used once, because the write cost is billed upfront.
  • Reuse the same context bundle across related edits so cache reads dominate over fresh writes.
  • Watch cache read and write counts per session instead of assuming the cache is quietly saving money.

Treating cache writes as an investment with a break-even point changes how you structure long sessions, and it removes the mystery from bills that otherwise look inflated for no reason.

Regenerating full answers after tiny prompt tweaks

Another silent multiplier is regeneration. When an agent hits a timeout, a malformed patch, or a slightly wrong result, the default in many setups is to resend the whole request and generate the entire answer again, paying full output price for work you mostly already have.

The same trap appears at the human level. You nudge one phrase in the prompt, the response changes slightly everywhere, and you ship the second version simply because it reads cleaner.

  • Resume or extend a partial response instead of regenerating the complete answer whenever the API supports it.
  • Ask only for the missing part of a change instead of requesting the whole solution again.
  • Pin down the failing constraint before retrying, because vague retries almost always produce longer answers.
  • Set a maximum step count for agent loops so a wandering run cannot quietly spend its way forward.
  • Batch small follow-up questions into one request instead of opening a fresh generation for each one.

Retries are legitimate when correctness is on the line, but they should be a deliberate decision rather than a reflex that fires the moment output looks imperfect.

Oversized models running the inner edit loop

Model choice is an output cost decision as much as a quality decision. Running a frontier model for every comma fix and import cleanup multiplies output prices across hundreds of small turns where a lighter model would have been perfectly fine.

A practical split is to keep the fast tier for mechanical edits and the strong tier for design and debugging. Claude Haiku 4.5 handles quick, scoped edits well, while DeepSeek V4 Flash is a solid choice for bulk mechanical transformations.

Billing follows the same logic. Fluxo is an AI API relay with one key and one base URL, https://api.fluxorelay.com, covering Claude, GPT, Gemini, DeepSeek, Kimi, GLM, Qwen, Grok and more. It bills per real token, including cache reads and writes, with no monthly fee, and it works with Claude Code, Codex, Gemini CLI and any OpenAI SDK.

Because the meter is transparent, you can run the same task against two models and see which one earns its output tokens. Users also earn a referral share when the people they invite pay, which quietly offsets the cost of bringing a whole team onto the same relay.

  • Route mechanical edits to a smaller model and reserve stronger models for architecture and genuinely hard bugs.
  • Track output tokens per task so you know which model actually earns its price.
  • Compare models by cost per completed task instead of cost per individual request.
  • Run bulk transformations in batch style whenever the result does not need to be interactive.
  • Watch the per-session total in your terminal and stop a loop that has stopped converging.

If any of this resonates, creating a Fluxo account takes about a minute, and if you get stuck you can leave a note on the contact page after signing in.

Next in the buffer