Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
AI and LLM integration

Azure OpenAI says the API deployment for this resource does not exist

ErrorThe API deployment for this resource does not exist

Short 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.

  • Applies to openai Python SDK 1.x, Azure OpenAI v1 endpoint
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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>")
  2. 2Match what you see, then jump to its fix

    1. 1You 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. 2The 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

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

Did this fix it?

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

Did this fix it?

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:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.