Skip to main content

Overview

ChatAzureOpenAI provides integration with Azure OpenAI Service, supporting GPT-4, GPT-5, and other OpenAI models through Microsoft Azure’s enterprise-grade infrastructure. It includes support for both Chat Completions API and the newer Responses API.

Basic Usage

Configuration

Required Parameters

str
required
Azure OpenAI model deployment name. Common options:
  • gpt-4o: Latest GPT-4 optimized model
  • gpt-4-turbo: High performance GPT-4
  • gpt-4.1-mini: Fast and cost-effective
  • gpt-5, gpt-5-mini, gpt-5-nano: Next generation models
  • gpt-5.1-codex-mini, gpt-5.1-codex-max: Codex models (require Responses API)

Azure-Specific Parameters

str
default:"None"
Azure OpenAI API key. Falls back to AZURE_OPENAI_KEY or AZURE_OPENAI_API_KEY environment variable.
Get your API key from Azure Portal
str
default:"None"
Your Azure OpenAI resource endpoint. Falls back to AZURE_OPENAI_ENDPOINT environment variable.Example: https://your-resource.openai.azure.com
str
default:"None"
Your Azure OpenAI deployment name. Falls back to AZURE_OPENAI_DEPLOYMENT environment variable.
str
default:"2024-12-01-preview"
Azure OpenAI API version. Use 2025-03-01-preview or later for Responses API support.
str
default:"None"
Azure Active Directory token for authentication (alternative to API key).
Any
default:"None"
Token provider function for dynamic Azure AD authentication.
str
default:"None"
Custom base URL (alternative to azure_endpoint).

Model Parameters

float
default:"0.2"
Sampling temperature (0.0 to 2.0). Lower values make output more deterministic.
float
default:"0.3"
Penalty for token frequency (-2.0 to 2.0).
str
default:"low"
Reasoning effort for reasoning models. Options: low, medium, high.
int
default:"None"
Random seed for deterministic output.
str
default:"None"
Service tier: auto, default, flex, priority, or scale.
float
default:"None"
Nucleus sampling parameter (0.0 to 1.0).
int
default:"4096"
Maximum tokens in the completion.

Client Parameters

str
default:"None"
Azure OpenAI organization ID.
float
default:"None"
Request timeout in seconds.
int
default:"5"
Maximum number of retries for failed requests.
dict
default:"None"
Additional headers to include in all requests.
dict
default:"None"
Additional query parameters for all requests.
httpx.AsyncClient
default:"None"
Custom async HTTP client.

Responses API Parameters

bool | str
default:"auto"
Whether to use the Responses API instead of Chat Completions API.
  • True: Always use Responses API
  • False: Always use Chat Completions API
  • "auto": Automatically detect based on model (default)
Responses API is required for models like gpt-5.1-codex-mini and computer-use-preview.

Advanced Parameters

bool
default:"False"
Add JSON schema to system prompt for better structured output.
bool
default:"False"
Disable forced structured output even when output_format is provided.
bool
default:"False"
Remove minItems from JSON schema for provider compatibility.
bool
default:"False"
Remove default values from JSON schema.

Advanced Usage

With Azure AD Authentication

Using Responses API

The Responses API is automatically used for models: gpt-5.1-codex-mini, gpt-5.1-codex-max, gpt-5-codex, and computer-use-preview.

Structured Output

With Custom Headers

Environment Setup

.env

Error Handling

Properties

provider

Returns the provider name: "azure"

name

Returns the model name.

Methods

get_client()

Returns an AsyncAzureOpenAI client instance.

ainvoke()

Asynchronously invoke the model with messages. Automatically routes between Chat Completions API and Responses API based on model.

Parameters

  • messages (list[BaseMessage]): List of messages
  • output_format (type[T] | None): Optional Pydantic model for structured output

Returns

ChatInvokeCompletion[T] | ChatInvokeCompletion[str] with:
  • completion: Response content
  • usage: Token usage (includes prompt_cached_tokens when available)
  • stop_reason: Finish reason

API Differences

Chat Completions API vs Responses API

Azure-Specific Features

Enterprise Security

  • Azure AD authentication support
  • Private network access with VNet
  • Managed identity integration
  • Compliance certifications

Deployment Options

  • Dedicated model deployments
  • Custom model fine-tuning
  • Multi-region availability
  • Provisioned throughput units (PTU)

Monitoring and Logging

  • Azure Monitor integration
  • Request tracing
  • Usage analytics
  • Cost management