Skip to content

xomicsdatascience/ClaudeCode_with_Azure

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

Setting Up Claude Code with Azure (Microsoft Foundry)

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.

Prerequisites

  • 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

Summary

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.

Azure Model

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.

Environment Variables

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.

Authentication Methods

Claude Code supports two authentication methods for Microsoft Foundry:

Option A: API Key Authentication

  1. Navigate to your resource in the Microsoft Foundry portal
  2. Obtain your API key. Save it to a text file in a secure location on your computer. Note the path.
  3. 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.

Option B: Microsoft Entra ID Authentication

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 login

Endpoint Format

Both authentication methods use Azure-hosted endpoints in the format:

https://{resource}.services.ai.azure.com/anthropic/v1/*

Claude Code

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).

VS Code Extension Configuration

If using the Claude Code VS Code extension:

  1. Open VS Code settings (Ctrl+, or Cmd+,)
  2. Search for "Claude Code: Environment Variables"
  3. Click "Edit in settings.json"
  4. 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"
  }
}

Required Azure Permissions

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.

Authentication Error

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.

Deployment Not Found

Ensure your Azure resource has the Claude model deployment configured and that the deployment name matches what Claude Code expects.

Alternative: Azure Databricks with LiteLLM

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.

References

About

Instructions for getting Claude Code to work using models deployed on Azure.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published