{"record":{"id":"b9b47af76a10b5a9","repo":"xtekky/gpt4free","slug":"provider-with-label-label-not-found","errorCode":null,"errorMessage":"Provider with label '{label}' not found","messagePattern":"Provider with label '(.+?)' not found","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"g4f/Provider/__init__.py","lineNumber":530,"sourceCode":"    @classmethod\n    def get_by_label(cls, label: str) -> ProviderType:\n        if not label:\n            raise ValueError(\"Label must be provided\")\n\n        # Check explicit map\n        try:\n            return __getattr__(label)\n        except AttributeError:\n            pass\n\n        # Fallback to search\n        for provider_name in _provider_names:\n            if provider_name.lower().startswith(label.lower()):\n                provider = __map__[provider_name]\n                if provider.working:\n                    return provider\n\n        raise ValueError(f\"Provider with label '{label}' not found\")\n\n\nimport sys\nimport types\n\n\nclass LazyProviderModule(types.ModuleType):\n    def __getattribute__(self, name):\n        if name.startswith(\"__\"):\n            return super().__getattribute__(name)\n\n        try:\n            return __getattr__(name)\n        except AttributeError:\n            pass\n\n        return super().__getattribute__(name)\n","sourceCodeStart":512,"sourceCodeEnd":548,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/Provider/__init__.py#L512-L548","documentation":"ValueError from ProviderUtils.get_by_label() when resolution fails: __getattr__(label) raised AttributeError (no exact provider by that name) AND no entry in _provider_names case-insensitively starts with the label among providers flagged working. Note the prefix fallback silently skips providers with working=False, so an exact-name match attempt is tried first regardless, but prefix matches only return working providers.","triggerScenarios":"Calling get_by_label with a typo, an obsolete label, or a prefix that only matches non-working providers (e.g. a provider currently marked broken in that g4f release).","commonSituations":"User-supplied provider strings; labels copied from outdated docs; prefixes matching only providers disabled upstream.","solutions":["Verify the exact name in _provider_names / dir(g4f.Provider)","Use a longer, exact label so the direct __getattr__ path resolves","Update g4f — provider names and working flags change between releases","Offer the user the list of valid labels on failure"],"exampleFix":"# before\nprovider = ProviderUtils.get_by_label('gemin')  # ambiguous/unknown\n\n# after\nprovider = ProviderUtils.get_by_label('Gemini')  # exact name","handlingStrategy":"try-catch","validationCode":"import difflib, g4f.Provider as P\n\ndef resolve_label(label):\n    if label in P._provider_names:\n        return label\n    close = difflib.get_close_matches(label, P._provider_names, n=1, cutoff=0.6)\n    return close[0] if close else None","typeGuard":"def is_resolvable_label(label: str) -> bool:\n    import g4f.Provider as P\n    return label in P._provider_names or any(\n        n.lower().startswith(label.lower()) for n in P._provider_names\n    )","tryCatchPattern":"try:\n    provider = ProviderUtils.get_by_label(label)\nexcept ValueError:\n    suggestions = [n for n in ProviderUtils.convert.keys() if n.lower().startswith(label.lower()[:3])]\n    raise ConfigError(f'unknown provider {label!r}; did you mean: {suggestions[:3]}?')","preventionTips":["Use exact provider names from dir(g4f.Provider) in configs","Surface the valid-label list when resolution fails","Re-validate saved labels after upgrading g4f"],"tags":["provider-registry","label-resolution","validation"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}