Edit

Deploy and use Claude models in Microsoft Foundry (preview)

Anthropic's Claude models bring advanced conversational AI capabilities to Microsoft Foundry, enabling you to build intelligent applications with state-of-the-art language understanding and generation. Claude models excel at complex reasoning, code generation, and multimodal tasks including image analysis.

In this article, you learn how to:

  • Deploy Claude models in Microsoft Foundry
  • Authenticate by using Microsoft Entra ID or API keys
  • Call the Claude Messages API from Python, JavaScript, or REST

For the full list of available Claude models, capabilities, quotas, and billing, see Claude models in Microsoft Foundry.

Prerequisites

Subscription type and region support

To use Claude models in Microsoft Foundry, you must have a paid Azure subscription with a billing account in a country or region where Anthropic offers the models for purchase. For a list of common subscription-related errors, see Common error messages and solutions. The following subscription types are currently not supported:

  • Enterprise Accounts located in South Korea
  • Cloud Solution Provider subscriptions
  • Azure subscriptions that don't have an active pay-as-you-go billing method (for example, student, free trial, or startup credit–based accounts)
  • Sponsored subscriptions that only use Azure credits. Note: If you have an account with a credit card on file, the credit card will be charged instead of Azure Credits.

For a list of supported regions, see supported geographic locations. Note that, Anthropic's "Supported Regions Policy" may apply for the availability in your region, check supported regions for details.

Use the Claude on Foundry starter kit

To get started with Claude on Foundry quickly, use the Claude on Foundry starter kit. The starter kit uses a single azd up command to provision a Foundry account, project, and your chosen Claude model deployments by using either Bicep or Terraform. It then wires the Anthropic SDK and the Claude Code CLI to call your deployment over Microsoft Entra ID, with no API keys to manage.

Deploy Claude models

Claude models in Foundry are available for global standard deployment. To deploy a Claude model, follow the instructions in Deploy Microsoft Foundry Models in the Foundry portal.

After deployment, use the Foundry playground to interactively test the model.

Call the Claude Messages API

After you deploy a Claude model, interact with it to generate text responses:

  • Use the Anthropic SDKs and the following Claude APIs:

    • Messages API: Send a structured list of input messages with text or image content. The model generates the next message in the conversation.
    • Token Count API: Count the number of tokens in a message.
    • Files API: Upload and manage files for use with the Claude API without re-uploading content with each request.
    • Skills API: Create custom skills for Claude AI.

Send messages with authentication

The following examples show how to send requests to Claude Sonnet 4.6 using Microsoft Entra ID or API key authentication. To work with your deployed model, you need:

  • Your base URL, which is of the form https://<resource name>.services.ai.azure.com/anthropic.
  • Your target URI from your deployment details, which is of the form https://<resource name>.services.ai.azure.com/anthropic/v1/messages.
  • Microsoft Entra ID for keyless authentication or your deployment's API key for API authentication.
  • Deployment name you chose during deployment creation. This name can be different from the model ID.

For advanced features and capabilities of Claude models, see Claude models in Microsoft Foundry.

Use Microsoft Entra ID authentication

