BerriAI/litellm · error · ModuleNotFoundError
Please install litellm with `litellm[caching]` to use disk…
Error message
Please install litellm with `litellm[caching]` to use disk caching.
What it means
DiskCache.__init__ fails to import the optional `diskcache` dependency; the sentinel error tells the user the `litellm[caching]` extra was not installed, with the original ModuleNotFoundError chained as the cause.
Solutions
- Install the caching extra: pip install 'litellm[caching]'.
- Alternatively use an in-memory or Redis cache instead of disk caching.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at litellm/caching/disk_cache.py:19 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/16ae0039ac7cffd5.
Report an issue: GitHub.
Appendix: source
Thrown at litellm/caching/disk_cache.py:19
import json
from typing import TYPE_CHECKING, Any, Final
from .base_cache import BaseCache
if TYPE_CHECKING:
from opentelemetry.trace import Span as _Span
Span = _Span | Any
else:
Span = Any
class DiskCache(BaseCache):
def __init__(self, disk_cache_dir: str | None = None):
try:
import diskcache as dc
except ModuleNotFoundError as e:
raise ModuleNotFoundError("Please install litellm with `litellm[caching]` to use disk caching.") from e
# if users don't provider one, use the default litellm cache
if disk_cache_dir is None:
self.disk_cache = dc.Cache(".litellm_cache")
else:
self.disk_cache = dc.Cache(disk_cache_dir)
def set_cache(self, key, value, **kwargs):
if "ttl" in kwargs:
self.disk_cache.set(key, value, expire=kwargs["ttl"])
else:
self.disk_cache.set(key, value)
async def async_set_cache(self, key, value, **kwargs):
self.set_cache(key=key, value=value, **kwargs)
async def async_set_cache_pipeline(self, cache_list, **kwargs):
for cache_key, cache_value in cache_list:View on GitHub (pinned to 77b7c6c40c)