Skip to main content
You can find information about Azure OpenAI’s latest models and their costs, context windows, and supported input types in the Azure docs.
Azure OpenAI vs OpenAIAzure OpenAI refers to OpenAI models hosted on the Microsoft Azure platform. OpenAI also provides its own model APIs. To access OpenAI services directly, use the ChatOpenAI integration.
Azure OpenAI v1 APIAzure OpenAI’s v1 API (Generally Available as of August 2025) allows you to use ChatOpenAI directly with Azure endpoints. This provides a unified interface and native support for Microsoft Entra ID authentication with automatic token refresh.See the ChatOpenAI Azure section for details on using ChatOpenAI with Azure’s v1 API.AzureChatOpenAI is still currently supported for traditional Azure OpenAI API versions and scenarios requiring Azure-specific configurations, but we recommend using ChatOpenAI or the AzureAIChatCompletionsModel in LangChain Azure AI going forward.
AzureChatOpenAI shares the same underlying base implementation as ChatOpenAI, which interfaces with OpenAI services directly.This page serves as a quickstart for authenticating and connecting your Azure OpenAI service to a LangChain chat model.Visit the ChatOpenAI docs for details on available features, or head to the AzureChatOpenAI API reference.
API ReferenceFor detailed documentation of all features and configuration options, head to the AzureChatOpenAI API reference.

Overview

Integration details

Model features

Setup

To access AzureChatOpenAI models you’ll need to create an Azure account, create a deployment of an Azure OpenAI model, get the name and endpoint for your deployment, get an Azure OpenAI API key, and install the langchain-openai integration package.

Installation

Credentials

Head to the Azure docs to create your deployment and generate an API key. Once you’ve done this set the AZURE_OPENAI_API_KEY and AZURE_OPENAI_ENDPOINT environment variables:
To enable automated tracing of your model calls, set your LangSmith API key:

Instantiation

Now we can instantiate our model object and generate chat completions.

Invocation

Streaming usage metadata

OpenAI’s Chat Completions API does not stream token usage statistics by default (see API reference here). To recover token counts when streaming with ChatOpenAI or AzureChatOpenAI, set stream_usage=True as an initialization parameter or on invocation:

Specifying model version

Azure OpenAI responses contain model_name response metadata property, which is name of the model used to generate the response. However unlike native OpenAI responses, it does not contain the specific version of the model, which is set on the deployment in Azure. e.g. it does not distinguish between gpt-35-turbo-0125 and gpt-35-turbo-0301. This makes it tricky to know which version of the model was used to generate the response, which as result can lead to e.g. wrong total cost calculation with OpenAICallbackHandler. To solve this problem, you can pass model_version parameter to AzureChatOpenAI class, which will be added to the model name in the llm output. This way you can easily distinguish between different versions of the model.

API reference

For detailed documentation of all features and configuration options, head to the AzureChatOpenAI API reference.