Blog

Cost Control for AI in Software Teams: There Is No Single Switch

The question everyone is asking these days: How do I make AI cheaper without making it dumber?

Most advice on AI costs is about hard limits: spending caps per key, turn limits, timeouts and alerts. Limits answer the question “how much can we lose?”. They do not answer the more useful question: how do we get the same work done for less? This article is about that. It is written for the engineers who spend the tokens, and for the engineering and project managers who sign the invoice.

The short answer is disappointing, so here it is up front. There is no universal method for lowering AI costs. There is no setting that halves the bill without side effects. What works is a combination of small practices, each of which removes some waste, and the right combination depends on how your team uses AI. A team that chats with an assistant needs different habits than a team running agents in CI, and both differ from a team that ships an AI feature to customers.

Prices and product features change every few months. This article names the practices and the reasons behind them. Check the numbers against current documentation when you apply them.

 

 

The cost equation

Every practice in this article makes sense once you see the equation behind an agent’s bill. The short version is:

cost ≈ number of agents
     × steps per task
     × (context per step × input price + output per step × output price)
     − what caching and batching save

Each factor is a lever:

Lever What pulls it Section
Context per step Reset, compact, new sessions, small starting context Keep the context small
Number of agents Fewer and shorter-lived agents and subagents Limit the number of agents
Price per token The right model for each step, other providers Use several models
Steps per task Good specs, stopping early, planning first Plan expensive, implement cheap
Caching and batching Prompt caching, batch APIs, response caches Caching
The price of the hardware itself Own or rented GPUs with open-weight models Own hardware, rented hardware

Notice that the factors multiply. Halving the context and halving the number of agents cuts the bill to a quarter, not by half. This is also why a single practice disappoints: it pulls one lever while the others stay where they are.

Keep the context small

The context is the largest and least visible cost driver. An agent resends its whole context on every step: system prompt, memory files, tool definitions, every file it has read and every tool result so far. A long session is expensive not because the last question was hard, but because it carries everything that came before. One practitioner guide estimates that a single message at a 500,000-token context costs about 50 times as much as the same message at 10,000 tokens. That is simply the arithmetic of input pricing, and it ignores the fact that quality also drops when the context fills with old material.

Four habits keep the context small.

1.Reset between tasks

When a task is done, clear the conversation before starting the next one. In Claude Code that is /clear. Other tools call it a new chat or a new thread. The agent loses nothing it needs, because the result of the previous task is in the repository, not in the conversation. What it loses is the thousands of tokens of exploration, failed attempts and test output that would otherwise ride along on every step of the next task.

The reset is the cheapest cost control there is, and the one people skip most often, because a long conversation feels like accumulated understanding. Most of it is accumulated noise.

2.Compact when you must continue

Sometimes you cannot reset: the task is half done and the conversation holds decisions you still need. Then compact. Compaction asks the model to summarize the conversation so far and continues with the summary instead of the full history. In Claude Code, /compact does this, and you can tell it what to keep: /compact keep the API decisions and the list of failing tests. A section called “Compact instructions” in CLAUDE.md steers what automatic compaction keeps. Codex CLI and Gemini CLI have similar commands.

Three cautions:

  • Compaction is not free. The model has to read the whole conversation to summarize it, so the compaction itself is an expensive request.
  • A summary loses detail. Compact at a milestone (the tests pass, the design is settled), not in the middle of a delicate change.
  • Undo is often cheaper than summarizing. If the last few turns went in the wrong direction, roll back to the point before them (/rewind in Claude Code, or double Escape) instead of compacting the mistake into the summary.

3.Start a new session with a handover

For longer work, a fresh session with a short written handover beats one endless conversation. The Agentic Scrum loop I described on this blog is built on this idea: every stage ends by writing a handover file, and the next stage starts a new agent that reads it. The handover is a few hundred tokens of decisions and open points instead of a hundred thousand tokens of history.

You can do the same by hand. Before you stop, ask the agent to write the state of the work to a file: what is done, what was decided and why, what is next, which files matter. Then reset and start the next session by pointing it to that file. It costs one short request and saves the history on every following step.

4.Start with a small context of code

