Azure OpenAI supported models
Quick answer
Azure OpenAI supports models such as
gpt-4o, gpt-4o-mini, gpt-4.1, and gpt-4.1-mini under custom deployment names. You must use your Azure deployment name when calling the API via the AzureOpenAI client. Model names differ from OpenAI’s public API and require specifying the deployment name in model parameter.PREREQUISITES
Python 3.8+Azure OpenAI API keyAzure OpenAI endpoint URLpip install openai>=1.0
Setup
Install the official openai Python package version 1.0 or higher. Set environment variables for your Azure OpenAI API key and endpoint URL. Use the AzureOpenAI client from the openai package to authenticate.
pip install openai>=1.0 Step by step
Use your Azure OpenAI deployment name as the model parameter. The deployment name corresponds to the model you deployed in your Azure portal (e.g., gpt-4o-deployment). Below is a complete example to call the chat completion endpoint.
import os
from openai import AzureOpenAI
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"], # e.g., "gpt-4o-deployment"
messages=[{"role": "user", "content": "Hello from Azure OpenAI!"}]
)
print(response.choices[0].message.content) output
Hello from Azure OpenAI! How can I assist you today?
Common variations
You can use different deployment names for other supported models like gpt-4o-mini or gpt-4.1. Streaming responses are supported by passing stream=True to chat.completions.create(). Async usage requires an async client or wrapper. Always use the deployment name, not the raw model name.
import asyncio
import os
from openai import AzureOpenAI
async def main():
client = AzureOpenAI(
api_key=os.environ["AZURE_OPENAI_API_KEY"],
azure_endpoint=os.environ["AZURE_OPENAI_ENDPOINT"],
api_version="2024-02-01"
)
response = await client.chat.completions.acreate(
model=os.environ["AZURE_OPENAI_DEPLOYMENT"],
messages=[{"role": "user", "content": "Stream a response from Azure OpenAI."}],
stream=True
)
async for chunk in response:
print(chunk.choices[0].delta.get("content", ""), end="", flush=True)
asyncio.run(main()) output
Streaming response text appears here in chunks...
Troubleshooting
- If you get a
ModelNotFounderror, verify your deployment name matches exactly the one in the Azure portal. - Ensure your
AZURE_OPENAI_ENDPOINTincludes the full URL, e.g.,https://your-resource-name.openai.azure.com/. - Check that your API key has permissions for the Azure OpenAI resource.
Key Takeaways
- Always use your Azure deployment name as the
modelparameter in API calls. - Supported models include
gpt-4o,gpt-4o-mini,gpt-4.1, andgpt-4.1-miniunder custom deployments. - Use the
AzureOpenAIclient withazure_endpointandapi_versionparameters for authentication. - Streaming and async calls are supported with the same deployment name model parameter.
- Verify environment variables and deployment names carefully to avoid common errors.