BerriAI/litellm · error · AttributeError
module {__name__!r} has no attribute {name!r}
Error message
module {__name__!r} has no attribute {name!r} What it means
litellm's package __init__ implements module-level __getattr__ for lazy loading. When an attribute is requested that is not served by any of the lazy-import handlers (the runs API block shown just above is one of the last explicit branches), the fallback raises AttributeError naming the module and the missing attribute. Practically this means the name does not exist in the litellm top-level namespace in your installed version.
Source
Thrown at litellm/__init__.py:2340
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 6c2dcb801b)
Solutions
- Check the installed version's exports: `python -c "import litellm; print(litellm.__version__)"` and inspect dir(litellm) or the import maps in litellm/_lazy_imports.py.
- Import from the canonical submodule instead of the top level (e.g. from litellm.types.utils import ModelResponse).
- If the symbol existed in another release, pin/upgrade litellm to the version your code was written against.
- Fix typos — the error message includes the exact attribute name as seen by __getattr__.
Example fix
# before import litellm encoder = litellm.cost_per_token # AttributeError: module 'litellm' has no attribute ... # after: import from the submodule that owns it from litellm.cost_calculator import cost_per_token
Defensive patterns
Strategy: type-guard
Validate before calling
import litellm, importlib.metadata
print(importlib.metadata.version('litellm'))
print([n for n in dir(litellm) if 'token' in n.lower()]) # confirm name exists Type guard
import litellm
def litellm_has(name: str) -> bool:
try:
getattr(litellm, name)
return True
except AttributeError:
return False
assert litellm_has('ModelResponse') Try / catch
try:
obj = getattr(litellm, name)
except AttributeError as e:
raise ImportError(f'{name} not in litellm {litellm.__version__}; import from submodule') from e Prevention
- Pin litellm and write code against that version's documented top-level exports.
- Prefer submodule imports for anything non-core.
- Wrap dynamic getattr(litellm, x) in guards; never assume a name exists across versions.
When it happens
Trigger: getattr(litellm, 'some_name'), `from litellm import some_name`, or hasattr-driven duck typing where some_name was never exported or was removed/renamed across versions — e.g. reaching for an old helper after downgrading, or a new symbol after upgrading.
Common situations: Version pinning mismatches between environments (code written against newer litellm running on older); typos in imports; plugins or copy-pasted snippets referencing API that moved into submodules; tools that iterate module attributes (pickle/copy of modules, doctests) hitting the fallback.
Related errors
- {category} lazy import: unknown attribute {name!r}
- Utils module lazy import: unknown attribute {name!r}
- LLM client cache lazy import: unknown attribute {name!r}
- HTTP handlers lazy import: unknown attribute {name!r}
- module {__name__!r} has no attribute {name!r}
AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15).
Data as JSON: /api/errors/b40742b4ae1faa9f.
Report an issue: GitHub.