{"record":{"id":"d2ec73b1690cc96d","repo":"xtekky/gpt4free","slug":"no-api-endpoint-found-for-model-model","errorCode":null,"errorMessage":"No API endpoint found for model: {model}","messagePattern":"No API endpoint found for model: (.+?)","errorType":"exception","errorClass":"ModelNotFoundError","httpStatus":null,"severity":"error","filePath":"g4f/Provider/needs_auth/Azure.py","lineNumber":79,"sourceCode":"        cls,\n        model: str,\n        messages: Messages,\n        stream: bool = True,\n        media: MediaListType = None,\n        api_key: str = None,\n        api_endpoint: str = None,\n        **kwargs,\n    ) -> AsyncResult:\n        if not model:\n            model = os.environ.get(\"AZURE_DEFAULT_MODEL\", cls.default_model)\n        if model in cls.model_aliases:\n            model = cls.model_aliases[model]\n        if not api_endpoint:\n            if not cls.routes:\n                cls.get_models()\n            api_endpoint = cls.routes.get(model)\n            if cls.routes and not api_endpoint:\n                raise ModelNotFoundError(f\"No API endpoint found for model: {model}\")\n        if not api_endpoint:\n            api_endpoint = os.environ.get(\"AZURE_API_ENDPOINT\")\n        if cls.api_keys:\n            api_key = cls.api_keys.get(model, cls.api_keys.get(\"default\"))\n            if not api_key:\n                raise ValueError(\n                    f\"API key is required for Azure provider. Ask for API key in the {cls.login_url} Discord server.\"\n                )\n        if api_endpoint and \"/images/\" in api_endpoint:\n            prompt = format_media_prompt(messages, kwargs.get(\"prompt\"))\n            width, height = get_width_height(\n                kwargs.get(\"aspect_ratio\", \"1:1\"),\n                kwargs.get(\"width\"),\n                kwargs.get(\"height\"),\n            )\n            output_format = kwargs.get(\"output_format\", \"png\")\n            form = None\n            data = None","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/Provider/needs_auth/Azure.py#L61-L97","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before\nexport AZURE_ROUTES='{\"gpt-4o\": \"https://res.openai.azure.com/openai/deployments/gpt-4o\"}'\n# client.calls(model=\"gpt-4o-mini\") -> ModelNotFoundError\n\n# after\nexport 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\"}'","handlingStrategy":"type-guard","validationCode":"routes = json.loads(os.environ.get(\"AZURE_ROUTES\", \"{}\"))\nif model not in routes and model not in Azure.model_aliases:\n    available = list(routes.keys())\n    raise ValueError(f\"model {model!r} has no route; available: {available}\")","typeGuard":"def model_is_routed(model: str) -> bool:\n    \"\"\"True when the model (after alias expansion) has an AZURE_ROUTES endpoint.\"\"\"\n    resolved = Azure.model_aliases.get(model, model)\n    return resolved in Azure.routes","tryCatchPattern":"from g4f.errors import ModelNotFoundError\n\ntry:\n    await Azure.create_async_generator(model=model, messages=messages)\nexcept ModelNotFoundError as e:\n    if \"No API endpoint\" in str(e):\n        # config gap: add route or fix model name; do not retry\n        raise","preventionTips":["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"],"tags":["configuration","model-routing","azure","model-not-found"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}