Azure OpenAI says the API deployment for this resource does not exist
The API deployment for this resource does not existShort answer
Azure OpenAI does not take a model name in the model field. It takes the name you gave your deployment. The error means Azure found no deployment with that name on the resource your endpoint points to. Put the exact deployment name in model, and check that the endpoint belongs to the resource where you created it.
Fix it fast
1Find out which cause you have
Print the endpoint and the model value your code actually sends, then compare both with the Deployments list of that resource in the Azure portal or Foundry.
import os print(os.getenv("AZURE_OPENAI_ENDPOINT")) print("model sent:", "<the value you pass as model>")2Match what you see, then jump to its fix
- 1
You pass model="gpt-4o" (or similar) but your deployment was named something else, such as my-chat.The model field holds the model name, not the deployment nameFix - 2
The deployment name is correct and visible in the portal, yet the call still fails.The endpoint points to a different resource than the one holding the deploymentFix
- 1
What does the error look like?
The API deployment for this resource does not exist
Cause 1 of 2
The model field holds the model name, not the deployment name
1Check
Azure OpenAI always needs the deployment name in the model argument. Open the resource and read the name in the deployments list; it can differ from the underlying model.
# Compare this value with the deployment name shown in the portal
print("model:", os.getenv("AZURE_OPENAI_DEPLOYMENT"))2Fix
Pass the deployment name as model. Keep it in one environment variable so code and portal cannot drift apart.
response = client.chat.completions.create(
model=os.getenv("AZURE_OPENAI_DEPLOYMENT"), # deployment name, not model name
messages=[{"role": "user", "content": "Hello"}],
)3Verify
The same call returns a completion instead of the error.
print(response.choices[0].message.content)Confirmed by learn.microsoft.com
Cause 2 of 2
The endpoint points to a different resource than the one holding the deployment
1Check
The base URL contains the resource name. A deployment exists only inside the resource where it was created, so a URL built from another resource, or a copied example with a placeholder name, cannot find it.
print(client.base_url)2Fix
Use the endpoint of the resource that owns the deployment, in the documented form with your own resource name.
from openai import OpenAI
client = OpenAI(
api_key=os.getenv("AZURE_OPENAI_API_KEY"),
base_url="https://YOUR-RESOURCE-NAME.openai.azure.com/openai/v1/",
)3Verify
Repeat the call with the deployment name from the first cause.
print(client.base_url)Confirmed by learn.microsoft.com
How do I stop it coming back?
- Store the deployment name and the endpoint as configuration, not as literals scattered in code.
- Name deployments after the job they do, and write the name down next to the model it uses.
- Keep the key and the endpoint from the same resource in one secret set.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- stegnor.comMy company site: 804 pages from a Python and Jinja generator, with 15 free browser tools.
- MenuloA restaurant discovery platform in Germany, kept current by a Python ingestion pipeline.
- ShopGoAn e-commerce aggregator with a Python scraping engine behind its catalog, past 10K Google Play downloads.
Related fixes
AI
Azure OpenAI fails with an SSL certificate verification error
httpx.ConnectError: [SSL: CERTIFICATE_VERIFY_FAILED]
The client checks the endpoint's certificate against its CA bundle, which is certifi by default.
2 causes, each with a fixAI
The OpenAI client says the API key is missing
Missing credentials. Please pass an `api_key`
OpenAI() looks for an api_key argument first and then the OPENAI_API_KEY environment variable.
3 causes, each with a fixAI
OpenAI says the model is a chat model and not supported in the v1/completions endpoint
This is a chat model and not supported in the v1/completions endpoint
The v1/completions endpoint accepts completion models such as gpt-3.5-turbo-instruct.
3 causes, each with a fixAI
Old openai.ChatCompletion or openai.Embedding code breaks on a new SDK
APIRemovedInV1
The Python SDK was rewritten in version 1.0.
2 causes, each with a fixAI
TypeError when you index an OpenAI response like a dictionary
TypeError: 'ChatCompletion' object is not subscriptable
Since SDK 1.0 the OpenAI Python library returns Pydantic model objects instead of dictionaries, so response['choices'] fails.
2 causes, each with a fixAI
TypeError: Client.__init__() got an unexpected keyword argument 'proxies'
TypeError: Client.__init__() got an unexpected keyword argument 'proxies'
httpx 0.28.0 removed its deprecated proxies argument.
2 causes, each with a fix