Skip to main content

Overview

The AzureOpenAILLMClient provides integration with OpenAI models hosted on Azure, supporting both the native Azure OpenAI SDK and OpenAI’s v1 API compatibility endpoint.

Installation

The OpenAI SDK (which includes Azure support) is included by default.

Basic Usage

Constructor

AsyncAzureOpenAI | AsyncOpenAI
required
Pre-configured Azure OpenAI client. Must be either:
  • AsyncAzureOpenAI for native Azure SDK
  • AsyncOpenAI with Azure v1 API endpoint
LLMConfig | None
default:"None"
Configuration object. If None, creates default config.
int
default:"16384"
Maximum output tokens for responses.
str | None
default:"None"
Reasoning effort level for reasoning models (GPT-5, o1, o3). Options: 'minimal', 'low', 'medium', 'high'
str | None
default:"None"
Verbosity level for reasoning models. Options: 'low', 'medium', 'high'
Caching is not supported. The cache parameter in the base class is always False.

Azure SDK Setup

Option 2: AsyncOpenAI with Azure v1 Endpoint

Supported Models

All OpenAI models available on Azure are supported: Reasoning Models (via responses.parse):
  • gpt-5-* deployments
  • o1-* deployments
  • o3-* deployments
Standard Models (via chat.completions or beta.chat.completions.parse):
  • gpt-4o deployments
  • gpt-4-turbo deployments
  • gpt-4 deployments
  • gpt-3.5-turbo deployments
Use your Azure deployment name as the model parameter, not the base model name.

Structured Output Handling

The client automatically selects the appropriate API based on model type:

Reasoning Models (GPT-5, o1, o3)

Uses responses.parse API:

Standard Models (GPT-4o, etc.)

Uses beta.chat.completions.parse API:

Response Parsing

The client handles different response formats:

ParsedChatCompletion (Standard Models)

Responses.parse (Reasoning Models)

Reasoning Model Configuration

For GPT-5 and o-series deployments:
Reasoning parameters:
  • reasoning: 'minimal', 'low', 'medium', 'high'
  • verbosity: 'low', 'medium', 'high'
Reasoning models do not support temperature. The client automatically omits temperature for these models.

Error Handling

Refusals

Rate Limits

Automatic Retries

The client retries up to 2 times for:
  • Validation errors
  • JSON parsing errors
  • Transient API failures
Error context is appended for model self-correction:

Token Usage Tracking

Track token consumption across requests:

Model Detection

The client automatically detects reasoning models:
Behavior changes for reasoning models:
  • Uses responses.parse instead of beta.chat.completions.parse
  • Omits temperature parameter
  • Includes reasoning and verbosity options

Example: Complete Integration

Performance Tips

  1. Use appropriate deployment sizes: Deploy both large and small models
  2. Set reasonable max_tokens: Azure charges per token
  3. Monitor quotas: Azure has deployment-specific rate limits
  4. Use model_size parameter: Let Graphiti choose optimal deployment

Differences from OpenAIClient

Troubleshooting

Authentication Errors

Deployment Not Found

Rate Limiting