AzureOpenAI class.
The Azure API shape differs from the core OpenAI API shape, which means that the static types for responses and parameters won’t always be correct.
Basic Usage
With API Key
With Azure Deployment
You can specify anazure_deployment to include it in the base URL:
Authentication Methods
Azure OpenAI supports multiple authentication methods:API Key
The simplest method uses an API key:Azure Active Directory (Recommended)
For production deployments, use Azure AD authentication:Azure AD Token (Static)
You can also pass a static Azure AD token:Configuration
Required Parameters
The following parameters are required:api_version: Azure API version (orOPENAI_API_VERSIONenvironment variable)azure_endpointORbase_url: Your Azure endpoint (orAZURE_OPENAI_ENDPOINTenvironment variable)
Environment Variables
The SDK automatically reads these environment variables:Available Options
All options from the baseOpenAI client are available, plus:
Async Client
UseAsyncAzureOpenAI for async operations:
API Version
Azure OpenAI uses versioned APIs. See the Azure REST API versioning docs for available versions. Currently recommended version:2023-07-01-preview
Deployment Names
In Azure OpenAI, you deploy models with custom deployment names. Use your deployment name in themodel parameter: