LiteLLM response caching with Redis, S3 or GCS

LiteLLM's exact-match response cache can cut repeated provider calls, but only a shared backend keeps hit rates up across workers and pods. This page covers the backend choices, cache keys, controls and setup steps.

On this page

How LiteLLM response caching cuts repeat provider calls

The LiteLLM exact-match response cache stores the provider's answer to a request and returns that stored answer when an identical request arrives again, so the gateway skips a paid provider call and responds faster. It is worth enabling when the same requests repeat, such as batch jobs that resend the same prompts, evaluation suites, or internal tools that issue identical lookups across many users. A single gateway process with one in-memory cache can help, but a self-hosted gateway that runs several workers or pods only gets consistent hits when every instance reads and writes the same backend. That is why a shared cache such as Redis or Valkey, or an object store such as an S3 or GCS bucket, matters: without it, each pod keeps its own partial cache and a request that hits pod A can still miss on pod B.

The cache matches only requests that are identical, so a rephrased prompt, a changed system message, or a different temperature or model name produces a miss. The cache key is built from the request content and its parameters, so before enabling caching, confirm with your own traffic which fields vary between calls, including timestamps or request IDs that some clients embed in prompts. Paraphrase-level reuse is a different mechanism covered in the semantic caching topic, which carries its own risks for multi-turn traffic. Ask the team that owns each calling application which of its requests are deterministic enough to cache, because caching a non-deterministic answer changes what users receive.

Treat caching as a change to data handling as well as to cost. Cached responses persist in the backend you choose, so the Redis or bucket location, its encryption, its access policy and its retention must be reviewed like any store that holds prompt-derived content. Confirm with your platform team how the cache TTL is set and who can flush it, and confirm your Redis version against the Redis licenses page, since the license terms for Redis 8 and later differ from earlier lines. Measure hit rate and provider spend before and after enabling the cache so the saving is evidence, not an assumption.

Which cache backend fits which gateway layout

This table compares Redis or Valkey, S3, GCS, in-memory and disk caches by the gateway layout each one suits, from a single-worker test rig to a multi-pod production gateway and long-retention archives. Read each row against your worker and pod count, and confirm the exact backend settings in the LiteLLM cache docs for your release before you choose.

BackendBest fit layoutWhat it needs from youMain limitation
In-memory cacheSingle worker test rig or local developmentNothing beyond the proxy process; memory headroom sized for cached responsesEach worker keeps its own cache, so hit rates fall as worker or pod count grows
Disk cacheSingle host, single worker, longer local reuse during testingLocal disk space and a writable path; cleanup policy you controlNot shared across pods, and a restart or pod replacement can lose or strand entries
Redis or ValkeyMulti-worker or multi-pod production gateway with one shared cacheRedis 7.0 or newer per the production guide; a Redis 8 license choice if you use Redis Open Source; or a Valkey deployment you operateNeeds its own availability plan, memory sizing and eviction settings; Sentinel needs at least three instances for robust failover
S3 bucketLong-retention archive or audit-friendly cache across regions or teamsAn S3 bucket, IAM permissions for the gateway, and a lifecycle rule for expiryHigher lookup latency than Redis, so it suits cost reduction more than latency gains; confirm supported settings for your version
GCS bucketLong-retention archive on Google Cloud infrastructureA GCS bucket, service account permissions, and a lifecycle rule for expirySame latency trade-off as S3; confirm supported settings for your version
Shared cache across podsHorizontally scaled gateway where every pod should reuse the same responsesA shared backend reachable from every pod and worker, plus network policyWithout it, identical requests spread across pods miss the cache and repeat provider calls
Cache-key scope and tenancyMulti-team gateway with different models or settings per teamAgreement on which request fields form the key, such as model and parametersOverly broad keys can return one team's answer to another; confirm key composition in the docs

How the cache key is built and why hit rates fall without a shared store

