Azure AI chat model using the Anthropic Messages API via Azure AI Foundry.
Azure AI chat model using the Anthropic Messages API.
Wraps :class:langchain_anthropic.ChatAnthropic so that Anthropic
Claude models hosted by Azure AI Foundry can be accessed through the
/anthropic endpoint with native Microsoft Entra ID authentication.
Authentication uses :class:anthropic.AnthropicFoundry (and
:class:anthropic.AsyncAnthropicFoundry) under the hood, which accepts
an azure_ad_token_provider callable that is invoked on every
request ā so bearer tokens are refreshed automatically and the model
can be used in long-running services without manual token rotation.
Microsoft Entra ID authentication (recommended):
from langchain_azure_ai.chat_models import AzureAIAnthropicChatModel
from azure.identity import DefaultAzureCredential
model = AzureAIAnthropicChatModel(
endpoint="https://<resource>.services.ai.azure.com",
credential=DefaultAzureCredential(),
model="claude-sonnet-4-20250514",
)
The endpoint is the Azure AI Foundry resource root; the
/anthropic path is appended automatically. You may also pass a URL
that already ends in /anthropic ā the result is the same.
Alternatively, supply a Foundry project endpoint and the resource root is derived automatically:
model = AzureAIAnthropicChatModel(
project_endpoint=(
"https://<resource>.services.ai.azure.com/api/projects/my-project"
),
credential=DefaultAzureCredential(),
model="claude-sonnet-4-20250514",
)
project_endpoint and endpoint are mutually exclusive.
API-key authentication:
model = AzureAIAnthropicChatModel(
endpoint="https://<resource>.services.ai.azure.com",
credential="your-api-key",
model="claude-sonnet-4-20250514",
)
Environment variables:
The following environment variables are checked when the corresponding constructor parameters are not provided:
AZURE_AI_PROJECT_ENDPOINT or FOUNDRY_PROJECT_ENDPOINT ā resolved
as project_endpoint. AZURE_AI_PROJECT_ENDPOINT takes precedence
when both are set.ANTHROPIC_FOUNDRY_RESOURCE ā resolved as endpoint when neither
endpoint nor project_endpoint is set (directly or via env var).
May be a bare resource name (e.g. my-resource) or a full URL. When
a bare name is provided the endpoint is synthesized as
https://<ANTHROPIC_FOUNDRY_RESOURCE>.services.ai.azure.com.
This is the same variable used by Claude Code when connected to
Azure AI Foundry, so models configured that way will work here without
any additional configuration.Resolution priority (highest to lowest):
project_endpoint, endpoint).AZURE_AI_PROJECT_ENDPOINT environment variable (or
FOUNDRY_PROJECT_ENDPOINT if the former is not set).ANTHROPIC_FOUNDRY_RESOURCE environment variable.All other keyword arguments accepted by
:class:langchain_anthropic.ChatAnthropic are forwarded as-is.