Send less repeatedly
Summarize histories, retrieve only relevant chunks, cache stable prefixes, and lazy-load tool definitions.
Guide / LLM cost control
Control recurring AI spend by estimating the architecture before merge, exposing uncertainty, and turning the largest cost drivers into engineering decisions.
The operating equation
A useful cost estimate begins with a baseline: how many user actions occur, how many model calls each action creates, how much context enters each call, how much output is allowed, and how often the workflow retries, falls back, or invokes tools. Model rates matter, but they multiply the design. A cheap rate attached to an uncontrolled workflow can produce a large bill.
For a simple workload, monthly cost can be approximated as request volume × calls per request × token quantity × model rate. Real systems add cached input, batch discounts, multiple models, context replay, tool schemas, failed attempts, human rework, cloud services, and uncertain adoption. The purpose of estimation is not to pretend those variables are exact. It is to make them explicit before they become production behaviour.
Eight cost levers
Why averages fail
The expected monthly cost is useful, but it can hide a right tail created by demand spikes, longer outputs, retry storms, context growth, and fallback usage. P50 describes the median modelled outcome. P90 is a more conservative budget number: nine out of ten simulated outcomes fall below it under the declared assumptions. P95 exposes a deeper tail for systems where overruns are especially expensive.
A percentile is not a guarantee. It is conditional on the estimate basis. That is why Class1 reports estimate maturity separately from the P50/P90/P95 distribution. A mathematically precise simulation can still rest on weak volume assumptions. New workflows should be labelled as early estimates and calibrated against actual usage after deployment.
The pre-merge workflow
1. Establish the baseline. Record the current models, calls, tokens, retries, fallbacks, tools, demand, and monthly cost basis.
2. Read the proposed change. Identify which cost levers the pull request changes and which inputs cannot be inferred from code.
3. Declare assumptions. Add expected request volume, adoption, token distributions, routing, and budget ownership instead of fabricating unknown values.
4. Simulate baseline and change together. Paired scenarios isolate the cost delta and make unchanged systems return an exact-zero delta.
5. Review the drivers. Show which variables create the P90 tail and which engineering control would lower it.
6. Approve, revise, or block. Use an advisory comment first. Introduce a blocking budget gate only when the team trusts the basis and has a clear exception process.
7. Reconcile with actuals. Compare the approved estimate with the real deployment window. Update assumptions without rewriting the historical estimate.
Controls that usually work
Summarize histories, retrieve only relevant chunks, cache stable prefixes, and lazy-load tool definitions.
Use structured outputs, realistic ceilings, stop conditions, and smaller responses for intermediate agent steps.
Retry only recoverable failures, add backoff, inspect failure classes, and stop cascades across models.
Route by difficulty and required capability. Escalate deliberately instead of using the most expensive model everywhere.
Track calls per completed task and per active user so product growth does not hide architecture inflation.
Require review when a proposed positive P90 monthly delta exceeds the budget owned by the team.
Worked decision
Imagine a pull request that moves from a smaller model to a larger one, raises the output ceiling from 1,024 to 8,192 tokens, allows five retries, and adds an expensive fallback. A spreadsheet that changes only the model rate will understate the proposal. The review must include the output distribution, retry tail, fallback frequency, request volume, and the cost of replaying context on every attempt.
The correct question is not “Is the new model more expensive?” It is “What monthly cost distribution does this architecture create, what benefit justifies it, and which control can reduce the tail?” The Class1 browser estimator demonstrates this decision with a fixed example and lets you paste a diff locally without uploading code.
FAQ
Use token rates as an input, not the final KPI. Cost per completed task captures retries, fallbacks, failed outputs, and the number of calls required to finish useful work.
After the team has a declared basis, a budget owner, and an exception process. Start in advisory mode and block only positive cost deltas that exceed an agreed P90 threshold.
No. Code can expose models, token ceilings, retries, fallbacks, tools, and added callsites. Demand and real call frequency require workload assumptions or actual telemetry.
Re-estimate when architecture, pricing, model routing, demand, or measured distributions change. Keep the original approved estimate so variance can be explained later.
Choose one costly workflow, define the baseline and budget, run the worked estimator, and inspect the variables that drive P90 before adding a blocking policy.
Next step
Use the sandbox to see how model choice, output limits, retries, context, and budget change a pull-request decision. Then review the product workflow for applying the same method in CI.