Agents are curious. Ask one to “fix the export bug” in a large repository and it will list directories, open files and search the code base until it has built its own picture, and every file it reads stays in the context. You can do much of that work for it, cheaply, by starting small:

  • Point to the files. “The bug is in src/export/invoice_csv.py, the test is tests/test_invoice_csv.py” saves a dozen exploration steps.
  • Keep the memory file short. Project memory is loaded into every request. Claude Code’s documentation recommends keeping CLAUDE.md under about 200 lines and moving procedures into skills, which load only when needed.
  • Keep noise out of reach. Deny the agent access to build output, vendored dependencies, generated code and large data files. It cannot waste tokens on what it cannot open.
  • Switch off tools you do not use. Every connected MCP server adds tool definitions to the context. Newer harnesses load them on demand, but an unused server is still overhead. Where a command line tool does the job (gh, aws, kubectl), it is often cheaper than an MCP server.
  • Trim tool output. A test run that prints 3,000 lines puts 3,000 lines into the context. A hook can cut it down to the summary and the failures before the model sees it.
  • Let a subagent explore. If exploration is needed, give it to a subagent. Only its summary comes back to the main context.

In Claude Code, /context shows what is taking up the context right now. Run it once in a typical session. Most people are surprised by how much is spent before they type their first word.

Limit the number of agents

Parallel agents feel like free speed. Five agents finish in an afternoon what one agent does in a week. But each of them has its own context, its own loop and its own bill, and they bill in parallel too. Speed through parallelism is real. Savings through parallelism do not exist.

Claude Code’s documentation gives an idea of the scale: a team of cooperating agents uses roughly seven times as many tokens as a standard session when the teammates work in plan mode. Subagents are cheaper than full agent teams, because they are short-lived and return only a summary, but they still count.

Practical rules:

  • One agent per genuinely independent task. Two agents editing related code do not save time. They create merge conflicts and duplicate exploration.
  • Cap the concurrency. The Agentic Scrum runner runs one stage at a time on purpose. If you run agents in parallel, set a maximum in the runner, not in people’s heads.
  • Shut agents down. An idle agent with a full context that someone pokes again tomorrow pays for yesterday’s context.
  • Give helpers a smaller model. A subagent that searches files or summarizes logs rarely needs the largest model. In Claude Code, a subagent definition can set its own model:
---
name: log-summarizer
description: Summarizes long test and build logs into failures and likely causes.
model: haiku
---
Read the log you are given. Return only the failing tests, the first error
for each, and one line on the likely cause. No other text.

Use several models, sometimes from several providers

Model size is a cost decision. In daily practice that means you rarely use one model for everything. A rough division of labor:

  • Large model: specification, architecture, hard debugging, security review.
  • Mid-size model: most implementation, refactoring, tests, documentation.
  • Small model: search, classification, summaries, formatting, commit messages, routing.

The price difference between the largest and the smallest model of the same provider is often more than tenfold. Even a rough split, applied consistently, moves the bill more than any amount of prompt polishing.

A second knob sits next to the model: the reasoning effort. Many models let you choose how much they think before answering (/effort in Claude Code). Thinking tokens are output tokens, the expensive kind. Routine tasks rarely need the highest level.

Other providers

The same logic extends across providers. Some tasks are done well by a cheaper model from another vendor, or by an open-weight model offered by a hosting provider at a fraction of the frontier price. An LLM gateway makes this manageable: a proxy between your tools and the providers, with one interface, per-team and per-key budgets, logging and routing rules. LiteLLM is an open-source gateway you host yourself. OpenRouter is a managed service. Cloud platforms and several other vendors offer their own.

Research supports the idea. The RouteLLM project (UC Berkeley and LMSYS, 2024) trained routers that send each request either to a strong or to a cheap model, and reported cost reductions of more than 85% on one benchmark while keeping 95% of the strong model’s quality. That is a benchmark, not your workload, but it shows how much of a typical request mix does not need the most expensive model.

Multiple providers come with costs that do not appear on any invoice:

  • Every provider is a data processor. Each one needs the data protection checks: contract, retention, training on your data, location. A cheap model you are not allowed to send code to costs nothing and is worth nothing.
  • Every model needs its own evaluation. A prompt or a skill that works with one model can fail quietly with another. Run your evaluation set before you switch a task.
  • Switching mid-task loses the cache. Prompt caching works per model. A session that alternates between models pays full price for its context every time.

Plan with an expensive model, implement with a cheaper one

The combination of models that pays off most reliably follows the structure of good engineering anyway: think first, then type. The expensive model does the part where mistakes are expensive. The cheaper model does the part where the plan is already clear.

For an example feature, an invoice export:

  1. Plan (large model, high effort). Read value.md and requirements.md, ask the open questions, write agent-spec.md and test-spec.md (see specs a coding agent can follow). A human approves both. This step is short in tokens and decides everything after it.
  2. Implement (mid-size model, new session). Start fresh with the approved spec as the only input. The spec is specific enough that the cheaper model does not have to make design decisions.
  3. Grind (small model, subagents). Run the tests, summarize the failures, format, write the commit message.
  4. Review (large model, new session). Check the diff against the spec and the security checklist. A fresh session, so the reviewer is not anchored by the implementer’s reasoning.

