Skip to main content
This will help you get started with AzureAIOpenAIApiChatModel chat models. The AzureAIOpenAIApiChatModel class uses the OpenAI-compatible API available in Azure AI Foundry. AI Foundry has several chat models, including AzureOpenAI, Cohere, Llama, Phi-3/4, and DeepSeek-R1, among others. You can find information about their latest models and their costs, context windows, and supported input types in the Azure docs. Microsoft Foundry provides project-level access to models and Azure services. Use AzureAIOpenAIApiChatModel from langchain-azure-ai when your application uses a Foundry project, Azure credentials, or other Foundry capabilities.

Overview

Integration details

Model features

Setup

To access AzureAIOpenAIApiChatModel models, you’ll need to create an Azure account, get an API key, and install the langchain-azure-ai integration package.

Credentials

Head to the Azure docs to see how to create your deployment and generate an API key. Once your model is deployed, you click the ‘get endpoint’ button in AI Foundry. This will show you your endpoint and api key. Once you’ve done this, set the environment variables:
If you want to get automated tracing of your model calls, you can also set your LangSmith API key:

Installation

The LangChain AzureAIOpenAIApiChatModel integration lives in the langchain-azure-ai package:

Instantiation

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

Invocation

Anthropic Claude models

Use AzureAIAnthropicChatModel to call Claude models deployed in Microsoft Foundry through the /anthropic endpoint with Microsoft Entra ID or API key authentication.
When both project_endpoint and endpoint are omitted, AzureAIAnthropicChatModel resolves AZURE_AI_PROJECT_ENDPOINT, then FOUNDRY_PROJECT_ENDPOINT, as the project endpoint. If neither is set, it falls back to ANTHROPIC_FOUNDRY_RESOURCE as a bare Foundry resource name (for example, my-resource); pass full URLs via endpoint. When credential is omitted, AzureAIAnthropicChatModel defaults to DefaultAzureCredential() and ignores OPENAI_API_KEY and ANTHROPIC_API_KEY. For API key authentication, pass credential="<your-api-key>" with endpoint or project_endpoint. Do not use init_chat_model("azure_ai:...") as it resolves to AzureAIOpenAIApiChatModel, not AzureAIAnthropicChatModel.