Own Weights

Semantic caching for LLMs: skip calls you already paid for

Semantic caching for LLMs: reuse answers to similar prompts so you skip paid API calls, and find the cache hit rate where it starts to pay off.

Updated

Semantic caching for LLMs stores the answer to a prompt you already paid a model to answer. When a new prompt means the same thing as a stored one, the app returns the saved answer and skips the API call.

It works best on traffic that repeats, such as support questions, FAQ lookups, and document questions. It is cheap to build and easy to break, so this page covers how it works, where it beats provider features, and the hit rate you need before it pays.

What does semantic caching mean for an LLM app?

An exact cache matches identical text. A semantic cache matches meaning. Each prompt becomes an embedding, a list of numbers where similar text sits close together. The cache holds past prompts and their answers. A new prompt searches those embeddings for its closest match. If the match is above a similarity threshold you choose, the stored answer comes back. If not, the call goes to the model and the new pair is saved.

The cache key needs more than the prompt text. Include the model name, the version of your system prompt, the tool list, and settings such as temperature. Two identical questions with different system prompts should not share an answer.

Semantic cache vs prompt caching: which one do you need?

These two features get mixed up, but they do different jobs. Provider prompt caching reuses the processing of a long repeated prefix, such as a long system prompt. The model still runs and writes a new answer, so you save only on input tokens.

Semantic caching lives in your application. It stores finished answers and skips the model call on a hit, so it removes whole calls, not just input tokens. You can use both. Check your provider’s pricing page for how its prompt cache is billed.

How do you cache LLM responses to save money?

Work in this order:

  1. Start with exact matches: hash the normalized prompt with the settings. This never returns a wrong answer for a different question.
  2. Add embedding lookup for near matches once exact matching is working and logged.
  3. Set the similarity threshold on labeled pairs. Collect prompts your team knows are the same question and prompts that are different questions, then pick the threshold where wrong matches are rare.
  4. Give every stored answer a time-to-live, and expire it early when its data changes. A cached price or policy goes stale.
  5. Log each hit with the id of the stored answer, so a bad hit can be traced and removed.

A false hit returns a confident wrong answer. That costs more than a miss, so set the threshold strict and loosen it only with evidence.

Deduplicating LLM requests before they reach the API

Deduplication is the cheapest first step. Apps often send the same prompt several times in a short window, such as a user who clicks twice, a batch job that reprocesses a file, or a retry loop around a slow call.

Give each request a key. Duplicates that arrive while the first call is still running wait for its result, so only the first request reaches the model. This is in-flight deduplication, not caching, because the answer is shared only while the call is in progress. A retry after a failed call still has to go through. Count the duplicates in your logs first. That number tells you how much this step removes.

If you already run offline work, read batch API vs real-time calls to see which calls can wait for the half-price path.

How much does caching save on an AI API?

The saving depends on the hit rate, the share of calls answered from the cache. Roughly, it is the hit rate times the cost of the calls you stop, minus what the cache costs to run: an embedding call per prompt, storage, and search.

Here is a hypothetical example with round numbers. Suppose an app makes 100,000 calls a month at $0.01 each, a $1,000 bill. If 30 percent of calls hit the cache, 30,000 calls stop, saving $300 before cache costs. If only 5 percent hit, the saving is $50, and a $60 lookup bill would cancel it out. These figures are invented to show the method. Your own numbers come from your logs.

Output tokens are often the bigger part of a hit’s saving. On Claude list prices, Opus is $4 per million input tokens and $20 per million output tokens. Haiku is $0.10 input and $0.50 output, for prompts up to 100K tokens.

When does the hit rate make caching worth it?

Caching pays when the same questions come back, as in internal help desks, FAQ search, product lookups, and support bots. Creative writing, open-ended chat, and unique inputs see few hits, so the lookup cost is wasted.

Measure first. Run the cache in shadow mode for a week of real traffic. It records what it would have returned but still calls the model every time, giving you a real hit rate and false-hit sample with no user impact. If the would-be hit rate is low, skip the cache.

Caching is the wrong fix when the model is the real cost. If the same narrow task keeps arriving with different wording, a cache misses most of the time, and a trained model may fit better. Own Weights fine-tunes an open-weight model for one high-volume task, tests it against the current model on your own data, and serves it in your cloud account or on-prem. To find out, take the prompts the cache missed during the shadow-mode week, have a person check the right answer for a sample of them, and score the current model and a trained candidate on that same sample.

Caching also stores data. Cached prompts can contain customer details, and cached answers can leak them to the next user with a similar question. Keep the store in your own environment, under your own access and retention rules. This is an engineering point, not compliance advice.

Run the free AI cost audit on one repository to see how much of your bill repeats. It lists your AI calls, models, and estimated cost, and flags calls with no caching. Get in touch if you want us to look at your traffic with you.

Questions

How much does caching save on an AI API?

It depends on the hit rate, the share of calls answered from the cache, and what the cache costs to run. Savings grow with traffic that repeats and stay close to zero for unique prompts. Measure hits on real traffic before you count on any saving.

What is the difference between semantic cache and prompt caching?

Prompt caching is a provider feature that makes repeated long input cheaper, but the model still runs on every call. Semantic caching runs in your application and returns a stored answer, so a hit makes no model call at all.

Can I cache LLM responses to save money?

Yes, if your traffic repeats. Store finished answers under a key made from the prompt and every setting that changes the output, and expire them when the data behind them changes. Start with exact matches, then add similarity matching after you check it on labeled pairs.

How do I deduplicate LLM requests?

Build a key from the normalized input and the settings, then make duplicate requests that arrive while the first is running wait for its result. Retries after a failed call still need to go through. Count the duplicates in your logs to see how much this step removes.