All posts
Resources9 min read

6 AI Caching Strategies to Reduce LLM API Costs

6 AI Caching Strategies to Reduce LLM API Costs
Ghita El Haitmy
Ghita El Haitmy
Software Engineer @ Eli · Oct 27, 2026

100 users can ask your app the same question, and your app can still pay for 100 separate AI answers. For an unchanged public FAQ, a valid cached answer could let you generate once and reuse it for the other 99 requests.

Repeated questions are only one source of wasted work. Your app may also resend the same instructions, re-embed unchanged documents, repeat an extraction step, or launch several identical requests at once.

These six AI caching strategies address those different problems. You can use them in apps built with hosted AI APIs; you do not need to run your own model or manage GPU memory.

The first distinction matters: prompt caching can make eligible input cheaper, while answer caching can avoid another generation call altogether. Embedding and step caches save work in specific parts of your application.

You can see the six patterns in the animated caching guide.

What is AI caching?

AI caching means storing reusable work so your application can retrieve it instead of repeating it. The saved item might be a complete answer, a document embedding, the output of one workflow step, or a result that is still being generated.

A cache hit means a suitable saved item was found. A cache miss means your app needs to do the work. The important word is suitable: the same question can need a different answer when the user, permissions, source data, or product version changes.

Here is what each strategy is designed to reuse:

  • Prompt caching: repeated input at the beginning of an AI request.
  • Exact answer caching: a completed answer for the same relevant request.
  • Semantic caching: an answer that also fits a differently worded question.
  • Embedding caching: a vector already computed for unchanged text.
  • Step caching: the result of a reusable intermediate operation.
  • In-flight caching: one pending result shared by concurrent duplicates.

1. Prompt caching: pay less for repeated input

Many AI requests start with the same material: your app’s instructions, examples, tool definitions, or a reference document. Provider prompt caching can reuse the processing of an eligible unchanged beginning, usually called the prompt prefix.

The model still generates a new answer. Cached input is billed according to the provider’s cache pricing, and writes may have a separate rate. The official OpenAI documentation explains its model-specific matching, eligibility, and cache controls.

Example: a customer-support assistant

Your assistant uses the same 8,000-token product handbook for many questions. Keep that stable material first, with each new question later. Where the provider supports explicit cache boundaries, configure a boundary after the shared material. Check actual cache usage rather than assuming every repeated handbook will hit.

Tools to use

  • OpenAI prompt caching: provider-managed reuse with usage reporting and cache diagnostics; configuration varies by model.
  • Claude prompt caching: supports automatic caching and explicit cache breakpoints, with documented cache-read and write pricing.

Watch for changing content at the beginning of the request. A fresh timestamp or rewritten instructions can prevent later shared content from matching. Compare total cost, including cache writes, instead of looking only at the read discount.

2. Exact answer caching: reuse a completed response

An exact answer cache checks for a saved response before calling the model. On a valid hit, the application returns that answer. On a miss, it calls the model and stores the result.

The Vercel AI SDK documentation demonstrates this pattern with caching middleware around model generation. Your production implementation also needs appropriate keys, expiry, and storage.

Example: answering a public product FAQ

A hundred people ask how to export a CSV from the same product version. If the instructions are public and unchanged, the first response can be saved and the next 99 matching requests can reuse it. That avoids 99 generation calls in this example; it does not imply a 99% reduction in your app’s entire AI bill.

Tools to use

  • Vercel AI SDK middleware: a useful integration point for checking a response cache before generation.
  • Upstash Redis: a shared key-value store whose SET command supports expiration, useful when several app instances need the same cached answers.

Make the key describe the relevant request, not just the question. Include the model, prompt version, source-data version, important settings, and authorization scope. A private answer for one customer must not become a shared answer for everyone.

3. Semantic caching: match meaning across different wording

Exact matching misses paraphrases. Semantic caching searches for a previously answered question with a similar meaning, then reuses the answer only when it applies to the new request and context.

Example: subscription-support questions

“How do I cancel my subscription?” and “How can I stop my plan?” may share an answer for the same product, region, and account type. “Can I get a refund?” is related, but it asks for a different outcome. A similarity match should not automatically reuse cancellation instructions.

Apple’s Krites research examines this correctness problem. It verifies some near-matches asynchronously and promotes approved answers for future reuse. Its reported gains come from particular simulated workloads; they are not a universal savings estimate. Verification can also incur additional AI cost.

Tools to use

  • RedisVL SemanticCache: provides vector-based lookup, matching thresholds, expiration, and metadata filters for a custom implementation.
  • Redis LangCache: a managed or self-managed service that handles semantic lookup and embeddings, with APIs and SDKs for integration.

Start with a narrow set of repetitive, stable questions. Test both correct matches and questions that look similar but need different answers. Choose your threshold from those results; a high hit rate is not useful if the cached answers are wrong.

4. Embedding caching: stop embedding unchanged text

An embedding represents text as numbers so your application can search or compare it by meaning. If the text and embedding configuration have not changed, a stored vector can avoid another embedding API call.

Example: refreshing a searchable knowledge base

