{"record":{"id":"85e1a640d93afa9f","repo":"xtekky/gpt4free","slug":"module-g4f-provider-has-no-attribute-name","errorCode":null,"errorMessage":"module 'g4f.Provider' has no attribute '{name}'","messagePattern":"module 'g4f\\.Provider' has no attribute '(.+?)'","errorType":"exception","errorClass":"AttributeError","httpStatus":null,"severity":"error","filePath":"g4f/Provider/__init__.py","lineNumber":476,"sourceCode":"_loaded_providers = {}\n\n\ndef __getattr__(name: str):\n    if name in _loaded_providers:\n        return _loaded_providers[name]\n    if name == \"__providers__\":\n        # Load all providers if specifically requested\n        providers_list = []\n        for provider_name in _provider_names:\n            try:\n                providers_list.append(__getattr__(provider_name))\n            except AttributeError:\n                pass\n        return providers_list\n    try:\n        return _resolve_provider(name)\n    except ImportError as e:\n        raise AttributeError(f\"module '{__name__}' has no attribute '{name}'\") from e\n\n\ndef __dir__():\n    return __all__\n\n\nclass _ConvertDict(dict):\n    def __contains__(self, item):\n        return item in _provider_names\n\n    def __getitem__(self, item):\n        try:\n            return __getattr__(item)\n        except AttributeError:\n            raise KeyError(f\"Provider '{item}' not found\")\n\n    def keys(self):\n        return _provider_names","sourceCodeStart":458,"sourceCodeEnd":494,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/Provider/__init__.py#L458-L494","documentation":"AttributeError raised by the module-level __getattr__ in g4f.Provider when _resolve_provider(name) raises ImportError. Provider modules are imported lazily; if importing the provider's file fails (missing optional dependency, syntax/module error, or name not in _provider_names), the lookup is converted into a standard 'module has no attribute' AttributeError so attribute access semantics are preserved.","triggerScenarios":"Accessing g4f.Provider.SomeName where SomeName is misspelled, was removed/renamed in a g4f upgrade, or whose module raises ImportError on import (e.g. a provider needing an uninstalled optional package).","commonSituations":"Code written against an older g4f version referencing providers deleted upstream; typos in provider names passed as strings; deploying without optional extras so a provider's imports fail.","solutions":["Check the spelling and case against _provider_names / dir(g4f.Provider) for your installed version","If the provider was renamed in a g4f update, migrate to the new name (see changelog)","Install missing optional dependencies that make the provider's module import fail","Pin the g4f version your code was developed against"],"exampleFix":"# before\nprovider = g4f.Provider.GeminiProVision  # removed in newer g4f\n\n# after\nprovider = g4f.Provider.Gemini  # or list available: print(dir(g4f.Provider))","handlingStrategy":"validation","validationCode":"import g4f.Provider as P\n\ndef get_provider(name):\n    if name not in dir(P):  # uses __dir__ -> __all__\n        raise ValueError(f'unknown provider {name!r}; available: ...')\n    return getattr(P, name)","typeGuard":"def is_known_provider(name: str) -> bool:\n    import g4f.Provider as P\n    return name in P._provider_names","tryCatchPattern":"try:\n    provider = getattr(g4f.Provider, name)\nexcept AttributeError:\n    provider = None  # or nearest match from g4f.Provider._provider_names","preventionTips":["Resolve provider names dynamically from the installed version, not hardcoded lists","Pin the g4f version in production","Validate user/config-supplied provider names before use"],"tags":["provider-registry","lazy-import","version-compat","attributeerror"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}