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.images.main defines a module-level __getattr__ that lazily imports only ImageEditRequestUtils; any other unknown attribute access raises AttributeError('module ... has no attribute ...') (litellm/images/main.py:1033). This is standard Python behavior for missing module attributes surfaced through the lazy-import hook.
Source
Thrown at litellm/images/main.py:1033
model=model,
custom_llm_provider=custom_llm_provider,
original_exception=e,
completion_kwargs=local_vars,
extra_kwargs=kwargs,
)
def __getattr__(name: str) -> Any:
"""Lazy import handler for images.main module"""
if name == "ImageEditRequestUtils":
# Lazy load ImageEditRequestUtils to avoid heavy import from images.utils at module load time
from .utils import ImageEditRequestUtils as _ImageEditRequestUtils
# Cache it in the module's __dict__ for subsequent accesses
module: Final = importlib.import_module(__name__)
module.__dict__["ImageEditRequestUtils"] = _ImageEditRequestUtils
return _ImageEditRequestUtils
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
View on GitHub (pinned to 6c2dcb801b)
Solutions
- Check dir(litellm.images.main) for the actual exported names and correct the import
- Import the symbol from its canonical module (e.g. litellm.images.utils for ImageEditRequestUtils)
- Upgrade/downgrade litellm to the version whose API surface your code targets
- For dynamic access, guard with hasattr() before getattr()
Example fix
# before from litellm.images.main import ImageGenerationUtils # AttributeError # after from litellm.images.utils import ImageEditRequestUtils
Defensive patterns
Strategy: type-guard
Validate before calling
import litellm.images.main as images_main AVAILABLE = set(dir(images_main)) assert "ImageEditRequestUtils" in AVAILABLE
Type guard
def module_has(module, name: str) -> bool:
try:
getattr(module, name)
return True
except AttributeError:
return False Try / catch
try:
from litellm.images.main import ImageEditRequestUtils
except AttributeError as e:
from litellm.images.utils import ImageEditRequestUtils # canonical location Prevention
- Import from canonical modules rather than internal routing modules
- Guard dynamic getattr with hasattr
- Track litellm release notes for moved/renamed symbols
When it happens
Trigger: getattr(litellm.images.main, 'SomeName'), from litellm.images.main import SomeName where SomeName doesn't exist; misspelling an export; relying on an attribute removed or renamed between litellm versions.
Common situations: Code written against a different litellm version importing a symbol that moved; IDE autocomplete suggesting a stale name; dynamic inspection tooling probing module attributes.
Related errors
- module {__name__!r} has no attribute {name!r}
- {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}
AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15).
Data as JSON: /api/errors/4140ce13c698b1a4.
Report an issue: GitHub.