Claude Code has a model setting for the first two steps in one session (opusplan: the large model in plan mode, the mid-size one for execution). In other tools you switch the model by hand or configure it per agent.

The trap is to measure the wrong thing. A cheap model that needs four attempts and two human corrections costs more than an expensive model that gets it right the first time, once you count the review hours. Measure cost per accepted change, not cost per token.

Caching

Caching means not paying twice for the same thing. It exists at three levels, and they are easy to confuse.

Prompt caching at the provider

Prompt caching works like this: if the beginning of a request is identical to a recent one, the provider bills those tokens at a reduced rate. For agents, this is the single largest discount available, because every step resends the same system prompt, memory files and spec. In late 2026, cached input at the large providers cost roughly a tenth of normal input. Writing to the cache sometimes costs a little more than normal input, and cache entries expire after a few minutes without use, unless you pay for a longer lifetime.

Coding agents handle caching for you, but your habits decide how well it works:

  • Stable content first, changing content last. The cache matches from the beginning. Anything that changes early in the context invalidates everything after it.
  • Do not edit the memory file in the middle of a session. It sits near the beginning of every request.
  • Do not switch models mid-session, as above.
  • Long pauses cost money. After a coffee break, the next request may rebuild the cache at full price. This is a reason to finish a task in one go, or to reset before the break instead of after it.

If you build your own AI features, structure your prompts the same way: fixed instructions and reference material first, the user’s question last.

Batch processing

Not every request needs an answer now. The large providers offer batch APIs: you submit many requests at once, the provider processes them within 24 hours, and you pay about half the normal price. According to the providers, the batch discount and prompt caching can be combined.

Good batch candidates in a software team: generating documentation for a whole module overnight, writing first-draft tests for many files, classifying the support ticket backlog, summarizing last week’s incidents, running an evaluation set. Anything a person waits for does not belong in a batch.

Response caching in your own product

If your product calls a model, many requests repeat. The same question about the refund policy arrives a hundred times a day. A response cache stores the answer and returns it without calling the model at all. An exact-match cache is simple and safe. A semantic cache also matches questions that are worded differently but mean the same thing, using embeddings. Tools include GPTCache (open source) and Redis LangCache (a managed service). A 2024 research paper measured up to 68.8% fewer API calls with a semantic cache on its test workload. Vendors claim more.

A semantic cache has risks of its own, and they are product risks, not cost risks:

  • A loose similarity threshold returns the wrong answer to a question that only looks similar. Tune it on real traffic and check samples.
  • Answers go stale. Give entries a lifetime, and invalidate them when the underlying facts change.
  • One user’s answer must never reach another user if it contains their data. Cache only answers that are the same for everyone, or keep the cache separate per tenant.

Own hardware, rented hardware

At some volume, every team asks whether it should run models itself. Open-weight models (models whose weights you can download and run, such as the Llama, Qwen, Mistral, DeepSeek and gpt-oss families) make this possible. The tools are mature: Ollama and llama.cpp run models on a laptop or a workstation, vLLM and SGLang serve them to many users on GPU servers. Quantization, storing the weights with fewer bits, shrinks the hardware needed: a 70-billion-parameter model needs about 140 GB of memory at 16-bit precision and about 35 GB at 4-bit, with a modest loss in quality.

Owning the hardware

Your own hardware turns a variable cost into a fixed one. You pay for the machines, the power, the cooling, the space and, above all, the people who run them. In return the marginal token is free, the data never leaves your building, and nobody changes the price or retires the model under you.

The economics depend on one number: utilization. An idle GPU costs the same as a busy one. Owning pays off when the load is high and steady, for example a product feature that runs around the clock or a large team that uses the models all day. It rarely pays off for a team of ten developers who use the models in bursts during office hours.

There are good reasons to own hardware that have nothing to do with cost: data that may not leave the premises, air-gapped environments, regulatory requirements. If those apply, cost is a secondary question.

Renting the hardware

Renting GPUs by the hour sits in between. In October 2026, an NVIDIA H100 cost roughly $2 to $4 per GPU-hour on demand at specialized GPU clouds and considerably more at the large cloud providers. Prices rose during 2026 because demand outgrew supply. Reserved capacity is cheaper per hour, but then you pay for idle time again.

