Installation
Azure OpenAI support is included in the base installation:Prerequisites
- Azure OpenAI Resource: Deployed in Azure Portal
- Model Deployments: Deploy your chosen models (e.g., gpt-4.1, text-embedding-3-small)
- API Keys: Retrieve from Azure Portal
Configuration
Environment Variables
.env
Basic Setup
Initialize Graphiti with Azure OpenAI:API Endpoint Format
Azure OpenAI uses a different endpoint structure than OpenAI: Correct format:- Use the v1 API endpoint (
/openai/v1/) - The standard
AsyncOpenAIclient works with Azure’s v1 API - Deployment names (not model names) are used in requests
Supported Models
Language Models
Deploy any of these models in Azure:- gpt-4.1: Latest GPT-4.1 model
- gpt-4.1-mini: Cost-effective mini model
- gpt-5-mini: Reasoning model with extended thinking
- gpt-5: Advanced reasoning model
- gpt-4o: Optimized GPT-4
- o1, o3: Specialized reasoning models
Embedding Models
- text-embedding-3-small: 1536 dimensions, cost-effective
- text-embedding-3-large: 3072 dimensions, highest quality
- text-embedding-ada-002: Legacy model
Model Deployment Names
In Azure, you create deployments with custom names for each model:Configuration Options
LLM Client
| Parameter | Type | Default | Description |
|---|---|---|---|
azure_client | AsyncOpenAI | Required | Azure OpenAI client instance |
config | LLMConfig | None | LLM configuration |
max_tokens | int | 8192 | Maximum tokens to generate |
reasoning | str | None | Reasoning effort for reasoning models |
verbosity | str | None | Verbosity for reasoning models |
Embedder Client
| Parameter | Type | Default | Description |
|---|---|---|---|
azure_client | AsyncOpenAI | Required | Azure OpenAI client instance |
model | str | "text-embedding-3-small" | Embedding deployment name |
Structured Output Support
Azure OpenAI supports structured outputs: For regular models (GPT-4o, etc.):- Uses
beta.chat.completions.parseAPI - Native Pydantic model validation
- Uses
responses.parseAPI - Supports reasoning and verbosity parameters
Reasoning Models Configuration
For GPT-5, o1, and o3 models:Complete Example
Error Handling
Graphiti automatically handles:- Rate Limit Errors: Exponential backoff and retry
- Validation Errors: Automatic retry with error context
- Refusal Errors: Content policy violations (no retry)
- API Errors: Network and service errors
When to Use Azure OpenAI
Choose Azure OpenAI if you:- Need enterprise compliance (SOC 2, HIPAA, etc.)
- Want regional data residency
- Require private network access (VNet integration)
- Need Azure Active Directory authentication
- Want cost management through Azure subscriptions
- Require Service Level Agreements (SLAs)
- Want access to the latest models immediately
- Don’t need enterprise compliance features
- Prefer simpler setup and pricing
Regional Availability
Azure OpenAI is available in multiple regions:- East US, East US 2
- West US, West US 2, West US 3
- North Europe, West Europe
- UK South
- And more…
Rate Limits and Quotas
Azure OpenAI uses Tokens Per Minute (TPM) quotas:.env
Security Best Practices
- Use Managed Identity: Avoid API keys in production
- Enable Private Endpoints: Restrict network access
- Configure Azure AD: Use role-based access control
- Enable Audit Logging: Track all API usage
- Rotate Keys: Regularly rotate API keys
Cost Management
- Use Provisioned Throughput: For predictable costs
- Monitor Usage: Set up Azure cost alerts
- Use Mini Models: Lower costs for simpler tasks
- Batch Operations: Reduce API calls
Monitoring and Logging
Enable Azure Monitor for:- Request/response logging
- Performance metrics
- Cost tracking
- Error analysis