{"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/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/_lazy_imports.py#L385-L421","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before\ncache = litellm.llm_client_cache  # AttributeError: LLM client cache lazy import: unknown attribute 'llm_client_cache'\n\n# after\ncache = litellm.in_memory_llm_clients_cache  # singleton instance\ncache_cls = litellm.LLMClientCache                 # the class","handlingStrategy":"type-guard","validationCode":"ALLOWED = {'LLMClientCache', 'in_memory_llm_clients_cache'}\nif name not in ALLOWED:\n    raise AttributeError(f'{name!r} not offered; use one of {sorted(ALLOWED)}')","typeGuard":"import litellm\n\ndef client_cache_attr(name: str):\n    if name not in ('LLMClientCache', 'in_memory_llm_clients_cache'):\n        return None\n    return getattr(litellm, name)","tryCatchPattern":"try:\n    cache = getattr(litellm, 'in_memory_llm_clients_cache')\nexcept AttributeError as e:\n    if 'LLM client cache' in str(e):\n        cache = None  # name not in the two-entry whitelist; check spelling\n    else:\n        raise","preventionTips":["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."],"tags":["litellm","python","attributeerror","lazy-import","caching","http-clients"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}