{"record":{"id":"8c38427724c1c801","repo":"BerriAI/litellm","slug":"llm-client-cache-lazy-import-unknown-attribute-n","errorCode":null,"errorMessage":"LLM client cache lazy import: unknown attribute {name!r}","messagePattern":"LLM client cache lazy import: unknown attribute (.+?)","errorType":"exception","errorClass":"AttributeError","httpStatus":null,"severity":"error","filePath":"litellm/_lazy_imports.py","lineNumber":403,"sourceCode":"    if name in _globals:\n        return _globals[name]\n\n    # Import the class\n    module: Final = importlib.import_module(\"litellm.caching.llm_caching_handler\")\n    LLMClientCache: Final = getattr(module, \"LLMClientCache\")\n\n    # If they want the class itself, return it\n    if name == \"LLMClientCache\":\n        _globals[\"LLMClientCache\"] = LLMClientCache\n        return LLMClientCache\n\n    # If they want the singleton instance, create it (only once)\n    if name == \"in_memory_llm_clients_cache\":\n        instance: Final = LLMClientCache()\n        _globals[\"in_memory_llm_clients_cache\"] = instance\n        return instance\n\n    raise AttributeError(f\"LLM client cache lazy import: unknown attribute {name!r}\")\n\n\ndef _lazy_import_http_handlers(name: str) -> Any:\n    \"\"\"\n    Handler for HTTP clients - has special logic for creating client instances.\n\n    This one is different because:\n    - These aren't just imports, they're actual client instances that need to be created\n    - They need configuration (timeout, etc.) from the module globals\n    - They use factory functions instead of direct instantiation\n    \"\"\"\n    _globals: Final = get_litellm_globals()\n\n    if name == \"module_level_aclient\":\n        # Create an async HTTP client using the factory function\n        from litellm.llms.custom_httpx.http_handler import get_async_httpx_client\n\n        # Get timeout from module config (if set)","sourceCodeStart":385,"sourceCodeEnd":421,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/_lazy_imports.py#L385-L421","documentation":"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 ...').","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before\nimport litellm\nlitellm.in_memory_llm_client_cache  # typo -> LLM client cache lazy import: unknown attribute\n\n# after\nimport litellm\nlitellm.in_memory_llm_clients_cache  # exact singleton name\n# or\nfrom litellm.caching.llm_caching_handler import LLMClientCache","handlingStrategy":"type-guard","validationCode":"import litellm\n\nVALID = {\"LLMClientCache\", \"in_memory_llm_clients_cache\"}\nname = \"in_memory_llm_clients_cache\"\nassert name in VALID, f\"{name!r} invalid; valid cache attrs: {sorted(VALID)}\"","typeGuard":"import litellm\nfrom typing import Optional, Any\n\ndef get_llm_client_cache() -> Optional[Any]:\n    \"\"\"Safely resolve the lazily created singleton, if available.\"\"\"\n    return getattr(litellm, \"in_memory_llm_clients_cache\", None)  # hasattr-safe via default","tryCatchPattern":"try:\n    cache = litellm.in_memory_llm_clients_cache\nexcept AttributeError:\n    cache = None  # attribute name changed; skip cache introspection","preventionTips":["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"],"tags":["attributeerror","lazy-import","cache","client-cache","python"],"backgroundTag":"module-has-no-attribute","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}