Skip to main content

Prerequisites

Before configuring Claude Code with Microsoft Foundry, ensure you have:
  • An Azure subscription with access to Microsoft Foundry
  • RBAC permissions to create Microsoft Foundry resources and deployments
  • Azure CLI installed and configured (optional - only needed if you don’t have another mechanism for getting credentials)
If you are deploying Claude Code to multiple users, pin your model versions before rolling out.

Setup

1. Provision Microsoft Foundry resource

First, create a Claude resource in Azure:
  1. Navigate to the Microsoft Foundry portal
  2. Create a new resource, noting your resource name
  3. Create deployments for the Claude models, noting the deployment name you give each; you’ll set these names as the model variables in step 4:
    • Claude Opus
    • Claude Sonnet
    • Claude Haiku
    When you configure a deployment, you also choose its hosting option, which determines whether inference runs on Azure or on Anthropic infrastructure.

2. Configure Azure credentials

Claude Code supports three authentication methods for Microsoft Foundry. Choose the method that best fits your security requirements. Option A: API key authentication
  1. Navigate to your resource in the Microsoft Foundry portal
  2. Go to the Endpoints and keys section
  3. Copy API Key
  4. Set the environment variable, replacing your-azure-api-key with the key you copied:
Option B: Microsoft Entra ID authentication When neither ANTHROPIC_FOUNDRY_API_KEY nor ANTHROPIC_FOUNDRY_AUTH_TOKEN is set, Claude Code automatically uses the Azure SDK default credential chain. This supports a variety of methods for authenticating local and remote workloads. On local environments, you commonly may use the Azure CLI:
Option C: Bearer token authentication Claude Code sends the value of ANTHROPIC_FOUNDRY_AUTH_TOKEN on every request as the Authorization: Bearer header. Use this option when another process, such as a host application or a sign-in script, has already obtained an access token for you. Requires Claude Code v2.1.203 or later. Set the variable to a bearer token that Microsoft Entra ID issued for your resource:
ANTHROPIC_FOUNDRY_AUTH_TOKEN takes precedence over ANTHROPIC_FOUNDRY_API_KEY and over the default credential chain.
When using Microsoft Foundry, the /logout command is unavailable since authentication is handled through Azure credentials.

3. Configure Claude Code

Set the following environment variables to enable Microsoft Foundry:

4. Pin model versions

Pin specific model versions for every deployment. Without pinning, model aliases such as sonnet and opus resolve to Claude Code’s built-in default for Microsoft Foundry, which can lag the newest release and may not yet be available in your account. Microsoft Foundry has no startup model check, so requests fail when the default is unavailable. When you create Azure deployments, select a specific model version rather than “auto-update to latest.”
Set the model variables to match the deployment names you created in step 1. Without ANTHROPIC_DEFAULT_OPUS_MODEL, the opus alias on Microsoft Foundry resolves to Opus 4.6. Set it to the ID of a newer Opus model, such as Opus 4.8: