{"record":{"id":"b40742b4ae1faa9f","repo":"BerriAI/litellm","slug":"module-name-r-has-no-attribute-name-r","errorCode":null,"errorMessage":"module {__name__!r} has no attribute {name!r}","messagePattern":"module (.+?) has no attribute (.+?)","errorType":"exception","errorClass":"AttributeError","httpStatus":null,"severity":"error","filePath":"litellm/__init__.py","lineNumber":2344,"sourceCode":"            get_eval,\n            update_eval,\n            delete_eval,\n            cancel_eval,\n            acreate_run,\n            alist_runs,\n            aget_run,\n            acancel_run,\n            adelete_run,\n            create_run,\n            list_runs,\n            get_run,\n            cancel_run,\n            delete_run,\n        )\n\n        return locals()[name]\n\n    raise AttributeError(f\"module {__name__!r} has no attribute {name!r}\")\n\n\n# ALL_LITELLM_RESPONSE_TYPES is lazy-loaded via __getattr__ to avoid loading utils at import time\n","sourceCodeStart":2326,"sourceCodeEnd":2348,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/__init__.py#L2326-L2348","documentation":"litellm/__init__.py uses a PEP 562 module-level __getattr__ for lazy loading; only whitelisted names resolve (e.g. the evals/runs functions create_run, get_run, list_runs, cancel_run, delete_run and their a-variants). Any other attribute access falls through to raise AttributeError(\"module 'litellm' has no attribute ...\"). This is the standard Python missing-attribute error, just surfaced through litellm's lazy-import machinery.","triggerScenarios":"`litellm.somename` where somename is a typo, was renamed/removed in an upgrade, or was never exported (e.g. litellm.MAX_TOKEN for max_tokens); getattr(litellm, name) with dynamically built names; hasattr checks naturally returning False then code assuming presence.","commonSituations":"Upgrading litellm major versions where symbols moved into lazy maps or were deleted; copying tutorial code targeting a different litellm version; IDE autocomplete suggesting private names; accessing a name that now lives on a submodule (litellm.constants, litellm.utils).","solutions":["Check the exact spelling against litellm's __all__ / docs: python -c \"import litellm; print('name' in litellm.__all__)\"","Import from the canonical submodule instead (e.g. from litellm.constants import ..., from litellm.utils import ...)","Upgrade or pin litellm to the version the example/tutorial was written for","If the name was removed, find its replacement in the litellm changelog/migration docs"],"exampleFix":"# before\nimport litellm\nlitellm.MAX_TOKENS  # AttributeError: module 'litellm' has no attribute 'MAX_TOKENS'\n\n# after\nimport litellm\nlitellm.max_tokens  # or: from litellm.constants import MAX_TOKENS","handlingStrategy":"type-guard","validationCode":"import litellm\n\nname = \"create_run\"\nif not hasattr(litellm, name):\n    raise AttributeError(f\"litellm does not export {name!r}; check litellm.__all__\")","typeGuard":"import litellm\n\ndef has_litellm_attr(name: str) -> bool:\n    \"\"\"PEP 562 __getattr__ makes hasattr accurate for lazy names.\"\"\"\n    return hasattr(litellm, name)\n\n# usage\nif has_litellm_attr(\"create_run\"):\n    litellm.create_run(...)","tryCatchPattern":"try:\n    fn = getattr(litellm, symbol)\nexcept AttributeError:\n    raise AttributeError(\n        f\"litellm.{symbol} not found in this version ({litellm.__version__}); \"\n        f\"see litellm.__all__ or import from the submodule\"\n    ) from None","preventionTips":["Pin the litellm version and validate dynamic attribute names against litellm.__all__ once at startup","Prefer explicit submodule imports (litellm.utils, litellm.constants) for less-stable internals","Run a tiny import smoke test after upgrading litellm to catch moved/removed symbols before traffic"],"tags":["attributeerror","lazy-import","api-surface","version-upgrade","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"}