#!/usr/bin/env python3 # STATUS: UNVERIFIED — no cloud credentials in this atlas; snippet follows official docs verbatim-ish # Source: https://platform.claude.com/docs/en/build-with-claude/claude-in-microsoft-foundry (retrieved 2026-09-18) # Install: pip install -U anthropic (Foundry support is in the base package; pip install azure-identity for Entra ID) # Env (read automatically by the SDK): ANTHROPIC_FOUNDRY_API_KEY, ANTHROPIC_FOUNDRY_RESOURCE (or ANTHROPIC_FOUNDRY_BASE_URL). import os from anthropic import AnthropicFoundry # API-key auth. Endpoint: https://{resource}.services.ai.azure.com/anthropic/v1/* client = AnthropicFoundry( api_key=os.environ.get("ANTHROPIC_FOUNDRY_API_KEY"), resource=os.environ.get("ANTHROPIC_FOUNDRY_RESOURCE"), ) message = client.messages.create( model="claude-haiku-4-5", # default deployment name for Haiku 4.5 (deployment names are what you send) max_tokens=8, messages=[{"role": "user", "content": "Reply with OK."}], ) print(next(block.text for block in message.content if block.type == "text")) # Entra ID alternative (not run here): # from azure.identity import DefaultAzureCredential, get_bearer_token_provider # provider = get_bearer_token_provider(DefaultAzureCredential(), "https://ai.azure.com/.default") # client = AnthropicFoundry(resource=os.environ["ANTHROPIC_FOUNDRY_RESOURCE"], azure_ad_token_provider=provider)