An exact-match cache answers a request from storage only when the new request produces the same key as an earlier one, so the key definition decides what counts as a hit. In LiteLLM, the key is derived from the request content and the parameters that shape the model output, such as the model name, the messages and sampling settings like temperature. Any field that changes the key makes a request miss: a different model alias, an extra system message, a changed temperature or a different max token value will each produce a new entry even when the user's question is effectively the same. Before you size the cache, confirm the exact key fields for your release in the LiteLLM caching docs, because fields like metadata or user identifiers may or may not be included, and that decision directly affects both hit rate and the risk of serving one team's answer to another.

The second factor is where the cache lives. A per-process cache, such as the in-memory option, belongs to one Python worker or one pod. A gateway with four workers on two pods has up to eight separate caches, so a repeated request only hits if the load balancer happens to send it to the same process that answered before. Hit rate therefore tends to fall as you add replicas, and the gain you measured on a single instance during a test may not appear in production. A shared backend such as Redis or Valkey, or a bucket store such as S3 or GCS, gives every worker and pod the same key space, so a response written by one process is available to all of them. Confirm the backend type and any TTL default for your release in the caching docs before you set a budget expectation.

Plan the test around this effect. Run the same repeated prompt set against one worker, then against your full replica count, and compare hit ratios, not only latency. If hit rate drops sharply as replicas grow, the cache is local and a shared backend is needed before you count savings in provider spend. Treat the shared store as part of the gateway's dependency set: it needs an owner, a failover plan and access controls, because cached responses can contain prompt content and model output that your data handling rules cover.

Setting up a shared response cache for the gateway

This sequence takes a self-hosted LiteLLM gateway from a per-pod cache to a shared cache that every worker and pod reads from and writes to. The result is a configuration you can verify with a repeated request across two pods before any production traffic relies on it.

  1. Choose the cache backend and confirm its licence

    Your platform team decides whether the shared store will be Redis, Valkey, an S3 bucket or a GCS bucket, based on whether you run multiple proxy instances and whether your latency needs call for an in-memory store. If you choose Redis, confirm the exact version and licence before provisioning, because Redis 8.0 and later can be used under RSALv2, SSPLv1 or AGPLv3, while Redis 7.4.x to 7.8.x are under the dual RSALv2 or SSPLv1 license and Redis 7.2.x and earlier are under BSD-3-Clause. Record the chosen version and licence in your change ticket so the security and legal reviewers can sign off on the same version you deploy.

  2. Provision the store in your own infrastructure

    Platform engineers deploy the chosen store inside the cloud account, data center or air-gapped network that already hosts the gateway, so cached prompt and response data never leaves your control. For Redis, confirm the deployment model with your team, including whether you need Sentinel for automatic failover, which the Redis Sentinel documentation says requires at least three Sentinel instances for a robust deployment. Confirm that network paths from every gateway pod to the store are open and that the store is not reachable from outside the gateway's network. The step is complete when a connection test from a gateway pod succeeds.

  3. Store the backend connection in a secret manager

    Security engineers place the connection string, host, port and any credentials for the cache store in your secret manager rather than in the configuration file or container image. The gateway reads these values from environment variables injected at runtime, and the master key is handled the same way. Confirm that the secret is scoped so only the gateway's service identity can read it, and that rotation has an owner. The step is complete when the proxy pod starts with the secret injected and no plaintext credentials appear in the rendered manifests or config files.

  4. Enable caching in the proxy configuration

    Platform engineers add the cache section to the proxy configuration file, pointing the cache type at the backend and referencing the injected environment variables for its connection. Keep this configuration in version control alongside the rest of the gateway settings so changes go through review. Check the current LiteLLM caching documentation for the exact configuration keys in your release line, because key names can change between versions. The step is complete when the configuration is merged, deployed and the proxy reports a healthy start without cache connection errors in its logs.

  5. Set the TTL and namespace

    The team agrees a time to live for cached responses, which controls how long an identical request can be served from cache, and a namespace that separates this gateway's cache entries from other applications using the same store. Confirm with the model owners whether any models or teams should be excluded from caching because answers must stay fresh. Write the chosen TTL and namespace into the configuration and the runbook. The step is complete when the values are set in configuration, reviewed by the owners who accepted them, and visible in the proxy's startup log.

  6. Send an identical request to the first pod

    An engineer sends one fixed test request, using a test virtual key with a low budget, to the gateway endpoint and records the response body and the timing. The first call should be a miss, meaning the provider is called and the response is written to the shared store. Use a request with deterministic parameters so the cache key matches on the second call. The step is complete when the first response is returned normally and the store contains a new entry under the configured namespace.

  7. Confirm a second pod returns the cached response

    The engineer sends the same request again, routed to a different gateway pod. The hit should return quickly and without a new provider call, which you can confirm in the provider's usage dashboard or the gateway's request logs. Repeat the test across each pod and each worker where possible, because a cache that is only shared by some workers will produce inconsistent hit rates. The step is complete when every pod returns the cached response and the provider call count does not increase for the repeated request.

  8. Verify the store is reachable from every worker

    Platform engineers check connectivity from every proxy pod and every worker process, using the same credentials and network path the gateway uses in production. Test a failure case as well, such as a brief store restart in a non-production environment, and confirm how the gateway behaves: whether it falls back to calling the provider or returns errors, and whether that behaviour matches your expectations. The step is complete when the results are recorded in the runbook and the team has agreed which failure behaviour they accept.

