Debug Fix easy · 3 min read

Fix Azure OpenAI deployment not found error

Quick answer
The deployment not found error occurs when the model parameter in AzureOpenAI calls does not match the deployment name configured in your Azure OpenAI resource. Use the AzureOpenAI client with the exact deployment name (not the model name) and ensure azure_endpoint and api_version are set correctly.
ERROR TYPE config_error
⚡ QUICK FIX
Use the exact Azure deployment name in the model parameter when calling AzureOpenAI.chat.completions.create().

Why this happens

This error is triggered when your code uses the Azure OpenAI SDK but specifies a model parameter that is not the deployment name you created in the Azure portal. Azure OpenAI requires you to deploy a model under a custom deployment name and then use that deployment name in API calls, not the base model name like gpt-4o.

Typical error message:

azure.core.exceptions.ResourceNotFoundError: Deployment not found

Example of incorrect code causing this error:

python
from openai import AzureOpenAI
import os

client = AzureOpenAI(
    api_key=os.environ["AZURE_OPENAI_API_KEY"],
    azure_endpoint=os.environ["AZURE_OPENAI_ENDPOINT"],
    api_version="2024-02-01"
)

response = client.chat.completions.create(
    model="gpt-4o",  # Incorrect: should be deployment name
    messages=[{"role": "user", "content": "Hello"}]
)
print(response.choices[0].message.content)
output
azure.core.exceptions.ResourceNotFoundError: Deployment not found

The fix

Use the exact deployment name you configured in the Azure portal for your OpenAI resource as the model parameter. This deployment name is case-sensitive and often looks like gpt4o-deployment or a custom string you chose.

Ensure you instantiate AzureOpenAI with the correct azure_endpoint and api_version. Then call chat.completions.create() with the deployment name.

python
from openai import AzureOpenAI
import os

client = AzureOpenAI(
    api_key=os.environ["AZURE_OPENAI_API_KEY"],
    azure_endpoint=os.environ["AZURE_OPENAI_ENDPOINT"],
    api_version="2024-02-01"
)

response = client.chat.completions.create(
    model=os.environ["AZURE_OPENAI_DEPLOYMENT"],  # Correct deployment name
    messages=[{"role": "user", "content": "Hello"}]
)
print(response.choices[0].message.content)
output
Hello

Preventing it in production

  • Validate your deployment names by listing them in the Azure portal or via Azure CLI before using them in code.
  • Use environment variables for deployment names to avoid hardcoding and typos.
  • Implement retry logic with exponential backoff for transient errors.
  • Log API errors clearly to detect misconfiguration early.
  • Keep azure_endpoint and api_version updated per Azure documentation.

Key Takeaways

  • Always use the Azure deployment name, not the base model name, in model parameter.
  • Configure AzureOpenAI client with correct azure_endpoint and api_version.
  • Use environment variables for deployment names to avoid typos and ease updates.
Verified 2026-04 · gpt-4o, AzureOpenAI
Verify ↗