litellm/litellm/caching
kenneth-berri 1b207c9b37
fix(embeddings): send request-shaped extra_body fields at the provider's documented path (#54273)
* fix(embeddings): send extra_body fields at the documented path for Marengo 3, SageMaker Cohere, Vertex and Gemini

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* refactor(bedrock): strip Marengo 3 placed fields from modelInput without recursion

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(embeddings): keep extra_body items aligned on partial cache hits, merge nested item settings, keep Cohere image type

* fix(caching): send the cut-down extra_body items with the uncached embedding inputs

* fix(caching): key the embedding cache write on the caller's extra_body after a partial hit

* fix(caching): key each cached embedding on the extra_body item written for its input

* fix(embeddings): let a per-input extra_body item win over a shared field and keep per-input caching to Vertex and Gemini

* fix(gemini): keep a shared extra_body config beside the config of one request

* fix(gemini): resolve each request's extra_body settings before the named params and the video check read them

* refactor(gemini): build each embed request in a typed helper and annotate the new cache tests

* test(caching): script Gemini with respx instead of replacing get_async_httpx_client

* test(caching): annotate the locals and embedder parameters of the per-input cache tests

* test(vertex): cover the fine-tuned endpoint in the request-shaped extra_body regression

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-11-25 13:29:52 -08:00
..
__init__.py chore(caching)!: remove the disk cache backend (#48114) 2026-10-29 18:02:31 -07:00
_embedding_router.py refactor(router): move router callers onto the entry points and invert the proxy imports (#48847) 2026-10-29 17:26:33 +00:00
_internal_lru_cache.py refactor(types): replace Unknown with proven types in 390 files (#53715) 2026-11-24 03:33:11 +00:00
affinity_cache.py feat(redis): serve the router's session pins from a native store (#50870) 2026-11-13 03:22:28 +00:00
azure_blob_cache.py feat(cache): apply scoped settings to exact-match response caching (#54041) 2026-11-24 11:37:16 -08:00
base_cache.py refactor(types): give bare dict, list and set returns, locals and constants proven types in 77 files (#54343) 2026-11-25 03:47:36 +00:00
caching.py fix(embeddings): send request-shaped extra_body fields at the provider's documented path (#54273) 2026-11-25 13:29:52 -08:00
caching_handler.py fix(embeddings): send request-shaped extra_body fields at the provider's documented path (#54273) 2026-11-25 13:29:52 -08:00
dual_cache.py refactor(types): annotate repeated bare-container parameters across method families (#54268) 2026-11-24 14:13:19 -08:00
evicted_client_closer.py fix(caching): key cached async clients by a per-loop token instead of id(loop) (#48877) 2026-10-29 13:14:48 -07:00
gcs_cache.py refactor(types): replace Unknown with proven types in 225 files (#53687) 2026-11-24 00:11:50 +00:00
in_memory_cache.py fix(cache): honor request TTL when refreshing in-memory responses (#54270) 2026-11-24 14:14:49 -08:00
llm_caching_handler.py refactor(types): replace Unknown with proven types in 390 files (#53715) 2026-11-24 03:33:11 +00:00
qdrant_semantic_cache.py refactor(types): replace Unknown with proven types in 86 files (#53803) 2026-11-24 12:45:20 +00:00
Readme.md fix(caching): allow excluding embeddings from response caching (#52902) 2026-11-19 11:48:35 -08:00
redis_batch.py fix(router): make the constructor stub work for mypy and guard it in CI (#50354) 2026-11-22 21:25:00 +00:00
redis_cache.py fix(caching): release Redis caller frames without cyclic GC (#54105) 2026-11-25 16:21:17 +00:00
redis_cluster_cache.py refactor(types): replace Unknown with proven types in 390 files (#53715) 2026-11-24 03:33:11 +00:00
redis_cluster_node_isolation.py fix(caching): keep a node timeout from forcing a cluster-wide topology reinit on redis-py 8.x (#39349) 2026-09-03 17:31:58 -07:00
redis_semantic_cache.py fix(caching): upgrade redisvl to 0.26.0 so the redis-semantic cache works with restricted Redis users (#54410) 2026-11-25 17:27:11 +00:00
s3_cache.py refactor(types): replace Unknown with proven types in 162 more files (#54089) 2026-11-23 22:58:19 -08:00
valkey_semantic_cache.py refactor(types): annotate repeated bare-container parameters across method families (#54268) 2026-11-24 14:13:19 -08:00

Caching on LiteLLM

LiteLLM supports multiple caching mechanisms. This allows users to choose the most suitable caching solution for their use case.

The following caching mechanisms are supported:

  1. RedisCache
  2. RedisSemanticCache
  3. QdrantSemanticCache
  4. InMemoryCache
  5. S3Cache
  6. AzureBlobCache
  7. DualCache (updates both Redis and an in-memory cache simultaneously)

Folder Structure

litellm/caching/
├── base_cache.py
├── caching.py
├── caching_handler.py
├── dual_cache.py
├── in_memory_cache.py
├── qdrant_semantic_cache.py
├── redis_cache.py
├── redis_semantic_cache.py
├── s3_cache.py

Embeddings and shared Redis memory

The response cache stores embeddings per input item. A batched embeddings request with N inputs writes N keys, each holding a full vector. A batch job over unique texts gets almost no cache hits, yet it can fill a Redis instance. Once Redis reaches maxmemory, a volatile-lru policy evicts any key with a TTL, and that includes the proxy's rate limit counters, spend and budget state, and auth cache entries when they share the instance. A shorter cache TTL does not prevent this, since the cache can still fill memory before keys expire.

To stop caching embeddings while keeping every other default call type, exclude them:

litellm_settings:
  cache: true
  cache_params:
    type: redis
    excluded_call_types: ["embedding", "aembedding"]

excluded_call_types removes names from supported_call_types, so list both the sync and async name. Listing every call type you do want in supported_call_types without the embedding names has the same effect.

To keep caching embeddings, give the response cache its own Redis instance. A different namespace or database number on the same instance does not help, because maxmemory and eviction apply to the whole instance. Point general_settings.coordination_redis, which holds rate limits, spend tracking and locks, and router_settings (redis_host, redis_port) at a different instance from cache_params:

litellm_settings:
  cache: true
  cache_params:
    type: redis
    host: cache-redis
    port: 6379

general_settings:
  coordination_redis:
    host: coordination-redis
    port: 6379

router_settings:
  redis_host: coordination-redis
  redis_port: 6379

Documentation