BerriAI/litellm · error · AttributeError
LLM client cache lazy import: unknown attribute
Error message
LLM client cache lazy import: unknown attribute {name!r} What it means
The LLM-client-cache lazy handler in litellm/_lazy_imports.py accepts exactly two names: 'LLMClientCache' (the class from litellm.caching.llm_caching_handler) and 'in_memory_llm_clients_cache' (its lazily created singleton). Any other attribute reaching this handler raises AttributeError('LLM client cache lazy import: unknown attribute ...').
Solutions
- Use the exact names: litellm.LLMClientCache or litellm.in_memory_llm_clients_cache
- Import the class directly: from litellm.caching.llm_caching_handler import LLMClientCache
- Check litellm's caching module for the current cache-management API
- Write a hasattr guard before optional cache access
Example fix
# before import litellm litellm.in_memory_llm_client_cache # typo -> LLM client cache lazy import: unknown attribute # after import litellm litellm.in_memory_llm_clients_cache # exact singleton name # or from litellm.caching.llm_caching_handler import LLMClientCache
Defensive patterns
Strategy: type-guard
Validate before calling
import litellm
VALID = {"LLMClientCache", "in_memory_llm_clients_cache"}
name = "in_memory_llm_clients_cache"
assert name in VALID, f"{name!r} invalid; valid cache attrs: {sorted(VALID)}" Type guard
import litellm
from typing import Optional, Any
def get_llm_client_cache() -> Optional[Any]:
"""Safely resolve the lazily created singleton, if available."""
return getattr(litellm, "in_memory_llm_clients_cache", None) # hasattr-safe via default Try / catch
try:
cache = litellm.in_memory_llm_clients_cache
except AttributeError:
cache = None # attribute name changed; skip cache introspection Prevention
- Use exact names LLMClientCache / in_memory_llm_clients_cache; there is no plural or abbreviated form
- Use getattr(litellm, name, None) for optional cache access in diagnostics/tests
- Pin litellm version in test environments so lazy-attr names can't drift silently
When it happens
Trigger: Accessing litellm.in_memory_llm_client_cache (missing 's'), litellm.llm_client_cache, or any other cache-related guess that routes here; hasattr-based capability probing on the litellm module.
Common situations: Trying to inspect/clear the in-memory LLM client cache (e.g. for client-leak debugging) with a misspelled name; copy-paste from outdated issues/PRs where the attribute was named differently.
Related errors
- lazy import: unknown attribute
- HTTP handlers lazy import: unknown attribute
- module has no attribute
- Utils module lazy import: unknown attribute
- 500
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/8c38427724c1c801.
Report an issue: GitHub.
Appendix: 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 77b7c6c40c)