Per-request cache controls by caller and use case

Application developers are the callers who know whether a given request is safe and useful to cache. A summarization job that processes a fixed document can benefit from a cache hit, while a chat turn that depends on earlier messages usually should not be served from cache. The gateway exposes request-level settings for this, so the caller can opt a call in, skip the cache for one call, or set a shorter lifetime for a time-sensitive answer.

  • Opt in or bypass per call: Enable caching for deterministic, repeatable requests and bypass it for anything personalized or interactive.
  • Set a TTL per call: Use a shorter lifetime for content that changes often, such as prices or status data.
  • Keep cache keys stable: Send identical parameters for identical requests, since differences in model, temperature or messages create separate entries.
  • Avoid caching secrets: Do not place credentials or personal data in prompts that are cached without the compliance review described in the next tab.
  • Test with two identical calls: Confirm the second call returns from cache before relying on it.

Confirm the exact parameter names and header behavior for your LiteLLM version in the LiteLLM caching documentation before writing application code.

What caching sensitive prompts and responses exposes

A response cache stores the same prompts and completions that passed through the gateway, often in a second system with its own access path. The cards below cover the places where that copy can leak, persist or be reused in the wrong context, and the checks to run before a cache holds real traffic.

Personal data in cached entries

Every cached entry holds the full request body and the model's reply, so a prompt that contained a customer name, account number or health detail is copied into Redis or the bucket. The cache is therefore a data store in its own right and belongs in the same data inventory as the gateway's logs. Ask which fields LiteLLM writes into each cache entry for your configuration and whether your privacy team has classified that store.

Production guide

Access control on the cache store

Anyone who can read the Redis keyspace or list the bucket can read cached conversations, regardless of which virtual key wrote them. Restrict the Redis ACL or network path to the gateway pods, and grant bucket read and list rights only to the gateway's cloud identity. Confirm that operators, backup jobs and monitoring agents do not hold broader rights to the cache.

Encryption at rest and in transit

A cache written to disk or object storage is only as protected as the storage layer beneath it. Confirm that TLS is enforced between the gateway and the Redis or Valkey endpoint, and that the bucket or volume uses encryption at rest with keys your security team can audit. Check whether your managed Redis or cloud provider stores snapshots and replicas under the same controls.

Retention and TTL as a privacy control

A cache entry that never expires keeps a prompt long after the business reason for it has passed. Set an explicit TTL for cached entries, and confirm that bucket lifecycle rules remove objects on the same schedule, since a bucket can keep objects that the application no longer reads. Document the TTL in the same retention schedule that covers logs and spend records, so deletion requests can reach the cache as well.

Cross-tenant reuse through shared keys

If two teams send identical prompts and the cache key does not include the team or key identity, one team can receive an answer generated from another team's data. Decide the scope of the cache before rollout, and check how your chosen cache key combines the model, messages and any namespace setting. Test with two virtual keys sending the same prompt to confirm that a hit does not cross the boundary you intend.

Redis license choice for the cache

