This guide explains how to configure Claude Code to use Azure-hosted Claude models through Microsoft Foundry. It has been updated from this Microsoft Dev Blog to improve descriptions and use secure key-handling practices.
- Claude Code CLI installed
- An Azure account with access to Microsoft Foundry
- Azure resource with Claude models deployed
- (Optional) Azure CLI installed for Entra ID authentication
If you're looking for the list of commands to get started, here they are:
export CLAUDE_CODE_USE_FOUNDRY=1
export ANTHROPIC_FOUNDRY_API_KEY=$(cat azure.key)
export ANTHROPIC_FOUNDRY_RESOURCE={resource_name}Then start Claude Code and use /model to select a model that has been deployed on your Azure instance or use claude --model {model_name} when starting Claude Code.
Log in to the AI Foundry ai.azure.com and either verify that your preferred model is available (My assets -> Models + endpoints) or deploy it (Model catalog -> select model -> deploy). Note the model name: it will be used when launching Claude Code later.
Set the following environment variables to enable Microsoft Foundry:
export CLAUDE_CODE_USE_FOUNDRY=1
export ANTHROPIC_FOUNDRY_RESOURCE={resource}Replace {resource} with your Azure resource name. The resource name can be found by logging in to the AI foundry (ai.azure.com)[ai.azure.com],
and going to the overview. If you look in the Endpoints and keys box, you'll see a URL titled similar to "Microsoft Foundry project endpoint" or
"Azure OpenAI endpoint". The URL has the structure of https://{resource}.services.ai[...] or https://{resource}.openai.azure.com/. Set the value
of resource above to that.
Claude Code supports two authentication methods for Microsoft Foundry:
- Navigate to your resource in the Microsoft Foundry portal
- Obtain your API key. Save it to a text file in a secure location on your computer. Note the path.
- Set the environment variable:
export ANTHROPIC_FOUNDRY_API_KEY=$(cat path_to_file_containing_key)NOTE: Do not put the value of the key directly through the command line, as that would put the key value in your command history.
When ANTHROPIC_FOUNDRY_API_KEY is not set, Claude Code automatically uses the Azure SDK default credential chain. This supports various methods for authenticating local and remote workloads.
For local development, you can use the Azure CLI:
az loginBoth authentication methods use Azure-hosted endpoints in the format:
https://{resource}.services.ai.azure.com/anthropic/v1/*
Start Claude Code in the terminal. By default, Claude Code currently uses Sonnet by default, but you can use your deployed model by supplying the --model argument:
claude --model [model_name]where model_name is the name you gave to your Azure deployment (see "Azure Model" section at the beginning of this document).
If using the Claude Code VS Code extension:
- Open VS Code settings (
Ctrl+,orCmd+,) - Search for "Claude Code: Environment Variables"
- Click "Edit in settings.json"
- Add the required environment variables:
{
"claude-code.environmentVariables": {
"CLAUDE_CODE_USE_FOUNDRY": "1",
"ANTHROPIC_FOUNDRY_RESOURCE": "your-resource-name",
"ANTHROPIC_FOUNDRY_API_KEY": "your-api-key"
}
}The following Azure roles include all required permissions for invoking Claude models:
- Azure AI User
- Cognitive Services User
For more restrictive permissions, create a custom role with the Microsoft.CognitiveServices/accounts/providers/* data action.
If you receive an error like:
Failed to get token from azureADTokenProvider: ChainedTokenCredential authentication failed
Solution: Either configure Entra ID authentication on the environment, or set the ANTHROPIC_FOUNDRY_API_KEY environment variable.
Ensure your Azure resource has the Claude model deployment configured and that the deployment name matches what Claude Code expects.
For organizations using Azure Databricks, you can configure Claude Code to work with Claude models hosted on Azure Databricks using LiteLLM as a universal API proxy.
Create a .claude/settings.json in your project directory and configure ANTHROPIC_BASE_URL to point to your LiteLLM endpoint.