BerriAI/litellm · error · AttributeError
LLM client cache lazy import: unknown attribute {name!r}
Error message
LLM client cache lazy import: unknown attribute {name!r} What it means
The LLM client cache lazy-import handler accepts exactly two names: 'LLMClientCache' (the class) and 'in_memory_llm_clients_cache' (a singleton instance, created once and cached). Any other attribute routed to this handler raises AttributeError 'LLM client cache lazy import: unknown attribute <name>'. It is a closed whitelist, not a general import path.
Source
Thrown at litellm/_lazy_imports.py:403
if name in _globals:
return _globals[name]
# Import the class
module: Final = importlib.import_module("litellm.caching.llm_caching_handler")
LLMClientCache: Final = getattr(module, "LLMClientCache")
# If they want the class itself, return it
if name == "LLMClientCache":
_globals["LLMClientCache"] = LLMClientCache
return LLMClientCache
# If they want the singleton instance, create it (only once)
if name == "in_memory_llm_clients_cache":
instance: Final = LLMClientCache()
_globals["in_memory_llm_clients_cache"] = instance
return instance
raise AttributeError(f"LLM client cache lazy import: unknown attribute {name!r}")
def _lazy_import_http_handlers(name: str) -> Any:
"""
Handler for HTTP clients - has special logic for creating client instances.
This one is different because:
- These aren't just imports, they're actual client instances that need to be created
- They need configuration (timeout, etc.) from the module globals
- They use factory functions instead of direct instantiation
"""
_globals: Final = get_litellm_globals()
if name == "module_level_aclient":
# Create an async HTTP client using the factory function
from litellm.llms.custom_httpx.http_handler import get_async_httpx_client
# Get timeout from module config (if set)View on GitHub (pinned to 6c2dcb801b)
Solutions
- Use the exact names: litellm.LLMClientCache for the class or litellm.in_memory_llm_clients_cache for the singleton instance.
- Inspect the singleton's public API (dir(litellm.in_memory_llm_clients_cache)) instead of guessing sibling attributes.
- If you need client invalidation, look for the documented reset/clear helpers on the cache object or router rather than unmapped names.
- Search litellm/_lazy_imports.py for other whitelists if the symbol you want lives in a different category.
Example fix
# before cache = litellm.llm_client_cache # AttributeError: LLM client cache lazy import: unknown attribute 'llm_client_cache' # after cache = litellm.in_memory_llm_clients_cache # singleton instance cache_cls = litellm.LLMClientCache # the class
Defensive patterns
Strategy: type-guard
Validate before calling
ALLOWED = {'LLMClientCache', 'in_memory_llm_clients_cache'}
if name not in ALLOWED:
raise AttributeError(f'{name!r} not offered; use one of {sorted(ALLOWED)}') Type guard
import litellm
def client_cache_attr(name: str):
if name not in ('LLMClientCache', 'in_memory_llm_clients_cache'):
return None
return getattr(litellm, name) Try / catch
try:
cache = getattr(litellm, 'in_memory_llm_clients_cache')
except AttributeError as e:
if 'LLM client cache' in str(e):
cache = None # name not in the two-entry whitelist; check spelling
else:
raise Prevention
- Remember this whitelist has exactly two names — spell them exactly.
- Use dir(litellm.LLMClientCache) to discover cache operations instead of guessing attributes.
- Pin versions if you depend on internal cache internals; they can change without notice.
When it happens
Trigger: Trying to access litellm.in_memory_llm_clients_cache / litellm.LLMClientCache with a typo, or probing sibling names (e.g. 'llm_client_cache', 'client_cache') that are not in the two-name whitelist; introspection code enumerating attributes can also land here.
Common situations: Custom caching/teardown code that wants to flush per-model client caches; guessing attribute names instead of checking docs/source; hasattr sweeps over the module during debugging.
Related errors
- module {__name__!r} has no attribute {name!r}
- {category} lazy import: unknown attribute {name!r}
- Utils module lazy import: unknown attribute {name!r}
- HTTP handlers lazy import: unknown attribute {name!r}
- input must be a string or a list
AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15).
Data as JSON: /api/errors/8c38427724c1c801.
Report an issue: GitHub.