Redis 8.0 and later can be used under RSALv2, SSPLv1 or AGPLv3, and the terms that apply depend on the version you run and how you offer it internally or to customers. Whether a modified Redis offered as a network service triggers source obligations is a legal question. Confirm the license choice and the deployment model with counsel before you select the Redis version for the cache.

Redis licenses

How a cached request flows through the gateway

A client request enters the LiteLLM proxy inside the client's trust boundary, and the gateway checks the shared cache backend before it calls any provider. A hit returns the stored response directly, so no provider call or provider spend occurs. A miss goes to the model provider, and the gateway writes the response back to the cache for later identical requests. Check that every worker points at the same cache backend, because each worker with its own cache produces misses that look like a caching failure.

Cache hits return from the shared backend, while misses call the provider and populate the cache.

Limits to confirm before relying on the cache

A response cache only pays off when the release, backend and traffic pattern line up. The cards below list what to confirm in your own environment before you count on savings, covering the LiteLLM release, the Redis baseline, streaming, cache size and the hit rate you can realistically expect from varied prompts.

Backend support in your release

Confirm that the LiteLLM release you plan to run supports each cache backend you intend to use, including Redis, S3, GCS and in-memory or disk caches. Support can differ between releases, so test the exact backend and configuration keys against the version you deploy rather than assuming parity with the documentation of a newer line. Record the result in your change request.

Minor versions supported
4
Production guide

Redis 7.0 minimum and license choice

Once more than one proxy instance runs, LiteLLM requires Redis 7.0 or newer for shared state, including the cache. Confirm which Redis line your platform team will run, because the license terms differ by version: Redis 8.0 and later offer a choice of licenses, while 7.4 to 7.8 use dual RSALv2 or SSPLv1. Ask your legal team to review that choice before deployment.

Redis licenses

Streaming response caching behavior

Confirm how the release you run handles cache writes and replays for streamed responses. Test a streaming request twice, check whether the second response is served from cache, and verify that the replayed chunks match what a caller expects. Streaming traffic is common in chat clients, so an unverified streaming path can give you false confidence in hit rates.

Cache size and eviction under load

Decide how much memory or disk the cache may use and what happens when it fills. Redis and object stores apply different eviction and expiry behavior, and an in-memory cache is lost on restart. Run a load test with realistic prompt sizes and confirm that entries expire as configured, that eviction does not starve other Redis workloads, and that memory alerts fire before the limit.

Hit rate for varied prompts

Exact-match caching only returns an answer when the cache key matches the request exactly, including messages, model and parameters. Prompts that differ in wording, timestamps, user names or conversation history will miss, so savings can be small for interactive or agent traffic. Measure hit rate on a sample of your own logs before you put a cost figure into a business case.

Cache keys and per-request controls

Confirm which request fields feed the cache key and which per-request controls callers may use to bypass or refresh entries. Check that keys include the model and the parameters that change output, and that one team's cached answer cannot reach another team's callers when shared data is sensitive. Document the allowed controls in the gateway runbook.

Questions buyers ask about LiteLLM caching

What drives the cost of setting up LiteLLM response caching?

The cost depends on the cache backend you choose, the number of gateway workers and pods that must share it, the high availability design, and how much testing you need before go-live. Setup is usually a one-time cost for design, configuration, load testing and handover. The cache itself is a recurring cost: a Redis or Valkey service, or bucket storage and requests on S3 or GCS, billed by your cloud or hosting provider. Costs go up when you need multi-region access, separate environments or a managed service with high availability. Ask for a quote that lists each backend, each environment, the high availability topology, the test cycles, and which upgrades and ongoing support are included or priced separately.

How long does a LiteLLM caching project take to deliver?

The duration depends on the confirmed scope, so no fixed figure applies to every setup. The main variables are whether Redis or Valkey is already running, whether you need a shared cache for several gateway workers or pods, whether you want a bucket-backed cache, how many teams need per-request cache controls, and how many load test rounds your change process requires. Environment access and approvals often take longer than the configuration itself. Ask for a written timeline tied to milestones such as design sign-off, staging validation, load test results and production cutover, and confirm which of your dependencies sit on the critical path.

What must our team provide before a caching engagement starts?

