Get started with LangChain and LangGraph with Foundry
Learn how to use langchain-azure-ai as an entry point for LangChain and LangGraph apps with Microsoft Foundry capabilities.
Use the langchain-azure-ai package as the entry point for building LangChain and
LangGraph applications with Microsoft Foundry capabilities. This article gives
you a high-level map of the package so you can start quickly, then move to the
right deep-dive documentation for each capability.
The Foundry User role on the Foundry project (least-privilege role for
The Foundry RBAC roles were recently renamed. Foundry User, Foundry Owner, Foundry Account Owner, and Foundry Project Manager were previously named Azure AI User, Azure AI Owner, Azure AI Account Owner, and Azure AI Project Manager. You might still see the previous names in some places while the rename rolls out. The role IDs and core permissions are unchanged by the rename.
development). If you also create or manage resources, use Contributor or
Owner as needed. For details, see Role-based access control for
Microsoft Foundry.
Python 3.10 or later.
Azure CLI signed in (az login) so DefaultAzureCredential can authenticate.
This article mentions support for Microsoft Foundry (new), which uses version azure-ai-projects>=2.0.
If you are using Foundry classic, use langchain-azure-ai[v1] instead.
Many langchain-azure-ai classes support connecting through a Foundry project
endpoint. Set AZURE_AI_PROJECT_ENDPOINT once, then reuse it across supported
classes.
When you use project_endpoint, authentication uses Microsoft Entra ID and
Azure RBAC on the project.API keys are for direct service endpoints, such as /openai/v1.
You can also configure clients specifically. As an example, let’s see AzureAIOpenAIApiChatModel as a representative pattern:
import osfrom azure.identity import DefaultAzureCredentialfrom langchain_azure_ai.chat_models import AzureAIOpenAIApiChatModel# Option A: Use a Foundry project endpoint (Microsoft Entra ID required).model_from_project = AzureAIOpenAIApiChatModel( project_endpoint=os.environ["AZURE_AI_PROJECT_ENDPOINT"], credential=DefaultAzureCredential(), model="gpt-5.2",)# Option B: Use a service endpoint directly.model_from_endpoint = AzureAIOpenAIApiChatModel( endpoint=os.environ["OPENAI_BASE_URL"], credential=DefaultAzureCredential(), model="gpt-5.2",)# Option C: Use a different credential strategy.model_with_cli_credential = AzureAIOpenAIApiChatModel( endpoint=os.environ["OPENAI_BASE_URL"], credential="super-secret", model="gpt-5.2",)
What this snippet does: Shows the same model initialized from a Foundry
project endpoint or from a direct service endpoint, and shows how to swap
credentials.You can apply the same pattern to tools. For example,
AzureAIDocumentIntelligenceTool can use the project endpoint and
DefaultAzureCredential without extra configuration when
AZURE_AI_PROJECT_ENDPOINT is set:
from langchain_azure_ai.tools import AzureAIDocumentIntelligenceTooldocument_tool = AzureAIDocumentIntelligenceTool()
DefaultAzureCredential tries several Microsoft Entra ID credential sources in
order and uses the first one that works. Common sources are environment
variables, managed identity, developer tools, and Azure CLI.Use DefaultAzureCredential as the default for local development and deployed
workloads. If you need stricter control, replace it with a specific credential
such as AzureCliCredential for local-only development or
ManagedIdentityCredential for production workloads in Azure.The same project-endpoint pattern is also used by other classes.