{"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/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/_lazy_imports.py#L429-L448","documentation":"The HTTP-handler lazy loader in litellm/_lazy_imports.py recognizes only 'module_level_aclient' (async httpx client via get_async_httpx_client) and 'module_level_client' (sync HTTPHandler, both honoring request_timeout). Any other name routed to this handler raises AttributeError('HTTP handlers lazy import: unknown attribute ...'), typically from a typo when reaching for litellm's shared HTTP clients.","triggerScenarios":"litellm.module_level_clients, litellm.aclient, or other guesses at the shared-client attributes; monkeypatching litellm's HTTP clients in tests with the wrong name; hasattr probes for client instrumentation.","commonSituations":"Test suites patching litellm's transport for mocking; debugging request timeouts by inspecting the module-level client; names changed across versions.","solutions":["Use exactly litellm.module_level_client (sync) or litellm.module_level_aclient (async)","For test patching, target the concrete handler: litellm.llms.custom_httpx.http_handler.HTTPHandler / get_async_httpx_client","Set timeouts via litellm.request_timeout rather than reconstructing clients","Guard optional access with hasattr"],"exampleFix":"# before\nimport litellm\nlitellm.module_level_aclients  # typo -> HTTP handlers lazy import: unknown attribute\n\n# after\nimport litellm\nlitellm.module_level_aclient   # async httpx client\nlitellm.module_level_client    # sync HTTPHandler","handlingStrategy":"type-guard","validationCode":"import litellm\n\nVALID = {\"module_level_client\", \"module_level_aclient\"}\nname = \"module_level_aclient\"\nassert name in VALID, f\"{name!r} invalid; valid handler attrs: {sorted(VALID)}\"","typeGuard":"import litellm\nfrom typing import Optional\n\ndef get_module_client(async_: bool = False) -> Optional[object]:\n    \"\"\"Safely fetch litellm's shared HTTP client, or None if unavailable.\"\"\"\n    return getattr(litellm, \"module_level_aclient\" if async_ else \"module_level_client\", None)","tryCatchPattern":"try:\n    client = litellm.module_level_aclient\nexcept AttributeError:\n    from litellm.llms.custom_httpx.http_handler import get_async_httpx_client\n    client = get_async_httpx_client(llm_provider=\"my_app\")  # construct directly","preventionTips":["Only two names exist: module_level_client (sync) and module_level_aclient (async)","In tests, patch litellm.llms.custom_httpx.http_handler rather than guessed module attributes","Set timeouts via litellm.request_timeout instead of rebuilding shared clients"],"tags":["attributeerror","lazy-import","httpx","http-client","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"}