BerriAI/litellm · error · AttributeError
module has no attribute
Error message
module {__name__!r} has no attribute {name!r} What it means
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.
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
Example fix
# before import litellm litellm.MAX_TOKENS # AttributeError: module 'litellm' has no attribute 'MAX_TOKENS' # after import litellm litellm.max_tokens # or: from litellm.constants import MAX_TOKENS
Defensive patterns
Strategy: type-guard
Validate before calling
import litellm
name = "create_run"
if not hasattr(litellm, name):
raise AttributeError(f"litellm does not export {name!r}; check litellm.__all__") Type guard
import litellm
def has_litellm_attr(name: str) -> bool:
"""PEP 562 __getattr__ makes hasattr accurate for lazy names."""
return hasattr(litellm, name)
# usage
if has_litellm_attr("create_run"):
litellm.create_run(...) Try / catch
try:
fn = getattr(litellm, symbol)
except AttributeError:
raise AttributeError(
f"litellm.{symbol} not found in this version ({litellm.__version__}); "
f"see litellm.__all__ or import from the submodule"
) from None Prevention
- 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
When it happens
Trigger: `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.
Common situations: 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).
Related errors
- lazy import: unknown attribute
- Utils module lazy import: unknown attribute
- HTTP handlers lazy import: unknown attribute
- LLM client cache lazy import: unknown attribute
- {e}
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/b40742b4ae1faa9f.
Report an issue: GitHub.
Appendix: source
Thrown at litellm/__init__.py:2344
get_eval,
update_eval,
delete_eval,
cancel_eval,
acreate_run,
alist_runs,
aget_run,
acancel_run,
adelete_run,
create_run,
list_runs,
get_run,
cancel_run,
delete_run,
)
return locals()[name]
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
# ALL_LITELLM_RESPONSE_TYPES is lazy-loaded via __getattr__ to avoid loading utils at import time
View on GitHub (pinned to 77b7c6c40c)