Azure AI Chat Completions model using the OpenAI-compatible API.
Azure AI chat model using the OpenAI-compatible API.
This class wraps :class:langchain_openai.ChatOpenAI and adds support
for the project-endpoint pattern available in Azure AI Foundry, in addition
to the classic endpoint + API-key style used by OpenAI-compatible services.
Use AzureAIOpenAIApiChatModel with any Foundry model compatible with
OpenAI APIs (e.g. gpt-5, Mistral, Cohere.) to get the benefits of
unified authentication, single configuration, and seamless integration
with other Azure services.
By default, this class uses Responses API. Set use_responses_api=False
to disable it and use the standard chat completions API instead.
Project-endpoint pattern (recommended for Azure AI Foundry):
from langchain_azure_ai.chat_models import AzureAIOpenAIApiChatModel
from azure.identity import DefaultAzureCredential
model = AzureAIOpenAIApiChatModel(
project_endpoint=(
"https://resource.services.ai.azure.com/api/projects/my-project"
),
credential=DefaultAzureCredential(),
model="gpt-4o",
)
Parameter model refers to the model deployment name in Azure AI Foundry,
which may differ from the base model name (e.g. "gpt-4o") depending on how
the deployment was configured.
If project_endpoint is omitted the value of the
AZURE_AI_PROJECT_ENDPOINT environment variable is used.
Direct endpoint + API-key pattern:
from langchain_azure_ai.chat_models import AzureAIOpenAIApiChatModel
model = AzureAIOpenAIApiChatModel(
endpoint="https://resource.services.ai.azure.com/openai/v1",
credential="your-api-key",
model="gpt-4o",
)
Use api_version parameter to specify the API version when using a
direct endpoint, or rely on the automatic API version detection
when using a project endpoint.
from langchain_azure_ai.chat_models import AzureAIOpenAIApiChatModel
model = AzureAIOpenAIApiChatModel(
endpoint="https://resource.services.ai.azure.com/openai/v1",
credential="your-api-key",
model="gpt-4o",
api_version="2025-05-12"
)
Environment variables:
The following environment variables are recognised as fallbacks when the corresponding constructor parameters are not provided:
AZURE_AI_PROJECT_ENDPOINT ā used as project_endpoint.AZURE_AI_OPENAI_ENDPOINT ā direct OpenAI-compatible endpoint
(e.g. https://<resource>.services.ai.azure.com/openai/v1).
Used as endpoint verbatim (no path is appended).AZURE_OPENAI_ENDPOINT ā root Azure OpenAI endpoint (e.g.
https://<resource>.services.ai.azure.com). /openai/v1 is
appended automatically and the result is treated as endpoint.AZURE_OPENAI_DEPLOYMENT_NAME ā model deployment name (model).AZURE_OPENAI_API_VERSION ā API version passed as the
api-version query parameter on every request.Resolution priority (highest ā lowest):
AZURE_AI_PROJECT_ENDPOINT environment variable.AZURE_AI_OPENAI_ENDPOINT environment variable.AZURE_OPENAI_ENDPOINT / AZURE_OPENAI_API_VERSION /
AZURE_OPENAI_DEPLOYMENT_NAME environment variables.AZURE_AI_PROJECT_ENDPOINT, AZURE_AI_OPENAI_ENDPOINT, and
AZURE_OPENAI_ENDPOINT may all be set at the same time; the project
endpoint takes precedence, then AZURE_AI_OPENAI_ENDPOINT, then
AZURE_OPENAI_ENDPOINT. However, passing both project_endpoint
and endpoint as constructor parameters raises :class:ValueError.
All other keyword arguments accepted by
:class:langchain_openai.ChatOpenAI are forwarded as-is, so you
retain full control over temperature, max_tokens, streaming, etc.