Azure OpenAI
Use OpenAI’s GPT-4o, GPT-4o-mini, o-series, and other models through Azure OpenAI Service. Same OpenAI capabilities, but authenticated with Azure credentials, billed through Azure, and deployed in your own Azure subscription with enterprise compliance.azureOpenai() uses the openai SDK’s built-in AzureOpenAI class. All OpenAI features — tool calling, streaming, JSON mode, vision, reasoning — work identically to the direct openai() provider.Setup
- Install
- Environment
The Azure OpenAI provider uses the same OpenAI SDK:
Factory
The model or deployment name. This is passed as the
model parameter to the API.Optional configuration. See Config below.
Supported Models
| Model | Description |
|---|---|
gpt-4o | Latest flagship model. Vision, audio, tool calling. |
gpt-4o-mini | Smaller, faster, cost-effective. |
gpt-4-turbo | High capability, larger context. |
o1-preview | Reasoning-optimized model. |
o3-mini | Fast reasoning model. |
Deploying models on Azure
Deploying models on Azure
You must create a deployment for each model in the Azure AI Studio portal. The deployment name becomes the
modelId (or you can use config.deployment). See Azure OpenAI docs for setup instructions.Config
Azure OpenAI API key. Falls back to
AZURE_OPENAI_API_KEY env var.Azure OpenAI endpoint URL. Falls back to
AZURE_OPENAI_ENDPOINT env var. Format: https://<resource-name>.openai.azure.comDeployment name. Falls back to
AZURE_OPENAI_DEPLOYMENT env var. If not set, modelId is used.Azure API version. Falls back to
AZURE_OPENAI_API_VERSION env var.Authentication Methods
Method 1: API Key (Recommended)
Method 2: Explicit Config
Tool Calling
Tool calling works identically to the direct OpenAI provider:Reasoning Models (o-series)
Azure OpenAI supports the o-series reasoning models with the samereasoning config:
Multi-Modal Support
Azure OpenAI GPT-4o supports images, audio, and files — same as the direct OpenAI provider:Full Example
Azure OpenAI vs Direct OpenAI
| Feature | openai() (Direct) | azureOpenai() (Azure) |
|---|---|---|
| Auth | OpenAI API key | Azure API key / Azure AD |
| Billing | OpenAI billing | Azure billing (consolidated) |
| Data residency | OpenAI servers | Your Azure region |
| VPC / Private | No | Yes (Private Endpoints) |
| Compliance | SOC2 | SOC2, HIPAA, FedRAMP, GDPR |
| Prompt Caching | Yes | Yes |
| Models | All OpenAI models | Models you deploy |
Environment Variables
| Variable | Description |
|---|---|
AZURE_OPENAI_API_KEY | Azure OpenAI API key |
AZURE_OPENAI_ENDPOINT | Azure OpenAI endpoint URL |
AZURE_OPENAI_DEPLOYMENT | Default deployment name |
AZURE_OPENAI_API_VERSION | API version (default: 2024-10-21) |
Cross-References
- OpenAI (Direct) — Direct OpenAI API with API key auth
- Azure AI Foundry — Open-source models (Phi, Llama, Mistral) on Azure
- Reasoning — O-series reasoning configuration
- Multi-Modal — Provider support matrix