← Back to blog

Taming Your AI Coding Bill: A Builder's Cost Playbook

Your AI coding spend is mostly context overhead, not prompts. Four structural levers that cut the bill without cutting how much you build.

Nishant Modi
August 10, 2026 · 9 min read
Featured image: Taming Your AI Coding Bill: A Builder's Cost Playbook

A 264-comment Hacker News thread on managing AI coding costs at scale hit a nerve this week, and the reason is simple: everybody’s AI coding bill is growing faster than their understanding of it. The Databricks piece is written for engineering orgs with hundreds of developers, but almost every lever in it works at any size — including a team of one. The counterintuitive part is that the biggest savings do not come from using the AI less. They come from four specific structural choices most builders have never audited. Here is the playbook, translated for people who pay their own API bill.

Where the money actually goes

The first thing to internalize is that you are not paying for what you type. As the Databricks team puts it, user input represents "only a negligible fraction of the data fed into the AI system." Your carefully worded prompt is a rounding error.

What you are actually paying for is context: system prompts, tool definitions, file contents the agent read, command output it captured, previous turns it is carrying forward, and every retry after something failed. A single "fix this bug" can quietly become hundreds of thousands of input tokens because the agent grepped through your repo, dumped three files, ran the test suite, and re-sent the whole accumulated pile on every subsequent turn.

This reframes the entire cost problem. Prompt golfing — the instinct to write shorter instructions — optimizes the one component that barely matters. The levers that matter are which model you use, how much context you drag around, and how often you retry.

It also explains the shape of a typical bill. Cost does not grow linearly with how much you ask for; it grows with session length, because context is re-sent on every turn. Two hours of conversation in one window is meaningfully more expensive than the same two hours split into four focused sessions, even though the work is identical. Anyone who has watched a long debugging session get slower and pricier as it drags on has felt this without necessarily naming it.

Lever one: ride the efficiency frontier

Databricks is blunt about the ranking here: "the single greatest cost lever is moving coding spend to more efficient models as they are released." Not the smartest model. The most efficient one that still clears your quality bar.

The nuance that makes this hard is that newer does not automatically mean cheaper for your workload. Databricks observed cost regressions with Opus 5.0 versus 4.8 on their tasks. Stripe evaluated Opus 4.7 and rejected it after finding no meaningful quality improvement over 4.6 at higher cost. These are companies with serious evaluation infrastructure reaching non-obvious conclusions — which is exactly why the article warns that "public benchmarks do a poor job of indicating real-world performance on coding tasks."

The lesson for a small team is not "run a benchmark suite." It is to stop assuming the flagship is correct for every task. Most of what an agent does in a day — renaming things, writing tests, formatting, summarizing a diff, drafting a commit message — does not need frontier reasoning. Reserve the expensive model for the work where you would genuinely notice the difference.

Lever two: route by task, not by habit

Dynamic routing — sending each request to the cheapest model that can actually handle it — is reported to cut costs by more than 30% while holding quality. Three patterns show up:

  • Request-level routing — a proxy inspects each call and picks the cheapest capable model.
  • Task-level routing — whole jobs get dispatched to a harness matched to their complexity.
  • Escalation — a cheap model does the first pass and hands off to an expensive one only when it gets stuck, or an expensive planner delegates execution to a cheap worker.

You do not need a gateway to benefit from this. The manual version is a habit: pick the model when you start the task instead of leaving whatever you used last time. Draft and explore on something cheap. Escalate deliberately when the cheap model starts flailing. The escalation pattern in particular maps neatly onto how you probably already work — plan with the strong model, execute with the fast one.

The failure mode to watch for is escalating too late. If a cheap model has already spent fifteen turns going in circles, the tokens it burned failing are pure loss on top of the expensive rerun you now need. A useful heuristic: if the cheaper model has not made visible progress in two or three turns, it is not going to. Escalate immediately rather than hoping the next attempt lands, because the sunk tokens are gone either way.

Lever three: cut the overhead, not the usage

This is where the largest untapped savings usually sit for individual builders, and Databricks reports a striking result: a 50% reduction in generated tokens from harness tuning alone. Same work, half the tokens, no change in what the developer asked for.

Their tactics translate directly:

  • Compress context frequently. Long-running sessions accumulate irrelevant history that gets re-sent every turn. Clearing or compacting between distinct tasks is one of the highest-return habits available.
  • Audit tool verbosity. A tool that returns 2,000 lines when 20 would do is charging you on every turn afterward. This is the quiet killer in custom MCP servers.
  • Break work into smaller units. Three focused sessions cost far less than one sprawling session where everything stays in context forever.
  • Tune prompt caching. Cached input tokens are dramatically cheaper. Keeping the stable parts of your context stable — so the cache actually hits — is nearly free money.
  • Prefer less verbose harnesses. Some agent scaffolds ship enormous system prompts and tool schemas you pay for on literally every request.

