{"record":{"id":"589cf3d37f627b7a","repo":"BerriAI/litellm","slug":"http-handlers-lazy-import-unknown-attribute-name","errorCode":null,"errorMessage":"HTTP handlers lazy import: unknown attribute {name!r}","messagePattern":"HTTP handlers lazy import: unknown attribute (.+?)","errorType":"exception","errorClass":"AttributeError","httpStatus":null,"severity":"error","filePath":"litellm/_lazy_imports.py","lineNumber":447,"sourceCode":"            params=params,\n        )\n\n        # Cache it so we don't create it again\n        _globals[\"module_level_aclient\"] = async_client\n        return async_client\n\n    if name == \"module_level_client\":\n        # Create a sync HTTP client\n        from litellm.llms.custom_httpx.http_handler import HTTPHandler\n\n        timeout = _globals.get(\"request_timeout\")\n        sync_client: Final = HTTPHandler(timeout=timeout)\n\n        # Cache it\n        _globals[\"module_level_client\"] = sync_client\n        return sync_client\n\n    raise AttributeError(f\"HTTP handlers lazy import: unknown attribute {name!r}\")\n","sourceCodeStart":429,"sourceCodeEnd":448,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/_lazy_imports.py#L429-L448","documentation":"The HTTP-handlers lazy-import handler is a small factory: for 'module_level_client' it builds a sync HTTPHandler with the module's request_timeout and caches it (and, per the sibling code, an async variant similarly). Any other name routed here raises AttributeError 'HTTP handlers lazy import: unknown attribute <name>'. Only the pre-declared module-level HTTP client entries are supported.","triggerScenarios":"Accessing litellm.module_level_client with a typo, or asking for names like 'http_handler', 'aclient', or 'module_level_aclient'-style guesses that the handler does not recognize; automated attribute-walking (pickle/copy of the module, mock.patch autospec) can also trip it.","commonSituations":"Test suites that mock litellm's shared HTTP clients and reference them by guessed names; code wanting to set timeouts by replacing the module-level client; refactors across litellm versions renaming these internals.","solutions":["Use the exact supported names — check the handler body in litellm/_lazy_imports.py for the current whitelist (e.g. module_level_client and its async counterpart).","Prefer configuring timeouts via documented API (e.g. request_timeout / per-call timeout) over touching module-level clients.","In tests, patch the concrete client class (litellm.llms.custom_httpx.http_handler.HTTPHandler) rather than guessing top-level names.","After a litellm upgrade, re-verify internal names you depend on — these handlers are internal surface and can change."],"exampleFix":"# before\nclient = litellm.http_module_client  # AttributeError: HTTP handlers lazy import: unknown attribute ...\n\n# after\nclient = litellm.module_level_client  # cached sync HTTPHandler built with module request_timeout","handlingStrategy":"type-guard","validationCode":"ALLOWED = {'module_level_client', 'module_level_aclient'}  # verify against installed _lazy_imports.py\nif name not in ALLOWED:\n    raise AttributeError(f'{name!r} not built by the HTTP handlers factory')","typeGuard":"import litellm\n\ndef http_client_attr(name: str):\n    try:\n        return getattr(litellm, name)\n    except AttributeError as e:\n        if 'HTTP handlers lazy import' in str(e):\n            return None\n        raise","tryCatchPattern":"try:\n    client = getattr(litellm, 'module_level_client')\nexcept AttributeError as e:\n    if 'HTTP handlers lazy import' in str(e):\n        client = None  # unsupported name; check whitelist in _lazy_imports.py\n    else:\n        raise","preventionTips":["Set timeouts through documented request_timeout / per-call params, not by swapping module-level clients.","In tests, patch litellm.llms.custom_httpx.http_handler.HTTPHandler directly instead of guessing top-level names.","Re-verify internal client names after every litellm upgrade; these handlers are private surface."],"tags":["litellm","python","attributeerror","lazy-import","httpx","internals"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}