Skip to content
Ask for a Budget
EngineeringMarch 3, 20263 min readUpdated on November 11, 2026

Cutting generative AI costs: caching, routing and per-user limits

Where generative AI cost really adds up, when to use exact or semantic cache, how to route by complexity, contain retry loops, plus a budget checklist.

Cutting generative AI costs: caching, routing and per-user limits
Índice do artigo
faltam 3 min de leitura

AI costs do not explode "out of nowhere".
They explode when you go to production without limits, without cache and without routing.

LLM applications have a variable cost that is scary for two reasons:

  1. it grows with usage (which is good, but it must be predictable)
  2. it has outliers (one user can generate the cost of 1,000 users)

This guide brings together practical strategies to cut costs without killing quality.

Cover of the article about cutting AI costs

What you will find here

  • The main cost drivers (what really adds up)
  • How to reduce tokens without making the answer worse
  • Cache: exact and semantic (when to use each)
  • Model routing (small vs large)
  • Budgets and rate limits per user/tenant
  • A final checklist to control the budget

Cost drivers (what costs the most)

Cost usually comes from a combination of:

  • input tokens (prompt + history + RAG context)
  • output tokens (answers that are too long)
  • number of calls (retries, tools, multiple steps)
  • "large" models used for everything
  • no cache

Diagram: cost funnel in an LLM application


1) Reduce input tokens (without losing context)

The biggest lever is usually context.

Good practices:

  • do not send the whole history: summarize it and keep structured state
  • avoid the "encyclopedia prompt": keep fixed instructions separate and lean
  • in RAG, use a few high-quality chunks (with reranking)
  • apply size limits to user input (and handle huge messages)

If you have not structured RAG yet, it is worth reading: RAG in practice.

2) Control output tokens (a short answer is a feature)

Long answers cost more and hurt UX.

Simple techniques:

  • set a "maximum of X lines" for standard answers
  • use formats: lists, bullet points, a short table
  • only generate long text when the user explicitly asks for it

3) Exact cache (the "cheap" option that works)

Exact cache is when you reuse the answer for the same input and the same context.

It works very well for:

  • FAQs
  • repeated internal prompts
  • answers with low variability

Precautions:

  • include the prompt/model version and the RAG configuration in the cache key
  • define a TTL and invalidation when content changes

4) Semantic cache (when many people ask "almost the same thing")

Semantic cache reuses an answer when the question is similar, not identical.

Example:

  • "How do I change my password?"
  • "How do I reset my password?"

Tips to get it right:

  • only use semantic cache for stable, non-sensitive topics
  • scope it by category/tenant (do not mix contexts)
  • have a fallback to generate from scratch when confidence is low

5) Model routing (do not use a sledgehammer to crack a nut)

Not every task needs an expensive model.

A common strategy:

  • use a cheaper model for triage/classification
  • use the strongest model only when needed

Example of routing by complexity:

  • if the question is short and in the FAQ → small model + cache
  • if it involves multiple sources → strong model + RAG
  • if it involves an action → strong model + tool calling + validation

6) Limits per user/tenant (what prevents "unbounded consumption")

Without limits, a single user can generate cost with no ceiling. OWASP treats this as risk LLM10:2025, Unbounded Consumption, which includes denial of service and the so-called Denial of Wallet: an attack that targets your bill, not your availability. OWASP itself recommends rate limiting and per-user quotas as mitigation.

Practices:

  • rate limit per user (requests/minute)
  • budget per tenant (maximum cost/day)
  • token limit per request
  • blocking abusive patterns (huge messages, loops, retries)

7) Avoid silent loops and retries

A common bug pattern:

  • tool fails → retry
  • the model "tries again" → calls the tool again
  • it becomes a loop and costs explode

Mitigation:

  • a limit on attempts per step
  • a circuit breaker for unstable tools
  • a fallback to an "I could not complete this right now" answer

8) Make cost observable from day 1

Without visibility per route/feature, you do not know where to optimize.

Minimum viable:

  • estimated cost per request
  • cost per feature
  • top 20 outliers per day
  • cost per user/tenant

This is LLMOps: LLMOps: metrics and logs.


Final checklist (cost control)

  • Limits on user input and on context sent to the model
  • Answers with a size limit (by default)
  • Exact cache for FAQs and repeated questions
  • Semantic cache with rules (only stable, non-sensitive topics)
  • Model routing by complexity
  • Budgets and rate limits per user/tenant
  • Retry limits and loop prevention
  • Dashboard with cost per request/feature + outliers

References

If cost has already become a decision criterion, connect this checklist to a commercial architecture for generative AI for companies and LLMOps to monitor cost, quality and latency.

Also read

What is DevOps?Understanding the Angular frameworkAPIs and microservices: the reinvention of technology
Previous post
AI content without becoming spam: editorial process and SEO
Next post
AI-assisted development: a checklist for speed with control
Newsletter

One email a month, no noise

What we learn shipping custom software and applied AI.

Related articles

What is DevOps?4 min · Engineering
Understanding the Angular framework2 min · Engineering
APIs and microservices: the reinvention of technology2 min · Engineering
Blockchain APIs: what can we learn from the application?2 min · Engineering
Docker: smart storage2 min · Engineering

Accelerate your business with X-Apps

Ask for a Budget
X-Apps is an IT provider partner and advised by
Gartner
Receive our e-mails
News on software and applied AI.
Follow X-Apps