* refactor(typing): clear basedpyright Any errors in proxy, router and core utils * refactor(typing): clear basedpyright Any errors in proxy server, logging and provider handlers * refactor(typing): clear basedpyright Any errors in types, proxy client and single-Any modules * refactor(typing): clear basedpyright Any errors in providers, responses and proxy endpoints * refactor(typing): clear basedpyright Any errors in key management, prometheus, gigachat and http handler * refactor(typing): clear basedpyright Any errors in a long-tail family sweep * refactor(typing): clear basedpyright Any errors in decode, guardrail and passthrough paths * refactor(typing): clear basedpyright Any errors in decode, realtime and management paths * refactor(typing): clear basedpyright Any errors in source-owned proxy, cache and provider paths * refactor(typing): clear basedpyright Any errors in wave 10 narrow deep pass * refactor(typing): clear basedpyright Any errors in wave 11 hotspot and route request pass * refactor(typing): clear basedpyright Any errors in wave 12 deep coupled pass * refactor(typing): clear basedpyright Any errors in wave 13 family pass * refactor(typing): clear basedpyright Any errors in wave 14 single-hotspot pass * refactor(typing): clear basedpyright Any errors in wave 15 single-hotspot pass * fix(typing): keep main's merged behavior typed after syncing with main * refactor(typing): share one int_of helper across batch, file and key endpoints * test: give mocked Anthropic calls a real message body The Anthropic chat transform now rejects a decoded body that is not a JSON object. Four tests mocked the HTTP client with a bare MagicMock, whose json() is never a real decoded response, so they now return a real Anthropic message. * fix(utils): keep FileTypes importable from litellm.utils The wave 14 pass dropped the now-unused FileTypes import, which also removed the litellm.utils.FileTypes attribute SDK users could import. Re-export it as a TypeAlias the same way TextChoices is. * fix: run real builtins instead of copied CPython errors and keep client SDK types Replace hand-copied CPython error sites with the real operations through small core_helpers wrappers, restore main's typed client SDK returns, and add tests that compare each helper's result and error with the builtin's * fix: raise instead of recursing in the typed narrowing helpers Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * test: call the value directly so the helpers test collects on Python 3.10 Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * refactor(typing): mark the three widened TypedDict fields read-only Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> |
||
|---|---|---|
| .. | ||
| __init__.py | ||
| _embedding_router.py | ||
| _internal_lru_cache.py | ||
| affinity_cache.py | ||
| azure_blob_cache.py | ||
| base_cache.py | ||
| caching.py | ||
| caching_handler.py | ||
| dual_cache.py | ||
| evicted_client_closer.py | ||
| gcs_cache.py | ||
| in_memory_cache.py | ||
| llm_caching_handler.py | ||
| qdrant_semantic_cache.py | ||
| Readme.md | ||
| redis_batch.py | ||
| redis_cache.py | ||
| redis_cluster_cache.py | ||
| redis_cluster_node_isolation.py | ||
| redis_semantic_cache.py | ||
| s3_cache.py | ||
| valkey_semantic_cache.py | ||
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:
- RedisCache
- RedisSemanticCache
- QdrantSemanticCache
- InMemoryCache
- S3Cache
- AzureBlobCache
- 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