xtekky/gpt4free · error · ValueError

Provider not found: {provider_name!r}

Error message

Provider not found: {provider_name!r}

What it means

ValueError from the config.yaml provider resolver: a provider name string could not be resolved to a provider class — it is absent from ProviderUtils.convert and not an attribute of the g4f.Provider module. The message echoes the offending name with repr() so whitespace/case errors are visible.

Source

Thrown at g4f/providers/config_provider.py:458

# ---------------------------------------------------------------------------
# Config-based provider
# ---------------------------------------------------------------------------


def _resolve_provider(provider_name: str):
    """Resolve a provider name string to a provider class."""
    from .. import Provider
    from ..Provider import ProviderUtils

    if provider_name in ProviderUtils.convert:
        return ProviderUtils.convert[provider_name]

    # Try direct attribute lookup on the Provider module
    provider = getattr(Provider, provider_name, None)
    if provider is not None:
        return provider

    raise ValueError(f"Provider not found: {provider_name!r}")


async def _get_quota_cached(provider) -> Optional[dict]:
    """Return quota info for *provider*, using the cache when possible."""
    name = getattr(provider, "__name__", str(provider))
    cached = QuotaCache.get(name)
    if cached is not None:
        return cached
    if not hasattr(provider, "get_quota"):
        return None
    try:
        quota = await provider.get_quota()
        if quota is not None:
            QuotaCache.set(name, quota)
        return quota
    except Exception as e:
        debug.error(f"config.yaml: get_quota failed for {name}:", e)
        return None

View on GitHub (pinned to 973504e177)

Solutions

  1. Print available names — from g4f import Provider; print([n for n in dir(Provider) if not n.startswith('_')]) — and match your config to it exactly (case-sensitive).
  2. Update g4f if the provider exists upstream but not in your installed version.
  3. Remove or comment out the unknown provider entry in config.yaml.
  4. Check for invisible whitespace in the YAML value (repr in the error message reveals it).

Example fix

# before (config.yaml)
provider: "OpenAiChat "

# after
provider: "OpenaiChat"
Defensive patterns

Strategy: validation

Validate before calling

from g4f import Provider
from g4f.Provider import ProviderUtils
unknown = [n for n in my_provider_names
           if n not in ProviderUtils.convert and getattr(Provider, n, None) is None]
if unknown:
    raise ValueError(f'config.yaml references unknown providers: {unknown}')

Type guard

def provider_exists(name: str) -> bool:
    from g4f import Provider
    from g4f.Provider import ProviderUtils
    return name in ProviderUtils.convert or getattr(Provider, name, None) is not None

Prevention

When it happens

Trigger: A config.yaml entry lists provider: 'Openai' / 'SomeTypo' / a provider removed from g4f; the resolver looks it up in ProviderUtils.convert and getattr(Provider, name) and both miss.

Common situations: Typos or wrong casing in provider names; configs written for an older/newer g4f where the provider was renamed or dropped; trailing spaces or quotes issues from YAML; community providers not shipped in your install.

Related errors


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