AI features have an unusual cost profile. Traditional software has a high fixed cost to build and a marginal cost per user that approaches zero. A feature that calls a large language model has a real marginal cost on every interaction, and that cost scales with how much the user writes, how much context you attach and how chatty the model is. A feature that delights users and goes viral can turn into a gross-margin problem within a month.
The good news is that most AI spend is wasteful in predictable ways, and fairly simple engineering cuts it substantially, often by 50 to 80 percent, without a visible drop in quality. This article covers the levers in order of impact, and how to measure whether the economics work.
Understand what you are paying for
Hosted models bill per token, with input and output priced separately, and output usually costing three to five times more per token than input. Prices differ by one to two orders of magnitude between small and frontier models. As a ballpark, 2025 and 2026 list prices range from well under US$0.50 per million input tokens for small models to US$10 or more for the largest reasoning-capable ones. Check current price lists, because they change often.
A token is roughly four characters, or three quarters of a word, in English. Other languages, code and structured data can use noticeably more tokens for the same content.
A request cost is therefore:
cost = (input tokens x input price) + (output tokens x output price) + (extras such as tool calls, images, reasoning tokens)
Three hidden multipliers account for many surprises:
- Context accumulation. In a chat, each turn resends the entire history. A twenty-turn conversation can cost far more than twenty times a single turn.
- Reasoning tokens. Models with extended thinking bill for internal reasoning that users never see.
- Agent loops and retries. Multi-step workflows multiply calls, and failed calls that are retried still cost money.
You cannot control a cost you only see on the monthly invoice. Attribute every token to a feature, a customer and a request at the moment it is spent.
Measure first: unit economics
Before optimizing, build the measurement. Log, for each call: feature name, user or tenant, model, prompt version, input tokens, output tokens, cached tokens, latency and outcome. Compute cost from a price table maintained in code.
Then derive the numbers that matter:
- Cost per request by feature.
- Cost per active user per month, including heavy-tail users. Look at the 95th and 99th percentile, not only the mean. A handful of users often account for most of the spend.
- Cost per successful outcome: per resolved ticket, per approved document, per qualified lead. A cheap model that fails half the time is more expensive per outcome than a pricier one that succeeds.
- Gross margin per plan. If a subscription costs US$20 a month and the median subscriber generates US$3 of model cost while the top 1 percent generates US$60, you have a pricing and limits problem.
A worked example: a document summarization feature sends 6,000 input tokens and receives 500 output tokens per document. With a mid-tier model at US$3 per million input and US$15 per million output tokens, the cost is 0.018 + 0.0075 = about US$0.0255 per document. At 100,000 documents a month, that is US$2,550. Switching the simple 70 percent of documents to a small model at one-tenth of the price reduces the bill to roughly US$900 while the harder 30 percent keep the stronger model. The saving is real, but only because the measurement made the split visible.