The community has been attacking this from a stranger angle too. Caveman is a Claude Code skill that strips prompts down to grunt-speak and claims a 65% token cut. It sounds like a joke and it is half a joke, but the underlying observation is correct: a lot of what gets sent is ceremony, not information. The serious version of that idea is auditing your tool output and your context hygiene.

Lever four: visibility before restriction

The most interesting recommendation in the piece is what not to do. Hard budget caps are "often used only as a last resort," because cutting someone off mid-task destroys more value than it saves. Instead the pattern is progressive friction: real-time dashboards, self-clearing gates that warn without blocking, downshifting to cheaper models at thresholds, and suspension only at the very end.

Underneath is a genuinely important insight: high spenders are frequently power users achieving "monumental efficiency gains." Cost per developer is a meaningless metric on its own. A developer burning triple the tokens while shipping four times the work is your best outcome, not your problem. Punishing consumption without measuring output optimizes the wrong variable.

For solo builders the equivalent is knowing your number before you get the invoice. Check spend weekly, notice which kinds of tasks dominate it, and instrument anything running unattended. If you have an LLM feature in production, Langfuse gives you per-trace cost attribution alongside latency and evals — which turns "the bill went up" into "this one endpoint doubled after Tuesday’s prompt change."

Do you need a gateway?

The infrastructure answer Databricks lands on is an AI gateway: a central proxy that all model traffic flows through, handling routing, budget tracking, configuration, and logging in one place. They have open-sourced pieces of this as Unity AI Gateway and Omnigent. If you are managing model access for a hundred developers, that is clearly the right shape — you cannot enforce routing policy or attribute spend without a chokepoint.

At small scale, though, building one is a trap. A gateway is infrastructure you now own, monitor, and debug at 2am, purchased to solve a governance problem you do not have yet. The honest threshold is roughly: if you cannot answer "which project is this spend from?", you need attribution, and that is usually a hosted observability tool rather than a proxy you wrote. If you cannot answer "why is this developer’s spend 5x the median?", you need a gateway — and by then you probably have a platform team.

The general principle applies well beyond this: at small scale, buy the visibility and skip the control plane. Restriction infrastructure only pays off once there are enough people spending that policy beats conversation.

The autonomy multiplier

There is a timing wrinkle worth flagging. Claude Code just made auto mode the default, and autonomous agents ship about 25% more PRs. That is a real productivity gain — and it is also a cost multiplier, because an agent that runs longer without stopping consumes more context, makes more tool calls, and retries more often without you watching.

This is not an argument against autonomy. It is an argument for pairing it with instrumentation. The cheapest failed run is the one that never happened, and unattended agents are exactly where silent, expensive failure loops live — a test that never passes, a build that keeps erroring, a retry cycle burning tokens for twenty minutes on a task that was framed wrong from the start. If you are increasing autonomy, increase observability in the same week.

A weekend audit that pays for itself

  1. Pull your last 30 days of spend and find the top three consumers. It is almost never what you expected.
  2. Check the token counts on your longest sessions. If a single session cost more than a nice dinner, that is a context hygiene problem, not a usage problem.
  3. Audit every MCP tool for output verbosity. Cap or summarize anything returning huge payloads.
  4. Move one routine task down a model tier — commit messages, formatting, test scaffolding — and see if you can tell.
  5. Confirm prompt caching is actually hitting, and stop shuffling the stable parts of your context.
  6. Start new sessions per task instead of running one endless conversation.
  7. Add tracing to anything running unattended, before you scale it up.
  8. Track cost against output, never in isolation. Tokens per shipped feature beats tokens per month.

The bottom line

The instinct when an AI bill spikes is to use the tool less, and that is almost always the wrong move — it trades a large productivity gain for a small financial one. The structural fixes are better on both axes. Right-sizing models, routing by task complexity, cutting context overhead, and measuring what you spend can plausibly halve a bill without touching how much you actually build.

The framing that matters most is the last one: cost is only meaningful next to output. A tool that costs real money and ships features that would have taken you a week is not expensive. A tool quietly burning tokens in a retry loop on a task nobody checked is expensive at any price. The difference between those two is not the model you picked — it is whether you can see what is happening. Start there.

AI is moving fast. Don't get left behind.

Get the weekly digest for AI builders & vibe coders. Curated tools, resources, and stories. Skip the scroll.

Keep reading