code-anything.com
Log inStart free

Guide

LLM Inference Cost Optimization: Beyond Token Counting in 2026

Cost per successful outcome, model routing, context caching, quantization and RAG hygiene: how production teams actually cut LLM inference bills in 2026.

· 10 min read

A 1M-token context window is not a feature. It is a billing surface — and it is now shipping in production models like the 744B MoE and 1M-context endpoints listed in Morph's 2026 inference optimization catalogue.

The cheapest way to cut your LLM inference bill in 2026 is not a cheaper token. It is fewer wasted tokens. Measure cost per successful outcome instead of price per million, cache the prefixes you resend, route each request to the smallest model that passes your evals, and treat quantization and retrieval hygiene as cost work rather than performance work. Token price is the last lever you should pull, not the first.

Key takeaways

  • Raw token price is a poor proxy. Retries, escalations, bloated context and multi-agent hops are where budgets actually leak.
  • Cost per successful outcome (CPSO) = total inference spend ÷ outcomes a user would accept. It is the only number that survives contact with a finance review.
  • Context caching, routing and quantization are all prefill-and-throughput plays. They compound; none of them is a one-off fix.
  • Self-hosting has a break-even point, and most teams reading this are below it. Utilization, not enthusiasm, decides.
  • Every optimization here needs an eval harness behind it, or you are trading quality for a smaller invoice you will not notice until churn.

Why is LLM inference so expensive in 2026?

Inference is expensive because you pay for tokens you did not intend to send. Long context windows, retried tool calls, agent loops that resend history on every hop, and retrieval that stuffs twelve near-duplicate chunks into the prompt all bill at full rate. The model is rarely the problem; the payload is.

Two structural things changed. Context windows got enormous — long enough that "just put the whole document in" became a default rather than a decision. And agentic workflows multiplied the number of model calls per user action. A single support ticket that used to be one completion is now a planner call, three tool calls, a verifier, and a summarizer.

The economics side of this is now its own discipline. Spheron's GPU FinOps playbook, published April 2026 and updated that September, frames it as inference cost economics rather than a serving problem — which is the right framing. If your cost model lives in a serving config file, you are optimizing the wrong layer.

What are AI FinOps strategies for LLM inference in 2026?

AI FinOps for LLMs means attributing every model call to a feature, a customer, and an outcome — then putting a budget on each. It is the same discipline as cloud FinOps, applied to something metered per token instead of per hour, which makes it faster to detect and faster to lose control of.

The practical levers, roughly in order of payoff:

LeverWhat it changesEffortTypical payoff
Context cachingPrefill cost on repeated prefixesLowHigh, if prefixes repeat
Model routingUnit price per requestMediumHigh
RAG hygieneInput tokens per requestMediumMedium to high
QuantizationThroughput and memory, self-hostedHighHigh at scale
Agent budget capsWorst-case spend per workflowLowPrevents outliers
Prompt/output trimmingOutput tokensLowModest

The ordering matters. Teams usually start with prompt trimming because it is visible, and it is the smallest lever on the list. Start with caching and routing.

If you want the accounting layer underneath this, our own write-up on the true cost of AI inference and how to optimize the bill covers the instrumentation side.

What is cost per successful outcome (CPSO) and why does it matter?

CPSO is total inference spend divided by the number of outcomes a user would accept — not the number of API calls, not the number of tokens. It prices failures. A cheap model that needs three retries and a human escalation is more expensive than an expensive model that works first time.

Concretely: if a workflow costs $0.40 in tokens but only 60% of runs produce something usable, your real cost per successful outcome is roughly $0.67. That is the number you compare against alternatives, and it is the number that changes your routing decisions.

It also kills the worst habit in this space, which is optimizing token spend in isolation. An eval suite that labels runs as pass or fail is the prerequisite. Without it, every cost change is a guess with a smaller invoice attached.

Model routing: how do you pick the cheapest model that still works?

Model routing sends each request to the cheapest model that passes your quality bar for that request class. You classify first, then dispatch. The classification itself usually runs on a small, fast model, and its cost is negligible against what it saves.

A routing table that holds up in production looks like this:

Request classRoute toReason
Classification, extraction, taggingSmall dense modelDeterministic output, short context
Drafting, summarization, reformattingMid-tier modelQuality gap over small models is small here
Multi-step reasoning, code changesFrontier modelFailures cost more than tokens
EmbeddingsDedicated embedding modelNever route embeddings through a chat model
Anything with a hard latency SLOSmallest model that passesLatency and cost usually agree

Two rules I would not bend on. First, route on the request class, not on the user's plan tier — a paying customer asking a trivial question should still hit the cheap model. Second, log which route served each request alongside the eval outcome, or you will never know whether a route is actually safe to keep.

Context caching for LLMs: how much does it actually save?

Context caching stores the processed form of a prompt prefix so the model does not re-read it on the next call. Prefill — reading the input — is the expensive half of a long-context request. If your system prompt, tool definitions, or document set is byte-identical across calls, you are paying to read it again every time. Vendors advertise prefill savings of up to 90% on repeated prefixes; treat that as a ceiling, not a forecast.

What determines whether you capture it:

  • Prefix stability. Any change anywhere in the prefix invalidates everything after it. Put static content first, dynamic content last.
  • Cache TTL. Caches expire. If your traffic is spiky, you may pay cache-write cost more often than you get reads.
  • Write cost. Some providers charge more to populate the cache than to read from it. Do the arithmetic on your own hit rate before assuming it wins.