Lever 1: Trim the tokens
The cheapest token is the one you never send.
Shorten and restructure prompts
- Remove redundant instructions and verbose examples. Audit long system prompts, since they are paid on every call.
- Replace many static examples with a few well-chosen ones, or select examples dynamically.
- Ask for concise output. Instruct the model on length (“at most three sentences”), and set a max output token limit as a safety cap.
- Use structured output with short field names and enumerations rather than prose when the consumer is code.
Control the context
- Retrieve fewer, better passages. Reranking to the top five often beats stuffing twenty.
- Summarize or truncate conversation history. Keep the last few turns verbatim and a running summary of the rest.
- Strip HTML, boilerplate and whitespace from documents before sending.
- Send only the fields of a record the task needs, not the whole JSON object.
Lever 2: Route to the right model
Not every request needs the most capable model. Routing sends each request to the cheapest model that can handle it acceptably.
Common routing strategies:
- Static by task. Classification, extraction and formatting go to a small model; open-ended reasoning and complex drafting go to a larger one. This is simple, predictable and captures most of the gain.
- Classifier-based. A small model or rules judge the difficulty or type of the request and choose the tier.
- Cascade. Try the cheap model first, check its output with a validator or a confidence signal, and escalate to the stronger model on failure. This works well when failures are detectable, such as schema violations or low scores.
- User-tier based. Free users get the fast model; paid plans unlock the stronger one.
Validate routing with your evaluation set per route, since a cheaper model that is slightly worse on average may be much worse on a specific category. Watch the escalation rate in a cascade: if 60 percent of requests escalate, you pay for both models and gain little.
Also consider whether a model is needed at all. Rules, regular expressions, lookup tables and classical classifiers handle many sub-steps for effectively nothing. Language models are best kept for the parts that truly require language understanding.
Lever 3: Cache aggressively but safely
| Cache type | What it saves | Typical impact | Risk |
|---|---|---|---|
| Exact response cache | Entire call for repeated identical inputs | 100 percent of repeats | Staleness; low if keyed by content hash |
| Provider prompt cache | Discount on repeated prefix tokens | 50 to 90 percent on cached portion | Needs stable prompt prefix |
| Embedding cache | Repeated embedding calls | Small per call, large at volume | None if keyed by text hash and model |
| Semantic cache | Calls for similar questions | Large on repetitive traffic | Wrong answers if threshold is loose |
| Precomputed outputs | Online generation | Very large | Freshness |
To benefit from provider prompt caching, put stable material first: system prompt, tool definitions, reference documents. Put variable content last. Avoid putting timestamps or request identifiers early in the prompt. Verify the hit rate in your usage logs; if it is low, something in your prefix is changing.
Precomputation deserves more attention. A product description summary, a translated help article or a daily digest can be generated once, in a batch, and served many times.
Lever 4: Batch and defer
If a user does not need the answer right now, do not pay interactive prices for it. Many providers offer batch interfaces at roughly half the standard price with a completion window of up to a day. Candidates include nightly classification, bulk enrichment, evaluation runs, content generation for catalogs and re-embedding a corpus.
Within interactive paths, batching still helps: group several small items into one prompt when the task allows it, such as classifying twenty short comments in a single call with an array output. This amortizes the instruction tokens across many items. Test accuracy, since very large batches can reduce per-item quality.
Self-hosting open-weight models can lower marginal cost at high, steady volume, but it introduces GPU capacity planning, utilization risk and operations work. A rough rule: below a few million requests per month, the managed API is usually cheaper once engineering time is counted. Do the arithmetic with realistic utilization before committing.
Lever 5: Budgets, limits and guardrails
Costs need hard ceilings, not hopes.
- Per-request caps. Maximum input size, maximum output tokens, maximum number of agent steps and tool calls.
- Per-user and per-tenant quotas. Daily or monthly token budgets, with graceful messaging when exceeded.
- Rate limits to stop abuse and runaway scripts.
- Global budget alarms. Alerts at 50, 80 and 100 percent of the monthly plan, plus anomaly alerts on hourly spend.
- Circuit breakers. If cost per hour exceeds a threshold, switch to a cheaper model or disable non-essential features automatically.
- Pricing aligned to cost. Usage-based tiers, credits or fair-use limits keep heavy users from being subsidized by everyone else.
Beware of prompt injection as a cost vector: an attacker who can make your agent loop or produce long outputs can run up the bill. Step limits and output caps double as security controls.
A practical order of operations
- Instrument cost per request, feature and tenant. Without this, stop.
- Find the top three features by spend and the heavy-tail users.
- Fix obvious waste: oversized prompts, duplicated context, missing max token caps.
- Add exact and prompt caching.
- Route simple work to small models, validated by evaluations.
- Move non-interactive work to batch.
- Set quotas, alerts and pricing.
- Review monthly, since prices, models and usage patterns keep shifting. A model released next quarter may offer your current quality at a fraction of the price, and your evaluation set lets you adopt it with confidence. Datainter reviews these numbers with clients on a monthly cadence for exactly that reason.
Keep the optimization honest by tracking quality alongside cost. Report cost per successful outcome, not just cost per call, and always run the evaluation set before and after a cost change.
Key takeaways
- Attribute every token to a feature, tenant and request; measure cost per outcome and look at the heavy tail, not just the average.
- Cut input tokens first: shorter prompts, trimmed context, fewer and better retrieved passages, concise output limits.
- Route by task and difficulty, use cascades with validators, and avoid models entirely where rules suffice.
- Structure prompts for provider caching, add exact-match caching, and precompute anything that does not need to be generated live.
- Use batch pricing for non-interactive work and group small items where accuracy holds.
- Enforce per-request caps, user quotas, budget alerts and circuit breakers, and align pricing with the cost of heavy usage.

