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 NoneView on GitHub (pinned to 973504e177)
Solutions
- 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).
- Update g4f if the provider exists upstream but not in your installed version.
- Remove or comment out the unknown provider entry in config.yaml.
- 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
- Validate provider names against the installed g4f at app startup.
- Names are case-sensitive and must not have stray whitespace.
- Re-validate config.yaml after every g4f upgrade.
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
- {provider_name} has no supported create method
- Unexpected end of condition expression
- Unknown variable in condition: {root!r}
- Cannot access field {part!r} on non-dict value while resolvi
- Unexpected token {kind!r}={value!r} in condition expression
AI-assisted analysis of xtekky/gpt4free@973504e177 (2026-08-14).
Data as JSON: /api/errors/992b917c562e0010.
Report an issue: GitHub.