AI & Automation

Cutting LLM Costs Without Cutting Quality: Routing, Caching and Smarter Prompts

AI features that delight in a demo can bankrupt a product at scale. Here are the techniques, from model cascades to caching, that keep your bill sane.

By · Published · Updated · 5 min read

A green seedling growing from a pile of coins

Prototype: ten test users, a few dollars a week. Launch: ten thousand users, each triggering several model calls, and suddenly AI is your largest line item. Cost is one of the main reasons AI projects stall. Gartner’s forecast that more than 40% of agentic AI projects will be cancelled by the end of 2027 cites escalating costs alongside unclear value and weak risk controls.[3]

The good news: most AI spend is wasteful in ways that are easy to fix.

Where the money actually goes

Model pricing is typically per token, with output tokens costing more than input tokens, and larger models costing much more than smaller ones. Your bill is therefore driven by four levers: which model, how long the prompt, how long the answer, and how many calls.

LeverWasteful patternCheaper pattern
Model choiceLargest model for every requestSmall model for easy tasks; large model for hard ones
Prompt lengthWhole documents and long histories on every callRetrieve only relevant passages; summarise history
Output lengthOpen-ended essaysTight format and explicit length limits
Call countSame question answered again and againCache and de-duplicate

1. Route by difficulty: model cascades

The FrugalGPT paper described strategies for cutting cost, including LLM cascades: send a query to a cheaper model first, check whether the answer is reliable, and escalate to a stronger model only if it is not. The authors reported that their approach could match the performance of a top model with cost reductions of up to 98% on the tasks studied.[1] Your savings will vary, but the principle is sound: most traffic is easy.

async function answer(question, context) {
  // Step 1: try the cheap, fast model.
  const draft = await cheapModel.complete({ question, context });

  // Step 2: decide whether to trust it. Cheap checks first.
  const confident =
    draft.citations.length > 0 &&            // grounded in sources
    !draft.text.includes('NOT SURE') &&      // model did not hedge
    passesSchema(draft);                     // output is well-formed

  if (confident) return draft;

  // Step 3: escalate only the hard cases.
  metrics.increment('llm.escalated');
  return strongModel.complete({ question, context });
}

Track the escalation rate. If 85% of requests are handled by the cheap tier, you have cut your bill dramatically. If 60% escalate, your routing check or your prompt needs work.

2. Cache what repeats

  • Exact-match cache. Hash the normalised prompt; if you have answered it before, return the stored result instantly. Ideal for FAQs, classification and extraction on repeated inputs.
  • Semantic cache. Reuse an answer when a new question is close enough in meaning to a cached one. Set a strict similarity threshold and never use it for personalised or time-sensitive answers.
  • Provider prompt caching. Many providers discount repeated prompt prefixes, such as a long system prompt or document you send with every call. Put the static content first and the changing question last so the prefix stays identical.

3. Shrink prompts and outputs

  1. Trim the system prompt. Long rambling instructions are paid for on every request. Edit ruthlessly.
  2. Retrieve, do not paste. Send the five relevant passages, not the 200-page manual. See RAG explained.
  3. Summarise conversation history rather than resending every turn.
  4. Constrain the output. Ask for JSON with fixed fields, or “answer in under 60 words”. Shorter outputs are faster and cheaper.
  5. Batch non-urgent work. Offline jobs such as nightly classification often qualify for cheaper batch pricing with many providers.

Measure before you optimise

Teams often start by switching to a cheaper model and only later discover that most of their spend came from one feature. Instrument every model call with the feature name, model, input tokens, output tokens, latency and cost. After a week of data, sort by total spend. The top two or three features usually account for most of the bill, and those are where the effort belongs.

LeverTypical effectRisk to watch
Route easy tasks to a smaller modelLarge savings on high-volume simple workQuality dips on edge cases; keep an evaluation set
Cache identical or near-identical requestsRemoves repeat cost entirelyStale answers; set sensible expiry
Use provider prompt caching for long fixed promptsCheaper repeated prefixesNeeds a stable prompt structure
Trim context and retrieved passagesFewer input tokensCutting out needed information
Cap output lengthFewer output tokensTruncated answers
Batch non-urgent workLower per-request pricing where offeredSlower results

Guardrails that protect your budget

  • Hard spending limits per day and per customer, with alerts at 50 and 80 percent.
  • Loop protection. Agents that retry or call tools repeatedly need a maximum step count.
  • Rate limiting. One abusive user or a bug in a client app should not be able to drain the account.
  • Per-feature budgets. Give each feature an owner and a monthly target.
  • Foreign-exchange awareness. If you bill in KES but pay in dollars, build the exchange-rate risk into your pricing.

Do not save money by silently getting worse

Every cost change is also a quality change. Keep a fixed test set of real inputs with expected results, and run it before and after each optimisation. Compare accuracy, tone and failure cases, not only cost. If a cheaper route saves 40 percent but breaks 5 percent of customer requests, you may have lost more than you saved. Roll out changes to a small share of traffic first, and watch complaint and escalation rates.

Frequently asked questions

Is it cheaper to host an open model ourselves?

Sometimes, at high and steady volume, but you take on GPU costs, operations and security. For most small teams, managed APIs are cheaper once engineering time is counted. Compare total cost, not per-token price.

What is semantic caching?

It returns a stored answer when a new question is similar in meaning to an earlier one, even if worded differently. It can save a lot on repetitive questions, but set a strict similarity threshold and never cache answers that contain personal data.

4. Build cost discipline into the product

  • Meter per feature and per customer. You cannot optimise what you cannot see. Log tokens and cost with each request.
  • Set budgets and alerts. Cap spend per user per day and alert on unusual spikes, which also catch abuse and runaway loops.
  • Put limits on agents. Maximum steps, maximum tokens, maximum time.
  • Price accordingly. If a feature costs real money per use, factor it into your plans and fair-use limits.
  • Evaluate every optimisation. A cheaper model that quietly hurts quality is false economy, so run your test set before and after.

The best advice mirrors broader guidance on building with AI: start with the simplest approach that works, measure, and add complexity only where it pays for itself.[2] Often the cheapest AI request is the one you did not need to make.

References & further reading

  1. Chen, L., Zaharia, M. & Zou, J., “FrugalGPT: How to Use Large Language Models While Reducing Cost and Improving Performance” (2023), arXiv:2305.05176. https://arxiv.org/abs/2305.05176
  2. Anthropic, “Building effective agents”, on starting simple and adding complexity only when it pays off. https://www.anthropic.com/engineering/building-effective-agents
  3. Gartner, “Gartner Predicts Over 40% of Agentic AI Projects Will Be Canceled by End of 2027” (June 2025), citing escalating costs. https://www.gartner.com/en/newsroom/press-releases/2025-06-25-gartner-predicts-over-40-percent-of-agentic-ai-projects-will-be-canceled-by-end-of-2027