Renting suits bursts and experiments: evaluating an open-weight model before you commit, fine-tuning, a large one-off batch job, or a pilot that may not survive.

The break-even check

Before anyone buys a server, do this calculation:

tokens per month to break even =
  monthly cost of the hardware (rent, or depreciation + power + operations time)
  / API price per token for a comparable model

Then compare the result with two other numbers: the tokens per month your team actually uses, and the tokens per month the hardware can physically produce. If the break-even point is higher than what the hardware can produce, self-hosting never wins on cost. Compare with the cheapest API that does the job well enough, often an open-weight model at a hosting provider, not with the most expensive frontier model.

Be honest about quality, too. In 2026, the best open-weight models are good at classification, summarization, extraction, embeddings and autocompletion. For long agentic coding tasks, frontier models still had a clear lead when this article was written. A common and sensible outcome is a hybrid: the small, high-volume tasks on your own or rented hardware, the hard tasks on a frontier API.

More practices that add up

Research for this article turned up a long tail of smaller practices. None of them is dramatic. Together they matter.

  • Measure first. You cannot control what you do not see. /usage in Claude Code shows the cost of the current session. Team plans and API consoles have spend reports per user and per key, and OpenTelemetry export gives per-user metrics for your own dashboards. Look for the outliers: one person, one job or one repository usually causes a large share of the bill.
  • Set per-user rate limits on API keys, so one runaway session cannot consume the whole team’s quota. Claude Code’s documentation suggests limits per user that shrink as the team grows, because not everybody works at full speed at the same time.
  • Ask for less output. Output tokens are the expensive ones. Ask for a diff instead of the whole file, for a list instead of an essay, and tell the agent not to repeat the code back to you.
  • Stop early. When you see the agent going in the wrong direction, interrupt it (Escape in Claude Code). Every further step in the wrong direction costs more than the previous one, because the context keeps growing.
  • Invest in the specification. The cheapest steps are the ones that never happen because the agent got it right the first time. A clear spec and tests written before the code cut the number of iterations more than any setting.
  • Turn off background features you do not use. Some harnesses spend tokens on suggestions, summaries and recaps in the background. Check the settings.
  • Choose the right billing model per use. A heavy interactive user is often cheaper on a seat with an included allowance. CI jobs and products run on API tokens.
  • Write prompts and skills once. A skill that encodes a procedure saves the tokens of explaining it again in every session, and of the agent rediscovering it.

No universal method: combine

Every practice above pulls one lever, and every one has a limit. Resetting does not help a team that runs ten agents in parallel. A cheaper model does not help when the context is full of test logs. Your own GPU does not help if it is idle most of the day. That is why there is no universal method for lowering costs. In most teams, the savings come from a combination of practices, chosen for how the team actually uses AI.

A starting point by situation:

Situation Start with Add later
Developers using a coding agent interactively Reset between tasks, small starting context, a smaller default model Handover files, subagents on small models, plan-then-implement
Agents in CI and an Agentic Scrum runner Hard limits, one stage at a time, a new session per stage Model per stage, trimmed tool output, cost per accepted change
An AI feature in your product Prompt structure for caching, the smallest model that passes the evaluation Response or semantic cache, batch jobs, a gateway with routing
Large, steady volume or strict data rules Break-even calculation, an open-weight pilot on rented GPUs Own hardware for the high-volume tasks, frontier API for the rest

Then do what works for every change: measure a baseline, change one thing, measure again. Cost control is not a project that ends. Prices, models and your own usage change every quarter, and the right combination changes with them.

Key takeaways

  • There is no single switch that lowers AI costs. Each practice pulls one lever of the cost equation, and the levers multiply.
  • Keep the context small: reset between tasks, compact at milestones, start new sessions with a handover, and point the agent to the right files from the start.
  • Every additional agent is an additional bill. Parallel agents buy speed, not savings.
  • Use several models: plan and review with an expensive one, implement and grind with cheaper ones. Measure cost per accepted change, not per token.
  • Use caching at all three levels: prompt caching at the provider, batch APIs for anything that can wait, and response caching in your own product, with care.
  • Own or rented hardware pays off only at high, steady utilization or when data rules require it. Do the break-even calculation first.

Try it

Pick one agent task you do every week. Run it once the way you normally do and note the cost from /usage or your provider’s console. Then run it again with three changes: a fresh session, a first prompt that names the relevant files, and a smaller model for the implementation after you have approved the plan. Compare the cost and check both results against the same rubric. Keep the changes that did not cost you quality.

The post Cost Control for AI in Software Teams: There Is No Single Switch first appeared on Sorin Mustaca: Security-AI-Software.