ResourceNotFound
azure.core.exceptions.ResourceNotFoundError
Stack trace
azure.core.exceptions.ResourceNotFoundError: (404) ResourceNotFound
Message: Deployment 'my-deployment' not found in Azure OpenAI resource.
During handling of the above exception, the following error occurred:
Traceback (most recent call last):
File "app.py", line 25, in <module>
response = client.chat.completions.create(
File "/usr/local/lib/python3.9/site-packages/azure/ai/openai/_client.py", line 150, in create
raise ResourceNotFoundError(message)
azure.core.exceptions.ResourceNotFoundError: Deployment 'my-deployment' not found in Azure OpenAI resource. Why it happens
This error occurs because the deployment name provided in your Azure OpenAI client configuration does not match any deployment configured in your Azure OpenAI resource. The Azure service cannot find the requested deployment to route your request.
Detection
Check for ResourceNotFoundError exceptions when calling Azure OpenAI APIs and verify the deployment name against your Azure portal deployments before making requests.
Causes & fixes
The deployment name specified in the client does not exist in the Azure OpenAI resource.
Verify and use the exact deployment name as configured in the Azure portal under your OpenAI resource deployments.
Using the wrong Azure OpenAI resource endpoint or subscription that does not contain the deployment.
Ensure your client is configured with the correct Azure OpenAI resource endpoint and subscription matching the deployment.
Deployment was deleted or not yet created in the Azure portal.
Create the deployment in the Azure portal or confirm it exists before calling the API.
Code: broken vs fixed
import os
from azure.ai.openai import OpenAIClient
client = OpenAIClient(
endpoint=os.environ["AZURE_OPENAI_ENDPOINT"],
credential=os.environ["AZURE_OPENAI_KEY"]
)
response = client.chat.completions.create(
deployment_name="wrong-deployment", # This causes ResourceNotFound error
messages=[{"role": "user", "content": "Hello"}]
)
print(response.choices[0].message.content) import os
from azure.ai.openai import OpenAIClient
client = OpenAIClient(
endpoint=os.environ["AZURE_OPENAI_ENDPOINT"],
credential=os.environ["AZURE_OPENAI_KEY"]
)
# Fixed: Use the correct deployment name as configured in Azure portal
response = client.chat.completions.create(
deployment_name=os.environ["AZURE_OPENAI_DEPLOYMENT_NAME"],
messages=[{"role": "user", "content": "Hello"}]
)
print(response.choices[0].message.content) Workaround
Catch ResourceNotFoundError exceptions and log the deployment name and endpoint used; optionally fallback to a default deployment if available.
Prevention
Automate deployment name validation by fetching available deployments from Azure API or maintain deployment names in a centralized config to avoid typos and mismatches.