When does LiteLLM semantic caching pay off?
A semantic cache pays off only when a self-hosted LiteLLM gateway receives many prompts that are similar in meaning but differ in wording, and each answer can safely be reused. LiteLLM's semantic caching embeds the incoming prompt and returns the closest cached response whose cosine similarity clears the configured similarity_threshold. Responses served from the cache carry an x-litellm-semantic-similarity header, so your team can see how close each hit was. The documented backends are Qdrant, Valkey and Redis, which hold the vectors and cached responses. Before you run one, decide whether your traffic is a good fit, because the cost of a wrong answer is paid by users, not by the cache.
The LiteLLM documentation is explicit that semantic caching is designed for single-shot prompts, such as a question that stands alone, a classification request or a summarization job with no earlier turns. It warns that the cache will replay stale responses on multi-turn or agentic traffic. A follow-up such as "make it shorter" can embed close to an earlier, unrelated question, and the gateway will return the old answer. Coding agents, chat clients and tool-calling loops are the usual cases where this happens, so a gateway that serves both single-shot and agentic traffic needs the cache scoped to the routes or keys that qualify.
Before you choose a threshold, confirm three things with your own data: the share of requests that are truly single-shot, how often a cached answer would still be correct for a near match, and whether the responses contain user data that a shared cache may keep. Ask your team to replay a sample of recent prompts against a test cache and review the hits, especially those close to the threshold. Also confirm the embedding model, its cost and where it runs, because every request is embedded, including misses. If the review shows many wrong near matches, the cache is not paying off and the threshold or scope should change.
Which traffic suits a semantic cache and which does not
Semantic caching returns a stored answer when a new prompt looks close enough to an earlier one, so the risk depends on whether the answer depends on earlier turns, tools or the identity of the user. The cards below sort common traffic types by how much a replayed answer can cost, and what to check before enabling a cache with Qdrant, Redis or Valkey.
FAQ-style single-shot prompts
Each prompt stands alone, such as a question about a published policy or product feature. This is the traffic LiteLLM's semantic caching is designed for, because a cached answer to a similar standalone question is usually still correct. Check that the source content changes rarely, and set a similarity threshold that you have tested against paraphrases and near-miss questions, since a loose threshold can match questions with different answers. Expect stale answers after a policy changes unless you clear or expire the cache when the content does.
Semantic caching docsInternal help desk questions
Employees ask standalone questions about IT, HR or facilities, and many are phrased differently but mean the same thing. This makes a semantic cache useful, but answers often depend on the employee's location, role or current entitlements. A cached reply given to one group can be wrong for another. Confirm whether answers vary by group, and keep those answers out of the shared cache or scope cache entries by team before enabling it.
Coding agents
Coding agents send long conversations that include prior file reads, tool results and error output. Two prompts can look similar while the repository state differs, so a cached reply may suggest a fix for code that has already changed. LiteLLM warns that semantic caching replays stale responses on agentic traffic. Exclude coding agent routes from the semantic cache, and use it only on separate, single-shot endpoints if you need it at all.
Multi-turn chat
In multi-turn chat, the same final sentence can carry different meaning depending on the earlier messages. A prompt such as "make it shorter" is nearly identical across conversations but needs the context that precedes it. Embedding only the latest message ignores that history, so the closest match may come from an unrelated conversation. Treat multi-turn chat as out of scope for semantic caching, and confirm with your LiteLLM configuration that the cache applies only to the traffic you chose.
Tool-calling agents
Tool-calling agents make decisions based on live data, such as account balances, ticket states or search results. A cached answer may reflect data that has since changed, and a replayed tool plan can trigger the wrong action. Because the answer is produced after tool execution, the cache cannot see what the tools returned. Keep tool-calling requests out of the semantic cache, and check each route in the gateway before enabling caching globally.
Prompts with personal data
Prompts that include names, account numbers, health details or other personal data are a poor fit because the cache stores both the prompt embedding and the response. Similar prompts from different people can match, which can return one person's information to another. Before enabling a cache on any route that carries personal data, confirm the retention period, the access controls on Qdrant, Redis or Valkey, and how deletion requests reach cached entries. Qdrant's default configuration has no authentication, so confirm that access is restricted before storing anything sensitive.
Qdrant security docsConfiguration options and when each fits
This table compares the main settings for LiteLLM semantic caching and the backend choices behind them, with the trade-off each one brings. Read each row as a decision to make before enabling the cache, and confirm exact config keys against the LiteLLM semantic caching docs before you write them into configuration.
| Setting | When it fits | Trade-off to weigh |
|---|---|---|
| Embedding model | Use a model that matches the language and domain of your prompts so similar questions land close together in vector space. | A stronger embedding model usually costs more per lookup and adds latency on every request, including misses. Confirm the supported embedding providers in the docs. |
| similarity_threshold | Set high when wrong answers are costly, such as policy or clinical questions. Set lower only where paraphrase reuse is clearly acceptable. | A high threshold lowers hit rate. A low threshold returns answers to questions that only look similar, which is the main correctness risk. |
| Backend: Qdrant | Fits teams that already run Qdrant or want a dedicated vector store with filtering, access control and audit logging in infrastructure they control. | Adds a separate stateful service to operate. Qdrant needs block storage, and self-deployed instances need authentication and TLS configured before use. |
| Backend: Valkey or Redis | Fits gateways that already run a shared Redis-compatible service for rate limits and router state, so the cache adds no new platform. | Vector search capability and index setup depend on the Redis or Valkey build and modules in use. Confirm the required features with the LiteLLM docs and your service vendor. |
| Collection or index scope | Scope per application or team when cached answers must not cross data boundaries. Share one scope only where all callers may see each other's cached content. | Narrow scopes raise isolation and lower hit rate. Broad scopes improve reuse but make a cached answer from one team visible to another. |
| TTL | Set short lifetimes for content that changes often, such as product, pricing or policy text. Longer lifetimes suit stable reference material. | Short TTLs reduce stale replies but cut savings. Long TTLs keep answers that may no longer be correct. Confirm the TTL key and its default in the docs. |
| Per-request controls | Use per-request cache controls to bypass or refresh the cache for sensitive calls, debugging or multi-turn sessions where history matters. | Callers must set the controls correctly. Without a gateway-side policy, teams may skip the cache inconsistently. Confirm the supported request parameters. |
| Expose x-litellm-semantic-similarity to callers | Expose it in development and evaluation so teams can see how close a cached match was and tune thresholds. | Callers may learn cache behavior or make decisions on the score. Many production setups keep it internal to the gateway and logs. Confirm the header behavior in your version. |
Choosing Qdrant, Redis or Valkey as the semantic backend
Qdrant is a vector search engine built for similarity lookup, so it fits teams that want semantic cache vectors held in a dedicated store separate from their general cache. The open-source engine is licensed under Apache-2.0 and is free to self-host in your own infrastructure. It needs block-level storage with a POSIX-compatible file system, so it cannot run on NFS or on object storage such as S3, and SSD or NVMe drives are recommended. Plan for a separate service to deploy, secure and back up.
- Licensing: The engine is Apache-2.0 and free to self-host, so the cost lies in the infrastructure and the people who run it.
- Storage: Use block storage with a POSIX-compatible file system, preferably SSD or NVMe. NFS and S3 are not supported.
- Authentication: By default, self-deployed instances listen on all network interfaces with no authentication. Configure API keys, TLS and network restrictions before the gateway connects.
- Operations: Production clusters are documented with at least three nodes for quorum, so size the deployment before you commit to it.
- Managed options: Qdrant Cloud, Hybrid Cloud and Private Cloud are priced through Qdrant's pricing page or sales team, so ask which deployment keeps data in the regions and networks your rules require.
Confirm with your security team which Qdrant deployment model meets your residency and access rules before selecting this backend.
Redis suits organizations that already run a shared cache tier for their LiteLLM gateway. Once more than one proxy instance runs, LiteLLM's production guidance calls for Redis 7.0 or newer for shared rate limits, router state and cache, so the semantic cache can reuse infrastructure you already need rather than adding a new engine. The trade-off is that your cache tier now holds embedding vectors alongside exact-match data, which affects memory sizing and access control.
- Existing requirement: Multi-instance gateways already need Redis 7.0 or newer, so the semantic cache may add little new infrastructure.
- Memory: Vector storage increases memory use. Size the instance for embeddings and cached responses together, not only for rate limit state.
- Access control: Confirm that authentication, TLS and network placement on the existing Redis match the sensitivity of cached prompts and responses.
- Eviction and retention: Decide how long cached entries live and whether eviction could remove entries your team expects to find.
- Failure impact: If the shared tier is unavailable, confirm how the gateway behaves for cache lookups and for rate limits.
Check your current Redis version, memory headroom and authentication settings before deciding whether to reuse this tier.
Valkey is an open-source, Redis-compatible data store that LiteLLM supports as a semantic cache backend alongside Qdrant and Redis. It is a good choice when your organization has standardized on Valkey for its cache tier and wants the same operational model across services. Treat it the same way as Redis for planning: the gateway needs a shared store once several instances run, and the semantic cache adds memory and access control requirements to that store.
- Fit: Choose Valkey when your platform team already operates it as the shared cache for the gateway.
- Version and compatibility: Confirm the Valkey version and its compatibility with the LiteLLM release you run, since the supplied facts do not list version pairings.
- Memory and retention: Size memory for embeddings and cached responses, and set retention so stale entries do not accumulate.
- Security: Enable authentication and TLS, and keep the store on a private network segment reachable only by gateway instances.
- Shared state: Remember that the same instance may hold rate limit and router state, so changes affect more than the cache.
Before you commit, ask your LiteLLM support contact or your own test environment to confirm the Valkey version and settings for your release.
Why multi-turn agent traffic gets stale answers from the cache
Semantic caching matches on the wording of the latest message, so a follow-up question can match an earlier cached answer that was correct only for the earlier conversation. A user who asks "what is the limit on that account?" after an earlier question about a different account produces an embedding close to the earlier cached prompt, yet the right answer depends on the prior turns. LiteLLM's semantic caching documentation warns that the feature is designed for single-shot prompts and will replay stale responses on multi-turn or agentic traffic, so this is a design boundary, not an edge case to tune away with a higher similarity threshold.
Agent loops make the problem worse. An agent calls a model, receives tool results, and calls the model again with a context that changes at every step. The final prompt may look similar to a prompt from another session, but the correct response depends on tool output, file contents, database rows or API state that changed since the cached answer was written. A cache hit on any step can skip the model call that would have incorporated that new state, and the agent then acts on an answer that no longer matches the world. Teams should confirm with their agent framework which requests carry tool results, retrieved documents or accumulated history, and treat those requests as uncacheable by default.
Cache controls therefore need to exclude these flows explicitly, not rely on similarity alone. Plan the routing so that agent and coding tool traffic, identified by the key, team, model group or request metadata your gateway can see, bypasses the semantic cache, and restrict the cache to single-turn endpoints such as FAQ or classification calls. Check that each caching control applies per request as your LiteLLM version documents, then test a multi-turn conversation with a changed tool result and confirm the response reflects the new state. Record which request types are excluded so that a later change to an agent workflow does not silently re-enable caching.
A semantic cache hit returns early, while a miss calls the provider and stores the answer
The request enters the LiteLLM proxy, which embeds the prompt and queries the vector backend for the closest cached response. If the best cosine similarity clears similarity_threshold, the gateway returns the cached answer with the x-litellm-semantic-similarity header and makes no provider call. On a miss, the request goes to the provider, and the new response is written back to the cache. Check the threshold and the cache scope before trusting hits, especially on multi-turn traffic.
Hit returns early from cache; miss calls the provider and stores the result.
Setting up semantic caching step by step
This sequence takes a team from confirming that its traffic suits semantic caching to a verified LiteLLM proxy that serves similar single-shot prompts from a Qdrant, Redis or Valkey backend, with the similarity and staleness behavior checked before rollout.
Confirm traffic is single-shot
Review a sample of real request logs or a representative export from the workload that will use the cache, and confirm that each request is a standalone prompt rather than part of a multi-turn conversation or agent loop. LiteLLM warns that semantic caching replays stale responses on multi-turn or agentic traffic, so mixed workloads should be split, with only the single-shot routes enabled for caching. The step is done when the owning team signs off on a list of routes or keys that qualify, and that list is recorded alongside the configuration change.
Choose and deploy the embedding model
Select the embedding model that will turn each prompt into a vector, and host it or reach it through a provider that your data handling rules allow. Record the model name, vector dimension and where prompts are sent, because the same model must be used for every cached entry and every lookup. Confirm the model with your security and privacy owners before any production prompt reaches it. The step is done when a test call to the embedding endpoint returns a vector of the expected dimension for a sample prompt.
Deploy the backend with authentication and TLS
Deploy Qdrant, Redis or Valkey inside the same network boundary as the gateway, and confirm the version and deployment path against the vendor documentation. Qdrant does not secure itself by default: its self-deployed instances listen on all interfaces with no authentication, so configure an API key and TLS before connecting the gateway. Apply equivalent authentication and TLS settings to Redis or Valkey, and keep the store off public networks. The step is done when an unauthenticated request is rejected, an authenticated request succeeds over TLS, and the credentials are stored in your secret manager rather than in the proxy config file.
Set similarity threshold and TTL
Decide the cosine similarity threshold that a cached answer must clear before it is returned, and the time-to-live that limits how long an entry can be replayed. A high threshold reduces wrong-answer replays but lowers hit rates, while a low threshold does the reverse, so set the value from test results rather than from a default. Set a TTL that matches how quickly the underlying answers go stale for your use case. Write both values into the change record with the reason for each choice. The step is done when the threshold and TTL are documented and reviewed by the team that owns answer accuracy.
Enable caching in the proxy configuration
Add the semantic cache block to the LiteLLM proxy configuration, referencing the embedding model, the backend connection details and the threshold and TTL values, and scope it to the routes or keys confirmed in the first step. Load the secrets from the environment or secret manager, and deploy the change to a non-production gateway first. Confirm the gateway starts without errors and that the cache connection is logged as established. The step is done when the non-production gateway serves requests with caching active on the scoped routes and no requests on other routes touch the cache.
Verify with test prompts
Build a test set of paraphrased single-shot prompts, prompts that share wording but ask different questions, and prompts that should never match. Send each through the gateway in sequence and record whether the response came from the provider or the cache. Check that the paraphrases hit the cache, that the different questions do not, and that the answers returned from cache are still correct. The step is done when the test results show the threshold separates matching from non-matching prompts for the agreed test set.
Check the similarity header and staleness
For each response, inspect the x-litellm-semantic-similarity header and confirm that cache hits report a similarity value at or above the configured threshold. Repeat the test with a multi-turn conversation on a route that is meant to stay uncached, and confirm that no cache hit is returned there. Review how old entries behave after the TTL expires. The step is done when the header values match the expected pattern, the excluded routes never return cached answers, and the team records the results in its release notes before expanding the cache to more traffic.
Security and data handling for cached prompts and responses
A semantic cache stores prompts and responses outside the model provider, so it inherits the sensitivity of everything users send through the gateway. The cards below cover where that data sits, how to lock down the Qdrant store, how to audit access, how to protect the gateway key, and how to keep teams from reading each other's cached answers.
Cached data stays in your infrastructure
A semantic cache keeps the prompt text, the embedding and the full response in a store you run, so the data never leaves for the provider again but it is now a second copy of sensitive content. Prompts from support tickets, HR cases or patient notes can end up in that store if callers do not screen them. Confirm the retention period for cache entries, who can read the store, and whether personal data in prompts must be removed or masked before the cache write. Document the answers as part of the data flow for your privacy review.
Qdrant ships without authentication
By default, self-deployed Qdrant instances listen on all network interfaces and have no authentication configured, so any host that can reach the port can read or delete cached vectors. Place Qdrant on a private network, enable an admin API key and a read-only key, and turn on TLS for REST and gRPC, which Qdrant has supported since v1.2.0. Keep the admin key out of application configuration and limit it to the gateway's maintenance role.
Qdrant security docsPer-collection access with JWT
Qdrant's JWT-based access control, available since v1.9.0, grants read or write permissions per collection. Use it to give each team or environment its own collection and a token that cannot reach the others. Test the boundary by sending a token for one collection against another and confirming the request is refused. Write down which tokens exist, who issued them and how they are rotated.
Audit trail of Qdrant operations
Qdrant has written JSON audit logs of authenticated API operations since v1.17.0. Route those logs to the same SIEM or log store your gateway logs go to, so a cache read or deletion can be traced to a credential. Check that the logs record the collection and operation type, and that retention meets your policy. Note that these logs cover authenticated calls only, so enabling authentication is a prerequisite.
Protecting the LITELLM_MASTER_KEY
The LITELLM_MASTER_KEY, which must start with sk-, grants administrative control over the gateway, including the cache configuration and the keys that reach Qdrant or Redis. Store it in a secret manager and inject it at runtime rather than placing it in a configuration file or container image. Rotate it on a schedule and after staff changes, and restrict who can read the secret store entry.
Tenant isolation in a shared cache
A single cache shared across teams can return one team's cached answer to another team's similar prompt, which is a disclosure risk when the prompts reveal internal projects or customer details. Decide whether to run separate collections or separate Qdrant instances per team, and confirm that the cache key or namespace includes the team or key identity. Test with two teams sending near-identical prompts and verify that neither sees the other's response.
Questions teams ask before running semantic caching
What does semantic caching with LiteLLM cost to run?
The LiteLLM software and Qdrant's open-source engine are free to self-host under their licenses, so the cost sits elsewhere. You pay for the embedding model calls that turn every prompt into a vector, the compute and storage for Redis, Valkey or Qdrant, the network path between the gateway and the cache, and the engineering time to set up and test it. Embedding calls recur on every cache lookup, so their cost grows with traffic. Managed Qdrant pricing is published on the Qdrant pricing page, where the free single-node tier and usage-priced Standard tier are listed, while Hybrid Cloud and Private Cloud are quoted by Qdrant sales. Ask any partner for a written quote that separates one-time work from recurring infrastructure and model costs.
How long does semantic cache setup take, and what drives it?
Duration depends mainly on three things: how much of your traffic is single-shot and therefore safe to cache, how hardened the cache backend must be, and how much threshold testing your team wants before go-live. Traffic analysis means sampling real requests and grouping them by intent and conversation length. Backend hardening covers authentication, network binding and TLS, which Qdrant does not provide by default. Threshold testing needs a labeled set of prompt pairs and repeated runs. A fixed-scope written plan from a partner or your own team should state the duration for each phase, and you should confirm that estimate against your traffic before agreeing to it.
What do we need to provide before the work starts?
Plan to provide four things. First, representative traffic samples from the calls you want to cache, with personal data removed or masked under your own policy. Second, a test set of prompt pairs labeled as same-answer or different-answer, drawn from your domain experts. Third, access to the LiteLLM proxy configuration, the embedding model endpoint and the cache infrastructure in your cloud accounts, data centers or restricted network. Fourth, a named owner who can approve the similarity threshold and the list of routes that may use the cache. Without the labeled set, threshold choice becomes guesswork, so confirm early who will produce it.
Can our own engineers set up semantic caching without a partner?
Yes, if your team already runs the LiteLLM proxy, operates Redis or Valkey or Qdrant, and can maintain a labeled evaluation set. The configuration itself is small, but the risk lies in the decisions: which traffic is single-shot, which embedding model to use, where the threshold sits, how the backend is secured and how hits are monitored. LiteLLM's own documentation warns about replay on multi-turn and agentic traffic, so an internal team should read the LiteLLM semantic caching docs and test the route categories before enabling the cache. A partner is most useful when the team lacks time for threshold testing or security review.
How do we know a semantic cache hit is safe to return?
A hit is safe only when the cached answer would also be correct for the new request, and similarity alone does not prove that. LiteLLM returns the closest cached response whose cosine similarity clears your threshold, and each response carries an x-litellm-semantic-similarity header you can log. Check hits against a labeled set, record the score distribution per route, and disable the cache for multi-turn sessions, agent loops and requests that depend on user data, tools or time. Review a sample of hits regularly, because stale answers often appear only after source content changes.
Where does the cache store prompts, and is that a security concern?
The cache stores prompts and responses, so it holds the same sensitive content as your logs. Qdrant documents that self-deployed instances listen on all interfaces and have no authentication by default, so you must configure API keys, TLS and network restrictions before any production use. Redis and Valkey need similar access controls, encryption in transit and a retention limit on cached entries. Confirm with your security team where the cache sits, who can read it, how long entries live and whether they fall under your data handling rules.
Should we choose Qdrant, Redis or Valkey for the semantic cache?
Choose based on what your organization already operates and the vector search needs you have. Qdrant is a dedicated vector search engine, licensed under Apache-2.0, and needs block-level SSD or NVMe storage rather than network file systems. Redis and Valkey suit teams that already run an in-memory store and want one service for caching and shared state. Confirm the exact backend setup and supported versions with LiteLLM's current documentation and your vendor before you commit to one.
How DeployOpen scopes and delivers semantic caching
DeployOpen plans, builds and hands over LiteLLM semantic caching with Qdrant, Redis or Valkey inside infrastructure you control. We start by deciding whether your traffic is single-shot enough for semantic matching, then build and test the cache against a written scope before anything reaches production callers.
How we scope
- We confirm which endpoints are single-shot prompts and which carry multi-turn or agent history before any cache is enabled.
- We agree in writing which backend, Qdrant, Redis or Valkey, the embedding model and the similarity threshold will be used.
- Engagements are fixed-scope, with deliverables and timelines agreed in writing before work starts; ongoing support is available as a retainer.
How we build
- We configure the proxy cache settings, embedding route and backend connection in your environment, with secrets kept in your secret manager.
- We test threshold behavior with representative prompt sets, including near-duplicate and non-matching questions, and record the results.
- We check the x-litellm-semantic-similarity header and exclude multi-turn traffic from caching in the routing configuration.
How we hand over
- You receive the configuration as code, a record of the threshold tests and the scope each cached route was approved against.
- We document how to confirm that the cache is hit only on the routes that were approved, and how to disable it quickly.
- Runbooks cover backend sizing checks, cache flushes and what to collect before escalating a stale-response report.
How we support
- Retainers cover upgrades to supported LiteLLM and Qdrant releases, retesting thresholds after model or prompt changes.
- Periodic review of cache hit patterns and stale-response reports can be added to the retainer scope.
- Continuous testing of the gateway can be scoped alongside the cache so changes to routing are checked before rollout.

