xtekky/gpt4free · error · ModelNotFoundError
No API endpoint found for model
Error message
No API endpoint found for model: {model} What it means
Azure routes requests by model name: create_async_generator looks up the api_endpoint in the cls.routes dict loaded from AZURE_ROUTES. ModelNotFoundError is raised when routes are configured but the requested model (after alias expansion) has no entry, so the provider has no URL to send the request to.
Solutions
- Add the model -> deployment endpoint mapping to AZURE_ROUTES and restart the process.
- Check spelling: the requested model string must exactly match a key in AZURE_ROUTES (after model_aliases expansion).
- Use a model alias in cls.model_aliases or pass api_endpoint explicitly to bypass routing.
- Call Azure.get_models() to list the currently configured route keys and verify your model is there.
Example fix
# before
export AZURE_ROUTES='{"gpt-4o": "https://res.openai.azure.com/openai/deployments/gpt-4o"}'
# client.calls(model="gpt-4o-mini") -> ModelNotFoundError
# after
export AZURE_ROUTES='{"gpt-4o": "https://res.openai.azure.com/openai/deployments/gpt-4o", "gpt-4o-mini": "https://res.openai.azure.com/openai/deployments/gpt-4o-mini"}' Defensive patterns
Strategy: type-guard
Validate before calling
routes = json.loads(os.environ.get("AZURE_ROUTES", "{}"))
if model not in routes and model not in Azure.model_aliases:
available = list(routes.keys())
raise ValueError(f"model {model!r} has no route; available: {available}") Type guard
def model_is_routed(model: str) -> bool:
"""True when the model (after alias expansion) has an AZURE_ROUTES endpoint."""
resolved = Azure.model_aliases.get(model, model)
return resolved in Azure.routes Try / catch
from g4f.errors import ModelNotFoundError
try:
await Azure.create_async_generator(model=model, messages=messages)
except ModelNotFoundError as e:
if "No API endpoint" in str(e):
# config gap: add route or fix model name; do not retry
raise Prevention
- Call Azure.get_models() at startup and assert your model list is covered
- Keep AZURE_ROUTES keys in sync with deployment names whenever you add a model
- Pass api_endpoint explicitly when using ad-hoc deployment names
When it happens
Trigger: AZURE_ROUTES contains e.g. only 'gpt-4o', and the caller requests model='gpt-4o-mini' (and it is not in model_aliases). The lookup cls.routes.get(model) returns None while cls.routes is non-empty -> immediate raise.
Common situations: New deployment added in Azure but AZURE_ROUTES not updated; typo in the model name; using a public model name that differs from your custom Azure deployment name; forgetting to restart the process after updating the env var.
Related errors
- API key is required for Azure provider. Ask for API key in…
- Invalid AZURE_API_KEYS environment variable
- Invalid AZURE_ROUTES environment variable format
- API key has failed too many times.
- Claude organization ID not found. Please set the…
AI-assisted analysis of xtekky/gpt4free@973504e177 (2026-08-14).
Data as JSON: /api/errors/d2ec73b1690cc96d.
Report an issue: GitHub.
Appendix: source
Thrown at g4f/Provider/needs_auth/Azure.py:79
cls,
model: str,
messages: Messages,
stream: bool = True,
media: MediaListType = None,
api_key: str = None,
api_endpoint: str = None,
**kwargs,
) -> AsyncResult:
if not model:
model = os.environ.get("AZURE_DEFAULT_MODEL", cls.default_model)
if model in cls.model_aliases:
model = cls.model_aliases[model]
if not api_endpoint:
if not cls.routes:
cls.get_models()
api_endpoint = cls.routes.get(model)
if cls.routes and not api_endpoint:
raise ModelNotFoundError(f"No API endpoint found for model: {model}")
if not api_endpoint:
api_endpoint = os.environ.get("AZURE_API_ENDPOINT")
if cls.api_keys:
api_key = cls.api_keys.get(model, cls.api_keys.get("default"))
if not api_key:
raise ValueError(
f"API key is required for Azure provider. Ask for API key in the {cls.login_url} Discord server."
)
if api_endpoint and "/images/" in api_endpoint:
prompt = format_media_prompt(messages, kwargs.get("prompt"))
width, height = get_width_height(
kwargs.get("aspect_ratio", "1:1"),
kwargs.get("width"),
kwargs.get("height"),
)
output_format = kwargs.get("output_format", "png")
form = None
data = NoneView on GitHub (pinned to 973504e177)