xtekky/gpt4free · error · ValueError

Provider with label '{label}' not found

Error message

Provider with label '{label}' not found

What it means

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.

Source

Thrown at g4f/Provider/__init__.py:530

    @classmethod
    def get_by_label(cls, label: str) -> ProviderType:
        if not label:
            raise ValueError("Label must be provided")

        # Check explicit map
        try:
            return __getattr__(label)
        except AttributeError:
            pass

        # Fallback to search
        for provider_name in _provider_names:
            if provider_name.lower().startswith(label.lower()):
                provider = __map__[provider_name]
                if provider.working:
                    return provider

        raise ValueError(f"Provider with label '{label}' not found")


import sys
import types


class LazyProviderModule(types.ModuleType):
    def __getattribute__(self, name):
        if name.startswith("__"):
            return super().__getattribute__(name)

        try:
            return __getattr__(name)
        except AttributeError:
            pass

        return super().__getattribute__(name)

View on GitHub (pinned to 973504e177)

Solutions

  1. Verify the exact name in _provider_names / dir(g4f.Provider)
  2. Use a longer, exact label so the direct __getattr__ path resolves
  3. Update g4f — provider names and working flags change between releases
  4. Offer the user the list of valid labels on failure

Example fix

# before
provider = ProviderUtils.get_by_label('gemin')  # ambiguous/unknown

# after
provider = ProviderUtils.get_by_label('Gemini')  # exact name
Defensive patterns

Strategy: try-catch

Validate before calling

import difflib, g4f.Provider as P

def resolve_label(label):
    if label in P._provider_names:
        return label
    close = difflib.get_close_matches(label, P._provider_names, n=1, cutoff=0.6)
    return close[0] if close else None

Type guard

def is_resolvable_label(label: str) -> bool:
    import g4f.Provider as P
    return label in P._provider_names or any(
        n.lower().startswith(label.lower()) for n in P._provider_names
    )

Try / catch

try:
    provider = ProviderUtils.get_by_label(label)
except ValueError:
    suggestions = [n for n in ProviderUtils.convert.keys() if n.lower().startswith(label.lower()[:3])]
    raise ConfigError(f'unknown provider {label!r}; did you mean: {suggestions[:3]}?')

Prevention

When it happens

Trigger: 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).

Common situations: User-supplied provider strings; labels copied from outdated docs; prefixes matching only providers disabled upstream.

Related errors


AI-assisted analysis of xtekky/gpt4free@973504e177 (2026-08-14). Data as JSON: /api/errors/b9b47af76a10b5a9. Report an issue: GitHub.