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:
az login
Option C: Bearer token authentication
{/* min-version: 2.1.203 */}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.
3. Configure Claude Code
Set the following environment variables to enable Microsoft Foundry:
# Enable Microsoft Foundry integrationexport CLAUDE_CODE_USE_FOUNDRY=1# Azure resource name (replace {resource} with your resource name)export ANTHROPIC_FOUNDRY_RESOURCE={resource}
# Or provide the full base URL:# export ANTHROPIC_FOUNDRY_BASE_URL=https://{resource}.services.ai.azure.com/anthropic
4. Pin model versions
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 Opus 4.8 ID to use the latest model:
Background tasks such as session title generation use the small/fast model, normally a Haiku-class model. On Microsoft Foundry, Claude Code defaults this to the primary model because not every account has a Haiku deployment. To use Haiku for background tasks, set ANTHROPIC_DEFAULT_HAIKU_MODEL to a Haiku deployment that is available in your account, as shown above.
Prompt caching is enabled automatically. To request a 1-hour cache TTL instead of the 5-minute default, set the following variable; cache writes with a 1-hour TTL are billed at a higher rate:
export ENABLE_PROMPT_CACHING_1H=1
5. Run Claude Code
With the environment variables set, start Claude Code from your project directory:
claude
Claude Code reads CLAUDE_CODE_USE_FOUNDRY and the other Microsoft Foundry variables from the environment and connects to your Azure resource on the first prompt. Unlike Amazon Bedrock and Google Cloud's Agent Platform, Microsoft Foundry has no interactive setup wizard, so the environment variables in steps 3 and 4 are the only configuration path.
To verify your setup, run /status inside Claude Code. The API provider line shows Microsoft Foundry, along with the resource name or base URL you configured.
Azure RBAC configuration
The Azure AI User and Cognitive Services User default roles include all required permissions for invoking Claude models.
For more restrictive permissions, create a custom role with the following:
If you receive an error "Failed to get token from azureADTokenProvider: ChainedTokenCredential authentication failed":
Configure Entra ID on the environment, or set ANTHROPIC_FOUNDRY_API_KEY.
If requests fail with repeated connection errors on the first prompt:
Check that ANTHROPIC_FOUNDRY_RESOURCE is set to your actual resource name rather than a placeholder. Claude Code builds the endpoint URL from this value, so an incorrect name points at a host that doesn't exist.
991. Navigate to the [Microsoft Foundry portal](https://ai.azure.com/)991. Navigate to the [Microsoft Foundry portal](https://ai.azure.com/)
1002. Create a new resource, noting your resource name1002. Create a new resource, noting your resource name
1013. Create deployments for the Claude models:1013. 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:
102 * Claude Opus102 * Claude Opus
103 * Claude Sonnet103 * Claude Sonnet
104 * Claude Haiku104 * Claude Haiku
1121. Navigate to your resource in the Microsoft Foundry portal1121. Navigate to your resource in the Microsoft Foundry portal
1132. Go to the **Endpoints and keys** section1132. Go to the **Endpoints and keys** section
1143. Copy **API Key**1143. Copy **API Key**
1154. Set the environment variable:1154. Set the environment variable, replacing `your-azure-api-key` with the key you copied:
196Claude Code reads `CLAUDE_CODE_USE_FOUNDRY` and the other Microsoft Foundry variables from the environment and connects to your Azure resource on the first prompt. Unlike Amazon Bedrock and Google Cloud's Agent Platform, Microsoft Foundry has no interactive setup wizard, so the environment variables in steps 3 and 4 are the only configuration path.196Claude Code reads `CLAUDE_CODE_USE_FOUNDRY` and the other Microsoft Foundry variables from the environment and connects to your Azure resource on the first prompt. Unlike Amazon Bedrock and Google Cloud's Agent Platform, Microsoft Foundry has no interactive setup wizard, so the environment variables in steps 3 and 4 are the only configuration path.
197197
198To verify your setup, run `/status` inside Claude Code. The API provider line shows `Microsoft Foundry`, along with the resource name or base URL you configured.
200The `Azure AI User` and `Cognitive Services User` default roles include all required permissions for invoking Claude models.202The `Azure AI User` and `Cognitive Services User` default roles include all required permissions for invoking Claude models.
221223
222* Configure Entra ID on the environment, or set `ANTHROPIC_FOUNDRY_API_KEY`.224* Configure Entra ID on the environment, or set `ANTHROPIC_FOUNDRY_API_KEY`.
223225
226If requests fail with repeated connection errors on the first prompt:
227
228* Check that `ANTHROPIC_FOUNDRY_RESOURCE` is set to your actual resource name rather than a placeholder. Claude Code builds the endpoint URL from this value, so an incorrect name points at a host that doesn't exist.