Your team provides the access and decisions that the work depends on. The typical list includes:

  • Cloud accounts, network paths and change windows for each environment.
  • A Redis or Valkey endpoint with credentials, or bucket names and IAM or service account roles for S3 or GCS.
  • A PostgreSQL database if you also use virtual keys, since those need it.
  • Representative test traffic, including prompt sizes, streaming mix and the models in use, so hit rates and latency are measured on realistic requests.
  • Named owners for security review, secrets handling and sign-off on the cache key design.

Missing items usually delay the schedule more than the technical work does, so confirm them in the written scope before the project starts.

Can our own platform team run a LiteLLM response cache?

Yes, if your team already operates Redis or Valkey and can take on the cache as a service. LiteLLM's production guide requires Redis 7.0 or newer once more than one proxy instance runs, so shared rate limits, router state and cache depend on it. For high availability without Redis Cluster, Redis Sentinel needs at least three Sentinel instances and promotes a replica automatically on failure. Your team then owns memory monitoring, eviction behavior, backups where needed, upgrades and the Redis license choice. Redis 8 and later can be used under a license of your choice, so have legal review the options, including AGPLv3, before you standardize on a version.

How do we measure cost savings from LiteLLM cache hit rate?

Start with the number of requests served from cache, multiplied by the provider cost you would otherwise have paid for those requests, and compare that figure with the provider invoices. Tag spend by key, team and model in LiteLLM so the numbers can be reconciled with provider bills. Measure over the same traffic before and after enabling the cache, because changes in user behavior distort simple comparisons. Count only identical requests, since the cache is exact-match. Also track latency on hits and misses separately, and review the cache retention period against how often your prompts repeat. Agree on this measurement method in the scope, so savings are reported on a basis your finance team accepts.

Why does our LiteLLM cache hit rate drop with several workers?

An in-memory cache belongs to a single worker or pod. When requests are spread across several workers, each one keeps its own entries, so a repeated request that lands on a different worker misses and calls the provider again. Restarts and scale-out events also clear local memory. A shared backend such as Redis, Valkey, S3 or GCS lets every worker read the same entries. Hit rates can also be low for reasons unrelated to the backend. Check that the cache key includes only the parameters that should make a request unique, and look for values such as timestamps, random seeds or per-user identifiers that stop identical requests from matching. Confirm the design with your engineers before choosing the backend.

When is a semantic cache a better choice than exact-match caching?

A semantic cache suits traffic where users ask different wording for the same question, such as help desk or knowledge lookups, and where an occasionally reused answer is acceptable. It depends on an embedding model and a similarity threshold, and it can use Qdrant, Redis or Valkey as the backend. The risk is staleness: on multi-turn agent traffic, similar prompts can have different correct answers, so a semantic match may replay the wrong response. Exact-match caching is the safer default for agents, tool-calling loops and workflows where context changes between turns. Compare both options on your own traffic, and see the sibling topic on LiteLLM semantic caching before deciding.

How DeployOpen scopes and delivers LiteLLM caching

DeployOpen plans and builds the LiteLLM response cache as part of a self-hosted gateway inside your own infrastructure. We start from which backend your gateway topology needs, then build, test, document and hand over the cache configuration so your platform team can run it.

How we scope

  • Map how many gateway workers and pods run, and whether a shared Redis or Valkey cache is required
  • Decide between Redis, S3, GCS, in-memory or disk caching, based on your topology and data location
  • Agree in writing which cache controls, cache key rules and TTL policies each team may use

How we build

  • Configure the cache backend, connection settings and secrets in your infrastructure, not ours
  • Test exact-match hit and miss behavior with per-request cache controls across multiple workers
  • Measure provider cost and latency impact with a load test that uses a fake provider endpoint

How we hand over

  • Document the cache configuration as code, with the backend, keys, TTLs and failure behavior
  • Walk your platform and security teams through what the cache stores and who can read it
  • Provide a runbook covering cache flushes, backend failover and checks for falling hit rates

How we support

  • Engagements are fixed-scope, with scope, deliverables and timelines agreed in writing before work starts
  • Ongoing upgrades, cache reviews and continuous testing are available as a retainer
  • A quote follows directly from the written scope, so ask us to itemize build, testing and handover work

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.