Suppose your knowledge base has 1,000 unchanged text chunks and your ingestion process runs five times. Recomputing every vector would mean 5,000 chunk-embedding operations. Reusing the first set would avoid 4,000 of those operations, assuming the cache remains available and the inputs stay identical.

Those are embedding-work savings. The model that answers a user’s question may still need a separate generation call.

Tools to use

  • LangChain CacheBackedEmbeddings: wraps an embedding model with a cache; use an appropriate model namespace and configure query caching separately when needed.
  • RedisVL EmbeddingsCache: stores and retrieves embedding vectors using exact matching, with optional expiration.

Include the text hash, embedding model, dimensions, input mode, and relevant configuration in the key. Re-embed changed content. Avoid assuming that saving vectors automatically handles document updates and deletions throughout your search index.

5. Step caching: reuse one stage of an AI workflow

An AI app often performs several operations before producing an answer. It may extract facts from a document, classify a request, retrieve information, and draft a response. Step caching saves a reusable intermediate result while allowing later stages to produce a fresh answer.

Example: asking several questions about one document

A document assistant first extracts structured facts, then answers questions about them. If ten questions use the same unchanged document and extraction instructions, your app can potentially run extraction once and reuse it nine times. Each final answer can still require its own AI call.

Tools to use

  • LangGraph node caching: lets you define cache keys and time-to-live policies for individual workflow nodes.
  • LlamaIndex IngestionPipeline: supports caching transformation results, useful for repeatable ingestion stages such as extraction and embedding.

Cache the smallest reusable operation. If the extraction key includes the new user question unnecessarily, every question may cause a miss. If it leaves out a relevant document or prompt version, it may reuse an outdated result. Choose storage that survives for the period in which reuse is expected.

6. In-flight caching: let duplicate requests share one AI call

A completed-answer cache cannot help while the first answer is still being generated. In-flight caching, also called request coalescing, lets concurrent callers with the same complete request key wait for one running operation.

Example: three identical requests arrive together

Your server receives three matching requests before any response has been saved. The first starts the AI call. The other two join its pending result. When it finishes, all three receive the result, and your app can save it in the completed-answer cache.

This shares one generation among three matching concurrent requests. A later request needs either a saved answer or a new operation.

Tools to use

  • p-memoize for JavaScript: memoizes async functions and can share only concurrent results when its completed-value cache is disabled with cache: false. Configure a key that captures all relevant arguments.
  • Go singleflight: suppresses duplicate calls for the same key while an operation is running and shares its result with waiting callers.

Local coalescing only coordinates the process that holds the pending work. If requests land on several server instances, use a shared coordination design when cross-instance suppression is required. Handle timeouts, cancellation, and failures so callers do not wait indefinitely or reuse a permanently failed entry.

Which AI caching strategy should you implement first?

Start with the work your app demonstrably repeats. For a typical API-based app, a reasonable rollout is:

  1. Measure input tokens, output tokens, embedding usage, latency, and cost per successful user task.
  2. Check provider prompt caching for large, stable prefixes. Confirm hits and total cost in usage reporting.
  3. Add exact answer caching for stable requests that are safe to reuse.
  4. Add in-flight sharing where duplicate concurrent requests occur.
  5. Cache embeddings and expensive workflow stages when repeated ingestion or intermediate work is significant.
  6. Introduce semantic reuse after you have evaluation examples for both safe matches and harmful near-matches.

These layers can work together. An exact answer hit may bypass the whole generation path. On a miss, a fresh response might still benefit from prompt caching and a cached extraction step. Measure the combined result so you do not count the same avoided work more than once.

How to tell whether your cache is saving money

Track savings at the layer where they occur. For provider prompt caching, compare ordinary input, cache reads, cache writes, and output costs. OpenAI exposes cache-related usage fields and diagnostics in its prompt-caching guidance.

For application caches, track how often a valid hit avoids an API call or a workflow step. Include the cost of cache storage, lookups, embeddings, and any verification in the comparison.

Also measure answer correctness and freshness. A useful dashboard shows successful tasks and real provider spend alongside cache hits. Test representative traffic with caching enabled and disabled before attributing a cost change to the cache.

A practical rule: use caching when the value of safely avoided work exceeds the cost of finding, storing, and validating that work.

Frequently asked questions

Does caching reduce tokens or just reduce their price?

It depends on the layer. Provider prompt caching generally changes the cost of eligible reused input. An application answer-cache hit can avoid another generation call. Embedding caching avoids re-embedding; step caching avoids the work performed by that step.

Can I cache answers across different users?

Only when those users are allowed to receive the same answer and its context is shared. Public FAQ instructions may qualify. Private account information, permission-specific results, and personalized conversation state require appropriately scoped keys and access checks.

How long should an AI cache last?

Match its lifetime to how long the result remains useful. A source-data or prompt-version change may require invalidation before a time limit expires. Provider-managed caches have their own supported lifetimes and pricing; application caches need an explicit expiry or invalidation policy.

Is semantic caching the same as RAG?

No. RAG retrieves supporting information to help generate an answer. Semantic answer caching looks for an existing answer that can already satisfy the request. A RAG application can use both, but a semantic hit must still be appropriate for the current question and context.

See what ELI finds in your stack.

Connect one source. Five minutes. Free to start.

Connect your stack →