xtekky/gpt4free · error · ValueError
Unknown Gemini model: {model}. Supported models: {', '.join(
Error message
Unknown Gemini model: {model}. Supported models: {', '.join(models)} What it means
ValueError from Gemini._resolve_model: after alias expansion (MODEL_ALIASES) the model name is not in the provider's supported models set. The message lists every supported model, so it doubles as live documentation. It fires before any network call — a pure input-validation failure.
Source
Thrown at g4f/Provider/needs_auth/Gemini.py:256
yield buffer.decode("utf-8", errors="replace")
def _resolve_model(model: str, think_override: int = None) -> tuple[str, bool]:
requested_model = model
think_mode = think_override
if "@think=" in model:
model, think_value = model.rsplit("@think=", 1)
requested_model = model
try:
think_mode = int(think_value)
except ValueError as exc:
raise ValueError(f"Invalid thinking mode: {think_value!r}") from exc
if think_mode is not None:
if not isinstance(think_mode, int) or not 0 <= think_mode <= 4:
raise ValueError("Thinking mode must be an integer between 0 and 4")
model = MODEL_ALIASES.get(model, model)
if model not in models:
raise ValueError(
f"Unknown Gemini model: {model}. " f"Supported models: {', '.join(models)}"
)
expanded_thinking = (
requested_model in EXPANDED_MODEL_ALIASES
if think_mode is None
else think_mode <= 2
)
return model, expanded_thinking
def _normalize_messages(messages: Messages | None) -> Messages:
if messages is None:
return []
if not isinstance(messages, list):
raise TypeError("messages must be a list")
return messages
View on GitHub (pinned to 973504e177)
Solutions
- Pick a model from the list embedded in the error message and use that exact string.
- Update g4f to the latest version so newly released Gemini models are recognized.
- Check MODEL_ALIASES in the provider source for accepted shorthand names before inventing your own.
- If the model must be user-configurable, validate against the provider's models list at startup.
Example fix
# before resp = await client.chat.completions.create(model="gemini-2.5-flsh", provider=Gemini, messages=msgs) # ValueError: Unknown Gemini model: gemini-2.5-flsh. Supported models: ... # after resp = await client.chat.completions.create(model="gemini-2.5-flash", provider=Gemini, messages=msgs)
Defensive patterns
Strategy: validation
Validate before calling
from g4f.Provider.needs_auth.Gemini import Gemini
from g4f.models import models as known_models # adjust to your g4f version
def gemini_model_supported(model: str) -> bool:
base = model.rsplit("@think=", 1)[0]
aliases = getattr(Gemini, "MODEL_ALIASES", {})
resolved = aliases.get(base, base)
return resolved in Gemini.supported_models if hasattr(Gemini, "supported_models") else True Type guard
def is_known_gemini_model(model: str, supported: set[str]) -> bool:
base = model.rsplit("@think=", 1)[0]
return base in supported Try / catch
try:
resp = await client.chat.completions.create(model=m, provider=Gemini, messages=msgs)
except ValueError as e:
if "Unknown Gemini model" in str(e):
supported = [name for name in str(e).split("Supported models: ")[-1].split(", ")]
m = pick_closest(m, supported) Prevention
- Validate model names against the provider's supported list at startup.
- Pin g4f versions so the supported-model list doesn't shift under you.
- Parse the error's supported-models list to offer users valid options.
When it happens
Trigger: Passing a Gemini model string that is neither a known alias nor a supported model — typos ("gemini-2.5-flsh"), retired names, or names from other providers. Also triggers when an @think= suffix was stripped correctly but the base name is wrong.
Common situations: Model deprecated/renamed after a Gemini API update while g4f pins the old list; typo'd model names from config files; assuming any Google model id works.
Related errors
- Invalid thinking mode: {think_value!r}
- Thinking mode must be an integer between 0 and 4
- Model '{model}' is not supported by {cls.__name__}. Supporte
- Provider '{item}' not found
- Label must be provided
AI-assisted analysis of xtekky/gpt4free@973504e177 (2026-08-14).
Data as JSON: /api/errors/0fe5ebe95818e474.
Report an issue: GitHub.