The classic failure is a system prompt with a timestamp or a session ID near the top. That single line destroys the cache for every request.

Quantization for LLM inference: what does it change?

Quantization stores model weights and often the KV cache at lower numeric precision — FP8 instead of FP16, or INT4 instead of INT8. FP8 halves the memory footprint of weights versus FP16; INT4 quarters it. That is arithmetic, not a benchmark. What it buys you is throughput and the ability to fit a model on fewer or cheaper GPUs.

What it costs you is quality, and the cost is not uniform. Some tasks tolerate INT4 with no visible change; others degrade subtly in ways your evals will catch and your users will not report. Quantize, then re-run the full eval suite, then compare CPSO — not latency alone.

Also note where the bottleneck actually is. Decode is usually memory-bandwidth bound, so quantization helps there more than it helps prefill. If your workload is long-input, short-output, quantization may be the wrong lever and caching is the right one.

RAG data hygiene: how do you cut context window bloat?

RAG hygiene means fixing retrieval quality so you retrieve fewer, better chunks. Most retrieval cost problems are relevance problems wearing a costume. If you are sending eight chunks, four of which are near-duplicates of each other, the fix is deduplication and reranking, not a smaller model.

Where the bloat comes from, and what to do:

  • Overlapping chunks. Deduplicate on content hash before assembly.
  • No reranker. Retrieve wide, rerank narrow, then send only the top few. The reranker is cheap; the context it removes is not.
  • Missing metadata filters. Filter by tenant, date or document type in the query, not in the prompt.
  • Boilerplate in chunks. Strip headers, footers and navigation before indexing.
  • Uncapped top-k. Set a hard ceiling. Someone will raise it during an incident and forget.

If you are still deciding whether retrieval is the right architecture at all, RAG vs. fine-tuning for production LLMs is the decision framework I would use before optimizing either.

Multi-agent system cost control: where do the hidden costs hide?

Multi-agent cost is multiplicative, not additive. Every hop resends accumulated history, so a five-step workflow with growing context costs far more than five single calls. The hidden cost is not the extra model calls — it is the context attached to them.

Controls that work:

  • Summarize between agents. Pass a structured summary, not the full transcript.
  • Cap turns per workflow. A hard ceiling with a graceful failure path beats an unbounded loop.
  • Cap spend per workflow. Budget per user action, not per day. Daily caps let one bad workflow eat the month.
  • Trace every hop. Cost per trace, attributed to the workflow, is the only way to find the expensive branch.
  • Kill the verifier that never disagrees. If a checking agent approves everything, it is pure cost.

API vs self-hosted LLM cost breakdown: where's the break-even?

The break-even is a utilization question, not a size question. Self-hosting wins when you keep GPUs busy; it loses badly when you do not, because you pay for idle capacity at full rate. Managed APIs bill per token, so idle costs nothing.

FactorManaged APISelf-hosted
Cost shapePer tokenPer GPU-hour
Idle costZeroFull
Ops burdenLowReal — drivers, autoscaling, upgrades
Data residencyProvider-dependentYou control it
Model choiceWhatever is servedWhatever you can run
Latency floorProvider-dependentYours to tune
Wins whenVariable or low utilizationSustained high utilization

For most teams reading this, the honest answer is that you are below break-even and should stay on APIs. If you are near it, serverless GPUs for AI inference is the middle path worth costing out — you get per-second billing without owning the cluster.

The 2026 LLM cost checklist

Work down this list before you touch model selection.

  1. Instrument spend per feature, per customer, per outcome.
  2. Build an eval suite that labels runs pass or fail.
  3. Compute CPSO for your top three workflows.
  4. Stabilize prompt prefixes and turn on context caching.
  5. Add routing with a logged route per request.
  6. Deduplicate and rerank retrieval; cap top-k.
  7. Summarize between agents; cap turns and spend.
  8. Quantize only if self-hosting, and re-run evals after.
  9. Re-check the API vs self-hosted math quarterly.

If you are building this into a product rather than a research notebook, our founder's checklist for launching scalable AI apps covers the surrounding decisions — auth, billing, background jobs — that quietly determine whether cost work survives contact with production. The click-by-click version of anything above lives in the docs on code-anything.com.

FAQ

What is cost per successful outcome in LLM inference?

It is total inference spend divided by the number of outputs a user would accept. It prices retries, failed tool calls and escalations into the same number as the tokens, which makes it a better routing and model-selection signal than price per million tokens.

Does context caching really cut LLM costs by 90%?

Not reliably. Vendors quote prefill savings up to 90% on repeated prefixes, but that assumes a stable prefix, a warm cache and a hit rate high enough to beat the cache-write cost. Change one line near the top of your prompt and the saving goes to zero.

Is quantization worth it if I use a managed API?

No — quantization is a self-hosting lever. If you call a managed endpoint, the provider has already made that decision. Your equivalent levers are routing, caching and retrieval hygiene, all of which reduce tokens rather than cost per token.

How many chunks should RAG send to the model?

Fewer than you think, and it should be a hard cap rather than a default. Retrieve wide, rerank, then send only the chunks that survived reranking. If two chunks say the same thing, one of them is pure cost.

When does self-hosting LLMs become cheaper than an API?

When sustained utilization is high enough that GPU-hours cost less than the equivalent token spend, and when you have the headcount to run it. Below that, the API wins on cost and you keep the ops time for something else.

Stop reading. Start shipping.

Describe what you want and watch it build — or connect a repo and ship a reviewed PR.