AI Strategy & Cost

How to reduce LLM API costs: where the money goes and what to try first

By the NeuralSaaS team · Updated · 6 min read

LLM API cost is the number of calls times the tokens in and out of each call, priced by the model you use. To reduce it, first measure cost per feature so you know where it goes. Then work in order: limits and alerts, remove wasted calls, send less context, cache what repeats, cap output length, move non-urgent work to batch, and only then route simple tasks to cheaper models. Each lever has a trade-off, so re-measure after every change.

Where does LLM API money actually go?

A model call is billed on the tokens you send in and the tokens it sends back, at rates set by the model. Output tokens are usually priced differently from input tokens, and some providers price repeated, cached input differently again. Check the rates on your provider's own pricing page, because they change.

That gives a simple formula for one operation: input tokens times the input rate, plus output tokens times the output rate. Monthly cost is the number of times the operation runs times that figure. Each term points at a lever: fewer calls, fewer input tokens, fewer output tokens, or a cheaper rate.

Spend often hides in the parts nobody reads: a long system prompt resent on every call, a conversation history that grows with each turn, retrieved documents that are larger than the question needs, an agent that loops, and retries that repeat an expensive call. Embeddings and speech calls add their own line items.

What should you measure before changing anything?

Measure per operation, not per request and not per account. A provider invoice tells you the total. It does not tell you that one feature, one customer or one runaway loop is driving it.

  • Record the input, output and cached token counts that come back with every response, tagged with the feature and the user or account.
  • Look at the spread, not only the average: your longest requests can cost far more than the typical one.
  • List your top consumers by feature, and note which run in the background and which a user is waiting for.
  • Keep a small set of real examples with the answers you consider good, so that every change can be checked for quality as well as cost.

If you have none of this yet, adding it is the first piece of work, and it is usually small.

Which levers reduce LLM costs, and what do they risk?

LeverWhat it doesWhen it helpsRisk
Spend limits and alertsStops or warns before spend runs awayAlways; protects against bugs and abuseHitting a limit blocks real users, so decide what degrades
Per-user rate limitsCaps how much one user or key can triggerPublic endpoints and free tiersLimits set too low frustrate legitimate use
Removing duplicate and needless callsCuts calls that repeat or that code could doEffects that fire twice, extra checking calls, date or format parsingLow, but check that the removed call was not doing something useful
Capping loops and retriesSets a maximum on agent steps and retry attemptsAgents, tool use, flaky upstream servicesLong tasks may stop early and need a handoff
Trimming contextSends only the text the task needsLarge prompts, whole documents, big retrieved setsDropping the right passage lowers answer quality
Windowing or summarising historyBounds what earlier turns add to each callLong conversationsThe model may lose early details
Prompt cachingReuses a repeated prefix at the providerA large static system prompt, tools or reference textHit rates vary; a changing prefix defeats it
Response cachingStores answers to repeated identical requestsFAQ-style questions, repeated document processingStale answers if the data or prompt changes
Output capsLimits reply length and reasoning effortShort-answer features, structured outputA cap set too low truncates useful answers
Batch interfaceSubmits non-urgent work to be collected laterNightly jobs, backfills, bulk classificationResults are delayed; not for live users
Model routingSends easy tasks to a cheaper modelMixed traffic with many simple requestsQuality loss; needs an evaluation set and monitoring
Embedding reuseSkips re-embedding unchanged contentSearch and RAG systems that re-index oftenStale vectors if change detection is wrong

In what order should you try them?

  • Guardrails first: spend limits, alerts and per-user limits. They cap the worst case before you optimise anything.
  • Measure per feature, as above.
  • Remove waste that has no quality cost: duplicate calls, unbounded loops and retries, history that grows forever, whole documents where a section would do.
  • Trim context and cache what repeats. Check the quality of answers on your examples after each change.
  • Cap output length and move non-urgent work to the batch interface.
  • Try routing to cheaper models last. It carries the most quality risk and needs the most testing, so do it once the cheaper wins are taken.

Change one thing at a time and re-measure. When two levers touch the same tokens, their savings do not simply add up.

What about the savings figures you see online?

Most percentages quoted for caching, routing or batching come from vendors or blog posts, and they describe somebody's traffic and prompts, not yours. A saving depends on how much of your prompt repeats, how many requests are simple, how much work can wait and what quality you must keep.

Treat any figure as a range with assumptions written beside it, and replace the assumptions with your measured values. The llm-cost-audit skill and the AI Bill Doctor calculator are built that way: they ask for your numbers, show the arithmetic and label the ranges as vendor-reported, to measure yourself. Neither promises a result.

How can you review your own code for these gaps?

The free llm-cost-audit skill runs inside your own AI agent. It reads your repository, lists every LLM call and the model it uses, checks 30 points across limits, context size, caching, loops and retrieval, and ranks the opportunities by effort, impact and confidence. It is read-only and does not know your prices unless you tell it.

Running costs also depend on how the system was designed in the first place. The guide on what drives the cost of an AI agent project covers the build side and the running side together.

Frequently asked questions

Where does LLM API money go?

Cost is the number of calls times the tokens in and out of each call, priced by the model you use.

What should I do first to reduce LLM costs?

Measure cost per feature so you know where it goes, then set limits and alerts before changing anything.

Which levers help, and in what order?

Remove wasted calls, send less context, cache what repeats, cap output length, move non-urgent work to batch, and only then route simple tasks to cheaper models.

Can I trust the savings figures I see online?

Treat them with care. Each lever has a trade-off, so re-measure on your own workload after every change.

Working on something like this?

Describe the workflow and we will tell you what is realistic and what a sensible first step looks like.

Keep reading