Engineering notes /AI cost control
Pay for the top model only when the work needs it
Route AI calls by task, step up only when an answer fails a mechanical check, and log the cost of every call. In production: around 40% off model spend, with no measurable loss in quality.
Brightwave engineering · 7 min read
Most organisations that adopt AI make one model decision early and never revisit it: pick the most capable model, point everything at it, and move on. It's a sensible way to start. It is also, a year later, usually the largest avoidable line in the AI bill, because most of the work doesn't need the most capable model.
Reading an invoice, classifying an email, summarising a ticket, writing a unit test for a small function: a mid-tier model does these as well as the top one, at a fraction of the price. At current Anthropic list prices, Claude Sonnet costs half what Claude Opus does per token, and Claude Haiku about a fortieth. Sending everything to the top model means paying top-model prices for work a cheaper model would pass.
Route by task, not by model
The fix we use is a small routing service between applications and the models.
Applications keep the standard Anthropic SDK and change three settings: the base
URL, the API key, and the model field, which now carries a
task name instead of a model name:
client.messages.create(
model: "doc.extract", # a task, not a model
max_tokens: 8192,
messages: [...]
)
The router looks the task up in configuration and decides which model handles it. That one change does two things. The application no longer knows or cares which model it's using, so moving a task to a newer or cheaper model is a config change reviewed like any other, not a code change in every app. And every call now passes through one place where it can be measured, priced and controlled.
A ladder, and a check that isn't a judgement
Each task gets a model ladder: the most cost-effective model that handles it well on the first rung, a stronger model on the next. The router always starts at the bottom and steps up only when the answer fails a check.
The important design decision is what that check is. It is mechanical, never a judgement. Is the response valid JSON? Does it match the schema? Did the generated code compile and pass the tests? Is the required field present? These checks are cheap, deterministic and impossible to argue with.
The router checks the shape of an answer. Whether the answer is right stays in the application, next to the people and test cases that define "right".
We deliberately don't ask a model whether another model's answer is good enough to decide escalation. That adds cost and latency to every request, and it hides the decision inside something nobody can audit. If a task needs a quality judgement, the application makes it, with its own evaluations, where its owners can see and change it.
Log the cost of everything, and the content of nothing
Every call through the router writes one log row: which task, which model, which rung of the ladder, input and output tokens, the price at the time, latency, and why it escalated if it did. Callers also tag each request with the job it belongs to and the item it's about, such as a pull request, a document or an order.
That tagging turns a single monthly invoice into questions you can answer:
- What did checking this customer's order cost in AI, document by document?
- Which team's agents spend the most per merged change?
- Which tasks escalate most often, and is a cheaper model failing them or is the prompt the problem?
What the log never contains is the prompt or the document. The router records metadata only, so the cost log is never a second copy of sensitive data, and automated tests check that it stays that way. File names stay in the application too, because they often carry customer names or reference numbers.
Prove it on real work before switching
Before moving any live traffic, we run a sample of real work three ways: directly as today, directly again, and through the router. Running the direct path twice matters. Models aren't perfectly deterministic, so the honest baseline is how often the current setup agrees with itself, not an imagined 100%.
In our production case, the router agreed with the direct path as often as the direct path agreed with itself, and had fewer read errors. That is what "no loss in quality" should mean: indistinguishable from today's variation, measured on your own work.
What it saves
The saving depends on how your work splits. As a worked example, take a workload where 30% genuinely needs the top model, half is routine and a fifth is simple, and 5% of routed requests escalate. At list prices that comes to roughly 40% off model spend. Escalations pay twice, which is why they have to stay rare, and why the checks need to be strict.
At enterprise volumes the numbers get large quickly. On a $10 million annual model bill, 40% is $4 million a year, before prompt caching and batch pricing, which stack on top. You can try your own figures.
The same gateway is a security control
Putting every AI call through one service turns out to be as useful to security teams as to finance:
- One credential holder. Cloud credentials live only on the router. Applications hold a scoped, rotatable token that can call only their own tasks.
- Region pinning. Only models in permitted regions pass validation, and a bad configuration stops the service starting rather than sending data elsewhere.
- No bypass. Raw model names are refused, so nothing can skip the routing and its controls.
Where it doesn't help
Routing saves money on per-request API usage. It does nothing for fixed per-seat licences, and some agent tools call models with their own keys and can't be pointed at a gateway. That's why we start any engagement by finding out how the bill actually splits and which traffic can be routed, before promising a number.