- −75%
- monthly LLM bill
- 6 weeks
- from first look to live
- 97% parity
- on 500 real questions
A customer came to us with a problem many teams have now. Their high-traffic, customer-facing AI chatbot handles about 12,000 messages a day and works well, but its LLM bill had become one of their largest monthly costs, and it grew with every new user. They asked us one thing: bring it down, without making the answers worse.
Six weeks later, the same chatbot runs at about 25% of the original cost, answers faster, and scores the same on quality. This is the full story: the problem, the goal, the architecture before and after, how we rolled it out safely, and the numbers.
The problem
The bot was built the way most first versions are: simple, reliable, and expensive at scale.
- Every message went to the largest model, including “what are your working hours?”.
- Every call carried everything: the whole conversation so far plus eight retrieved documents, about 6,100 input tokens on average.
- Nobody could see cost per conversation, only the monthly invoice, so there was no way to tell which kinds of question were expensive.
The goal
We agreed the target with the customer before touching anything, written so that either side could check it:
- Specific
- Cut the chatbot’s LLM spend without changing the product, the main model or the answers customers get.
- Measurable
- At least 60% lower monthly spend on the provider invoice. At least 95% answer parity on a 500-question test set, handoffs to humans no higher than 4.1%, and p95 response time no slower than today’s 4.8 s.
- Achievable
- Four weeks of logs showed heavy repetition and long prompts. Both are fixable with known techniques, with no retraining and no product change.
- Relevant
- LLM spend was growing faster than revenue: every new customer made the bot more expensive to run.
- Time-bound
- Live within 8 weeks, with a full week in shadow mode before switching over.
What the data showed
Week one was measurement only. Four weeks of real conversations, anonymised, gave three findings:
- 55% of messages were repeats. Grouped by meaning, they came down to about 400 questions asked in different words.
- About a third of the rest were simple. Single-fact answers straight from the help docs, which a small model answers just as well.
- Most of each prompt was padding. Of the ~6,100 input tokens, 52% was old conversation history and 34% was retrieved documents, most of them irrelevant to the question.
The new architecture
We didn’t replace the bot. We put five components in front of the model call:
1. Check: is this personal, and what is it about?
Every message is first tagged. If it’s about one customer’s own account or order (order numbers, “my plan”, “my refund”), it is marked personal and never touches the cache. Rules catch the obvious cases and a small classifier catches the rest; when in doubt, it’s treated as personal. The topic (how-to, policy, pricing, account) sets how long an answer may be cached.
2. Semantic cache, with expiry
General questions are turned into embeddings and matched against answers already given. An answer is reused only if the meaning is close enough (similarity 0.92 or higher), the topic matches, and it hasn’t expired. We tuned that threshold on 3,000 labelled question pairs; at 0.92, reviewers found wrong matches in 0.4% of a sample, and those were near-identical answers.
- Expiry by topic: how-to answers 7 days, policies 24 hours, prices and availability 1 hour.
- Changed docs clear the cache: when a help article changes, every cached answer built from it is dropped.
- Only good answers stay: an answer that gets a thumbs-down or leads to a human handoff is removed.
3. Router: the big model only when needed
Cache misses go to a small classifier trained on 6,000 labelled real messages. It decides whether the small model is enough and how sure it is. Below 80% confidence, the message goes to the large model. Complaints, refunds and anything legal always do. In practice about one in three cache misses goes to the small model, at roughly an eighth of the price.
4. Context compression: send only what matters
Instead of the whole conversation, the model gets a short running summary, the last two turns word for word, and any older turn that’s relevant to the current question. Retrieved documents are re-ranked and trimmed to the three most relevant passages. Average input fell from 6,100 to 3,700 tokens, with the same answers on the test set.
5. Logging and quality checks on every request
Every request records its tokens, cost, model, cache hit and response time. Every day, 200 answers are scored automatically against the test set’s standard and 30 are checked by a person. Alerts fire if quality dips or cost per conversation jumps, and each component sits behind a feature flag, so any one of them can be switched off in seconds.
How we rolled it out
Nothing reached customers until its numbers were proven in shadow mode first.
- Week 1Measure
Exported four weeks of anonymised logs, priced every conversation, and built a 500-question test set from real traffic with answers the support team signed off.
- Week 2Cache in shadow
The cache ran beside the live bot, logging what it would have answered. We tuned the similarity threshold and expiry times on this data. No customer saw it.
- Week 3Cache live
10% of traffic, then 50%, then 100%. By the end of the week, the biggest saving was already in.
- Week 4Router trained
Labelled 6,000 real messages as “small model is enough” or “needs the large model”, trained the classifier, and ran it in shadow.
- Week 5Router and compressor live
Both behind feature flags at 10%, then 50%. Quality checks ran on every step-up.
- Week 6Full stack, then switch
The full new path answered in shadow for a week. Parity held at 97%, so we moved 100% over and kept the old path as a one-click fallback.
Where the savings came from
The order matters: the cache took most of the easy questions, so the router had less left to save than we first estimated.
| Step | Impact | Why |
|---|---|---|
| Semantic cache | Biggest saving | over half of all messages no longer reach a model |
| Router | Medium | about one in three remaining calls moves to the small model |
| Context compression | Medium | every remaining call sends ~40% fewer tokens |
| New parts (embeddings, vector store, router) | Small added cost | all run on Nyas next to the app |
Results against the goal
| Measure | Goal | Result |
|---|---|---|
| Monthly LLM bill | ≥ 60% lower | 75% lower |
| Answer parity, 500 questions | ≥ 95% | 97% |
| Handoffs to a human | ≤ 4.1% | 4.0% |
| p95 response time | ≤ 4.8 s | 3.1 s (cache hits ~150 ms) |
| Time to live | ≤ 8 weeks | 6 weeks |
Three-quarters of the bill, saved every month from here on, and the bot got faster.
Why we could do it in six weeks
We didn’t learn this on the client’s money. We run the same pattern on our own platform, where we pay our own LLM bill every day.
- AgentOS shows cost per run. Our agents log the tokens, model and cost of every run. We’d already seen the pattern (repeats, big models on small jobs, bloated prompts), so week one went into confirming it, not discovering it.
- Anchor is built on sending only what matters. Our company memory gives an agent only the context a task needs. The compressor applies the same idea to a chatbot.
- Nyas hosted the new parts from day one. The cache, vector store and router run on Nyas next to the client’s app, with logs and metrics built in. Nothing to procure, nothing to wait for.
- Quality is a gate, not a hope. Test set, shadow mode and feature flags come as standard. We don’t switch anything over until the numbers say it’s safe.
- No lock-in. It works with whichever LLM provider you use, and your bot doesn’t need a rewrite.
What we learned
- Measure before you optimise. One week of data told us where the money went. Guessing would have started with the router, the smallest saving.
- The cache’s safety rules matter more than its hit rate. Never caching personal answers, and expiring by topic, is what made it safe to switch on.
- The levers stack, but in order. Caching removes calls, routing makes the rest cheaper, and compression makes every call smaller.
- Keep a way back. Feature flags and the old path on standby made every step reversible, which made every step easier to approve.
Is this you?
This fits best if LLM calls are a noticeable line in your monthly costs and your bot answers a lot of similar questions: support, sales, onboarding or internal help desks.