Connect Azure OpenAI models
This guide shows how to connect a model deployed in your own Azure OpenAI resource, such as GPT-4o, so your tenant can use it in Chat and through the platform API, the same way as the platform's own models.
Before you start
- The Editor or Owner role in your tenant. See Roles in a tenant.
- Access to an Azure subscription. To create a resource and copy its keys, you need the Cognitive Services Contributor role. To deploy a model, Cognitive Services OpenAI Contributor is also enough. See Role-based access control for Azure OpenAI.
Get your Azure values
You need four values from Azure: the Deployment name, Endpoint, Key and API version when connecting to a model deployed in your own Azure OpenAI resource.
-
Create an Azure OpenAI resource
Skip this step if you already have one. In the Azure portal, select Create a resource, search for Azure OpenAI and select Create. See Create and deploy an Azure OpenAI resource.
-
Deploy a model
Open Microsoft Foundry select the model you want to deploy.
-
Get the endpoint and API key
After deploying the model, come back to Microsoft Foundry and open the model you just deployed. There you can find the Deployment name, Endpoint and Key.
-
Pick an API version
Choose a dated version from Azure OpenAI API versions, or the one your existing code uses, such as
2024-02-01. Chat works without it, but calls from code don't.
Connect to an Azure OpenAI model
-
In the sidebar of the CM portal, go to Models → External Models → Connect external model.
-
Fill in the form:
Field Enter Example Provider Azure OpenAI — Provider model ID The Deployment name from step 3. Not the model's name. It can't be changed later. gpt-4o-prodAPI key The Key from step 3 3f9a...Base URL The Endpoint from step 3 https://my-resource.openai.azure.comAPI version The version from step 4. The form doesn't require it, but calls from code fail without it. 2024-02-01API model id The name your apps use to call the model. It copies Provider model ID until you edit it. It must be unique on the platform and can't be changed later. gpt-4oDisplay name The name people see in the portal and in Chat GPT-4o (Azure)Model type Chat, Embedding, Transcription or Guardrail. Choosing it ticks the matching modalities. See Choose the model type and modalities. Chat Input modalities What the model accepts. Keep the ticked ones and add any the model also supports. See Choose the model type and modalities. Text, Image Output modalities What the model returns. Keep the ticked ones. See Choose the model type and modalities. Text Context length The model's maximum tokens per request. Optional, but Azure doesn't report it, and apps and Chat use it to size prompts. 128000 -
Select Connect model. The model appears on the External Models tab.
-
Share it. Right now only you and the tenant's Owners can use it. Open the model, go to the Users tab and share it with the people, groups or whole tenant that should use it. See Share a resource.
Connect model saves the form without checking anything with Azure. If a value is wrong, you only find out when the first request fails, so test the model to verify it works.
Test it
In Chat: select Open chat in the sidebar, pick your model and send a message.
From code:
-
Open the model and copy its full API model id. The platform puts your tenant's name in front of the id you entered, so
gpt-4obecomes something likeacme/gpt-4o. -
On the same page, select Create API key. It opens the key form with this model already granted.
-
Copy the API URL from the bottom of the sidebar, then call the model:
curl "<API URL>/v1/chat/completions" \-H "Authorization: Bearer <your platform API key>" \-H "Content-Type: application/json" \-d '{"model": "acme/gpt-4o", "messages": [{"role": "user", "content": "Hello"}]}'Use your platform API key, not the Azure key.
Test from code even if Chat works. Chat doesn't use the API version, so it works without one. Calls to Chat Completions, Embeddings and Audio transcriptions fail when API version is empty. To fix it, open the model, edit its provider connection and enter an API version.
Good to know
- Which APIs work: Responses, Chat Completions, Embeddings and Audio transcriptions. The Messages API also works, but it uses Anthropic's format and the platform translates it.
- The API version is only used for Chat Completions, Embeddings and Audio transcriptions. Responses and Messages
calls go to Azure's
/openai/v1/responseswithout it. - Azure bills usage to your Azure subscription. The platform also counts the tokens in your tenant's usage.
- Prompts are processed in your Azure resource's region. Choose a region that fits your organization's data policy.
- Azure rate limits apply. Your deployment's tokens-per-minute quota limits how much traffic it can handle.
Troubleshooting
| Problem | What to check |
|---|---|
Requests fail with "deployment not found" or a 404 from Azure | Provider model ID matches the Azure deployment name exactly, including upper and lower case. It can't be edited, so connect the model again with the right name. |
| Every request fails with an authentication error | The API key belongs to the same Azure resource as the Base URL. |
| Chat works, but calls from code to Chat Completions, Embeddings or Audio transcriptions fail | API version is set, and your Azure resource supports it. If it's empty, edit the model's provider connection and enter one. |
Every request fails with a connection or 404 error | Base URL is the plain endpoint, with no path, query or trailing /. |
| Connect model fails because the id is taken | Another model, alias or preset agent already uses that API model id. Choose a unique one. |
| The model works for you but others can't see it | Share it on the model's Users tab. |
| The model is missing from Chat | Model type is Chat, and the model is shared with you. |
A call from code returns 404 with model "..." not found or not ready | Set model to the full API model id, with your tenant's name in front. |
| A call from code is refused with a permission error | The API key is granted this model. Create one from the model's page with Create API key. |