For Messages API endpoints, use your base URL with Microsoft Entra ID authentication.

  1. Install the Azure Identity client library: Install this library to use the DefaultAzureCredential. Authorization is easiest when you use DefaultAzureCredential because it finds the best credential to use in its running environment.

    pip install azure-identity
    

    Set the values of the client ID, tenant ID, and client secret of the Microsoft Entra ID application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.

    export AZURE_CLIENT_ID="<AZURE_CLIENT_ID>"
    export AZURE_TENANT_ID="<AZURE_TENANT_ID>"
    export AZURE_CLIENT_SECRET="<AZURE_CLIENT_SECRET>"
    
  2. Install dependencies: Install the Anthropic SDK by using pip (requires Python 3.8 or later).

    pip install -U "anthropic"
    
  3. Run a basic code sample to complete the following tasks:

    1. Create a client with the Anthropic SDK, using Microsoft Entra ID authentication.
    2. Make a basic call to the Messages API. The call is synchronous.
    from anthropic import AnthropicFoundry
    from azure.identity import DefaultAzureCredential, get_bearer_token_provider
    
    baseURL = "https://<resource-name>.services.ai.azure.com/anthropic" # Your base URL. Replace <resource-name> with your resource name
    deploymentName = "claude-sonnet-4-6" # Replace with your deployment name
    
    # Create token provider for Entra ID authentication
    tokenProvider = get_bearer_token_provider(
        DefaultAzureCredential(), "https://ai.azure.com/.default"
    )
    
    # Create client with Entra ID authentication
    client = AnthropicFoundry(
        azure_ad_token_provider=tokenProvider,
        base_url=baseURL
    )
    
    # Send request
    message = client.messages.create(
        model=deploymentName,
        messages=[
            {"role": "user", "content": "What are 3 things to visit in Seattle?"}
        ],
        max_tokens=1048,
        temperature=1,
        thinking={"type":"adaptive"},
        output_config={"effort": "max"},
        stream=False
    )
    
    print(message.content)
    

    Expected output: A JSON response containing the model's text completion with three Seattle recommendations.

    Reference: Anthropic Client SDK, DefaultAzureCredential

Use API key authentication

Important

Claude Mythos 5 and Mythos Preview support Microsoft Entra ID authentication only.

For Messages API endpoints, use your base URL and API key to authenticate against the service.

  1. Install dependencies: Install the Anthropic SDK by using pip (requires Python 3.8 or later):

    pip install -U "anthropic"
    
  2. Run a basic code sample to complete the following tasks:

    1. Create a client with the Anthropic SDK by passing your API key to the SDK's configuration. This authentication method lets you interact seamlessly with the service.
    2. Make a basic call to the Messages API. The call is synchronous.
    from anthropic import AnthropicFoundry
    
    baseURL = "https://<resource-name>.services.ai.azure.com/anthropic" # Your base URL. Replace <resource-name> with your resource name
    deploymentName = "claude-sonnet-4-6" # Replace with your deployment name
    apiKey = "YOUR_API_KEY" # Replace YOUR_API_KEY with your API key
    
    # Create client with API key authentication
    client = AnthropicFoundry(
        api_key=apiKey,
        base_url=baseURL
    )
    
    # Send request
    message = client.messages.create(
        model=deploymentName,
        messages=[
            {"role": "user", "content": "What are 3 things to visit in Seattle?"}
        ],
        max_tokens=1048,
        temperature=1,
        thinking={"type":"adaptive"},
        output_config={"effort": "max"},
        stream=False
    )
    
    print(message.content)
    

    Expected output: A JSON response containing the model's text completion with three Seattle recommendations.

    Reference: Anthropic Client SDK

Troubleshooting

The following table lists common errors when you work with Claude models in Foundry and their solutions:

Error Cause Solution
401 Unauthorized Invalid or expired API key, or incorrect Entra ID token scope. Verify your API key is correct. For Entra ID, confirm you use scope https://ai.azure.com/.default.
403 Forbidden Insufficient permissions on the resource or subscription. Verify you have Contributor or Owner role on the resource group. For Entra ID, ensure the Cognitive Services User role is assigned.
404 Not Found Incorrect endpoint URL or deployment name. Confirm your base URL follows the pattern https://<resource-name>.services.ai.azure.com/anthropic and the deployment name matches your configuration.
429 Too Many Requests Rate limit exceeded for your subscription tier. Implement exponential backoff with retry logic. Consider reducing request frequency or requesting a quota increase.
Subscription eligibility error Your Azure subscription type or billing region isn't supported, or your subscription tier has a default quota of 0 for the model. Confirm your subscription has an active pay-as-you-go billing method and a supported billing country/region. See Subscription type and region support. For tier-specific default limits, see Quotas, rate limits, and regions.
Region not available Deployment attempted in an unsupported region. Deploy to East US2 or Sweden Central, the supported regions for Claude models.