SPB Git forge

spb/doc-api

Public
2commits 1branches 0releases
15.7 MBsize
maindefault branch
14 days agolast push
Python 88.3% TypeScript 7.6% Shell 4.1%
1.4 KB · 27 lines python
Raw Blame History
1#!/usr/bin/env python32# STATUS: UNVERIFIED — no cloud credentials in this atlas; snippet follows official docs verbatim-ish3# Source: https://platform.claude.com/docs/en/build-with-claude/claude-in-microsoft-foundry (retrieved 2026-09-18)4# Install: pip install -U anthropic   (Foundry support is in the base package; pip install azure-identity for Entra ID)5# Env (read automatically by the SDK): ANTHROPIC_FOUNDRY_API_KEY, ANTHROPIC_FOUNDRY_RESOURCE (or ANTHROPIC_FOUNDRY_BASE_URL).6import os78from anthropic import AnthropicFoundry910# API-key auth. Endpoint: https://{resource}.services.ai.azure.com/anthropic/v1/*11client = AnthropicFoundry(12    api_key=os.environ.get("ANTHROPIC_FOUNDRY_API_KEY"),13    resource=os.environ.get("ANTHROPIC_FOUNDRY_RESOURCE"),14)1516message = client.messages.create(17    model="claude-haiku-4-5",  # default deployment name for Haiku 4.5 (deployment names are what you send)18    max_tokens=8,19    messages=[{"role": "user", "content": "Reply with OK."}],20)21print(next(block.text for block in message.content if block.type == "text"))2223# Entra ID alternative (not run here):24#   from azure.identity import DefaultAzureCredential, get_bearer_token_provider25#   provider = get_bearer_token_provider(DefaultAzureCredential(), "https://ai.azure.com/.default")26#   client = AnthropicFoundry(resource=os.environ["ANTHROPIC_FOUNDRY_RESOURCE"], azure_ad_token_provider=provider)27