Modelling what an AI feature will cost before you build it
AI features have a cost profile most software does not: marginal cost per request that scales linearly with usage. A feature that costs a fraction of a rupee per call is fine at a thousand calls a day and a real line item at a million — and the difference is knowable before you build it.
Conventional software cost is dominated by fixed infrastructure: the same server serves a hundred or ten thousand requests. Hosted language models invert that. Cost tracks usage almost exactly, which makes a cost model a design input rather than a finance exercise afterwards.
Measure tokens, do not estimate them
Every projection starts with tokens per request, measured on your actual evaluation set rather than guessed from a sample prompt. Retrieved context is usually the largest and most underestimated component.
The levers, in order of effect
Cost reduction options are not equal. These are ordered by how much they typically save relative to the effort and the quality risk involved.
- Retrieve less context. Passing ten chunks where four suffice inflates every single request. Measure quality against chunk count on your evaluation set — the curve usually flattens earlier than expected.
- Use a smaller model where evaluation permits. Capability differences are task-specific; many extraction and classification tasks show no measurable quality loss on a cheaper model.
- Cache aggressively. Identical or near-identical requests are more common than teams assume, particularly for document questions and summaries.
- Route by difficulty. Send straightforward requests to a cheap model and escalate only the hard ones, using a cheap classifier to decide.
- Cap output length. Verbose answers cost more and are frequently worse; a max-token limit is both a cost and a quality control.
- Trim the system prompt. Lower impact per token, but it is paid on every request forever.
Caching, and what is actually cacheable
There are three distinct caching strategies here and they are frequently conflated. Each addresses a different repetition pattern.
Cache keys must include the tenant, the retrieved context version and the prompt version. A cache that survives a prompt change serves output from a system you no longer run.
Building the projection
With measured tokens, the arithmetic is straightforward and worth writing down explicitly so assumptions are visible and challengeable.
Run it at three volumes: current, ten times current, and a hundred times. A feature that is comfortable at all three is safe to ship. One that breaks at ten times needs a cost design decision now, not after growth arrives.
Guardrails, because projections are wrong
No model survives contact with real usage patterns. What protects the budget is enforcement at runtime rather than accuracy in the spreadsheet.
- Per-tenant rate limits on AI features specifically, separate from general API limits
- A monthly token budget per tenant, with defined behaviour on exhaustion — degrade or queue rather than fail opaquely
- Alerting on cost per active user, which catches a change in usage pattern that a total-spend alert misses
- A hard provider-side spend cap, so a runaway loop cannot produce an unbounded bill
- Per-feature attribution, so you can tell which feature moved the number
Where this reaches the commercial model
A feature with genuine marginal cost per request sits awkwardly inside unlimited-usage pricing. That is a commercial decision rather than an engineering one, but engineering owns the number the decision depends on.
Producing a defensible cost-per-active-user figure early lets the pricing conversation happen while the product is still flexible — rather than after launch, when the options are raising prices or absorbing the cost.
Questions
What reduces AI feature cost most?
Retrieving less context, usually by a wide margin. Passing ten chunks where four would do inflates the input tokens of every single request. Measure quality against chunk count on your evaluation set — the curve typically flattens earlier than expected, which means the extra context was costing money without improving answers.
Should I use a cheaper model?
Test it rather than assume either way. Capability differences are task-specific: many extraction, classification and routing tasks show no measurable quality loss on a smaller model, while open-ended reasoning often does. The evaluation set answers this in an afternoon, and the saving compounds on every request thereafter.
Is semantic caching safe?
Only with a conservative threshold and per-tenant scoping. Two questions can be close in embedding space with genuinely different correct answers, particularly where one contains a temporal or conditional qualifier. Exact-match caching carries no such risk and frequently captures more repetition than teams expect, so start there.
How do I avoid a surprise bill?
Enforce limits at runtime rather than relying on the projection: per-tenant rate limits and token budgets, capped retries, per-feature cost attribution, and a hard spend cap at the provider. Alert on cost per active user rather than total spend alone — that is what catches a changed usage pattern before it becomes a large invoice.