Loading...
    • 開發者指南
    • API 參考
    • MCP
    • 資源
    • 發行說明
    Search...
    ⌘K
    入門
    Claude 簡介快速開始
    模型與定價
    模型概覽選擇模型Claude 4.6 新功能遷移指南模型棄用定價
    使用 Claude 構建
    功能概覽使用 Messages API處理停止原因提示最佳實踐
    模型能力
    延伸思考自適應思考思考力度快速模式(研究預覽)結構化輸出引用串流訊息批次處理PDF 支援搜尋結果多語言支援嵌入視覺
    工具
    概覽如何實作工具使用網頁搜尋工具網頁擷取工具程式碼執行工具記憶工具Bash 工具電腦使用工具文字編輯器工具
    工具基礎設施
    工具搜尋程式化工具呼叫細粒度工具串流
    上下文管理
    上下文視窗壓縮上下文編輯提示快取Token 計數
    檔案與資源
    Files API
    Agent 技能
    概覽快速開始最佳實踐企業技能透過 API 使用技能
    Agent SDK
    概覽快速開始TypeScript SDKTypeScript V2(預覽)Python SDK遷移指南
    API 中的 MCP
    MCP 連接器遠端 MCP 伺服器
    第三方平台上的 Claude
    Amazon BedrockMicrosoft FoundryVertex AI
    提示工程
    概覽提示產生器使用提示範本提示改進器清晰直接使用範例(多範例提示)讓 Claude 思考(CoT)使用 XML 標籤賦予 Claude 角色(系統提示)串連複雜提示長上下文技巧延伸思考技巧
    測試與評估
    定義成功標準開發測試案例使用評估工具降低延遲
    強化防護機制
    減少幻覺提高輸出一致性防範越獄攻擊串流拒絕減少提示洩漏讓 Claude 保持角色
    管理與監控
    Admin API 概覽資料駐留工作區用量與成本 APIClaude Code Analytics API零資料保留
    Console
    Log in
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...

    Solutions

    • AI agents
    • Code modernization
    • Coding
    • Customer support
    • Education
    • Financial services
    • Government
    • Life sciences

    Partners

    • Amazon Bedrock
    • Google Cloud's Vertex AI

    Learn

    • Blog
    • Catalog
    • Courses
    • Use cases
    • Connectors
    • Customer stories
    • Engineering at Anthropic
    • Events
    • Powered by Claude
    • Service partners
    • Startups program

    Company

    • Anthropic
    • Careers
    • Economic Futures
    • Research
    • News
    • Responsible Scaling Policy
    • Security and compliance
    • Transparency

    Learn

    • Blog
    • Catalog
    • Courses
    • Use cases
    • Connectors
    • Customer stories
    • Engineering at Anthropic
    • Events
    • Powered by Claude
    • Service partners
    • Startups program

    Help and security

    • Availability
    • Status
    • Support
    • Discord

    Terms and policies

    • Privacy policy
    • Responsible disclosure policy
    • Terms of service: Commercial
    • Terms of service: Consumer
    • Usage policy
    第三方平台上的 Claude

    Microsoft Foundry 中的 Claude

    透過 Microsoft Foundry 使用 Azure 原生端點和驗證來存取 Claude 模型。

    本指南將引導您完成在 Foundry 中使用 Python、TypeScript 或直接 HTTP 請求設定和呼叫 Claude API 的過程。當您可以在 Foundry 中存取 Claude 時,您將透過 Azure 訂閱在 Microsoft Marketplace 中為 Claude 使用量付費,讓您在透過 Azure 訂閱管理成本的同時存取 Claude 的最新功能。

    區域可用性:在發布時,Claude 在 Foundry 資源中以 Global Standard 部署類型提供(US DataZone 即將推出)。Microsoft Marketplace 中 Claude 的定價使用 Anthropic 的標準 API 定價。請造訪定價頁面了解詳情。

    預覽

    在此預覽平台整合中,Claude 模型在 Anthropic 的基礎設施上運行。這是透過 Azure 進行計費和存取的商業整合。作為 Microsoft 的獨立處理者,透過 Microsoft Foundry 使用 Claude 的客戶受 Anthropic 的資料使用條款約束。Anthropic 持續提供其業界領先的安全和資料承諾,包括零資料保留可用性。

    先決條件

    在開始之前,請確保您具備:

    • 有效的 Azure 訂閱
    • Foundry 的存取權限
    • 已安裝 Azure CLI(選用,用於資源管理)

    安裝 SDK

    Anthropic 的用戶端 SDK 透過平台特定套件支援 Foundry。

    佈建

    Foundry 使用兩層階層結構:資源包含您的安全和計費配置,而部署是您透過 API 呼叫的模型實例。您將首先建立 Foundry 資源,然後在其中建立一個或多個 Claude 部署。

    佈建 Foundry 資源

    建立 Foundry 資源,這是在 Azure 中使用和管理服務所必需的。您可以按照這些說明建立 Foundry 資源。或者,您可以從建立 Foundry 專案開始,這涉及建立 Foundry 資源。

    要佈建您的資源:

    1. 導覽至 Foundry 入口網站
    2. 建立新的 Foundry 資源或選擇現有資源
    3. 使用 Azure 發行的 API 金鑰或 Entra ID 配置存取管理以進行角色型存取控制
    4. 選擇性地將資源配置為私人網路(Azure 虛擬網路)的一部分以增強安全性
    5. 記下您的資源名稱——您將在 API 端點中使用它作為 {resource}(例如 https://{resource}.services.ai.azure.com/anthropic/v1/*)

    建立 Foundry 部署

    建立資源後,部署 Claude 模型使其可用於 API 呼叫:

    1. 在 Foundry 入口網站中,導覽至您的資源
    2. 前往 Models + endpoints 並選擇 + Deploy model > Deploy base model
    3. 搜尋並選擇 Claude 模型(例如 claude-sonnet-4-6)
    4. 配置部署設定:
      • Deployment name:預設為模型 ID,但您可以自訂(例如 my-claude-deployment)。部署名稱在建立後無法更改。
      • Deployment type:選擇 Global Standard(推薦用於 Claude)
    5. 選擇 Deploy 並等待佈建完成
    6. 部署完成後,您可以在 Keys and Endpoint 下找到您的端點 URL 和金鑰

    您選擇的部署名稱將成為您在 API 請求的 model 參數中傳遞的值。您可以使用不同名稱建立同一模型的多個部署,以管理不同的配置或速率限制。

    驗證

    Foundry 上的 Claude 支援兩種驗證方法:API 金鑰和 Entra ID 權杖。兩種方法都使用格式為 https://{resource}.services.ai.azure.com/anthropic/v1/* 的 Azure 託管端點。

    API 金鑰驗證

    佈建 Foundry Claude 資源後,您可以從 Foundry 入口網站取得 API 金鑰:

    1. 在 Foundry 入口網站中導覽至您的資源
    2. 前往 Keys and Endpoint 區段
    3. 複製提供的 API 金鑰之一
    4. 在請求中使用 api-key 或 x-api-key 標頭,或將其提供給 SDK

    Python 和 TypeScript SDK 需要 API 金鑰以及資源名稱或基礎 URL。如果定義了以下環境變數,SDK 將自動從中讀取:

    • ANTHROPIC_FOUNDRY_API_KEY - 您的 API 金鑰
    • ANTHROPIC_FOUNDRY_RESOURCE - 您的資源名稱(例如 example-resource)
    • ANTHROPIC_FOUNDRY_BASE_URL - 資源名稱的替代方案;完整的基礎 URL(例如 https://example-resource.services.ai.azure.com/anthropic/)

    resource 和 base_url 參數是互斥的。請提供資源名稱(SDK 使用它來建構 URL 為 https://{resource}.services.ai.azure.com/anthropic/)或直接提供完整的基礎 URL。

    使用 API 金鑰的範例:

    import os
    from anthropic import AnthropicFoundry
    
    client = AnthropicFoundry(
        api_key=os.environ.get("ANTHROPIC_FOUNDRY_API_KEY"),
        resource="example-resource",  # your resource name
    )
    
    message = client.messages.create(
        model="claude-opus-4-6",
        max_tokens=1024,
        messages=[{"role": "user", "content": "Hello!"}],
    )
    print(message.content)

    請妥善保管您的 API 金鑰。切勿將其提交到版本控制或公開分享。任何擁有您 API 金鑰存取權的人都可以透過您的 Foundry 資源向 Claude 發出請求。

    Microsoft Entra 驗證

    為了增強安全性和集中式存取管理,您可以使用 Entra ID(前身為 Azure Active Directory)權杖:

    1. 為您的 Foundry 資源啟用 Entra 驗證
    2. 從 Entra ID 取得存取權杖
    3. 在 Authorization: Bearer {TOKEN} 標頭中使用該權杖

    使用 Entra ID 的範例:

    import os
    from anthropic import AnthropicFoundry
    from azure.identity import DefaultAzureCredential, get_bearer_token_provider
    
    # Get Azure Entra ID token using token provider pattern
    token_provider = get_bearer_token_provider(
        DefaultAzureCredential(), "https://cognitiveservices.azure.com/.default"
    )
    
    # Create client with Entra ID authentication
    client = AnthropicFoundry(
        resource="example-resource",  # your resource name
        azure_ad_token_provider=token_provider,  # Use token provider for Entra ID auth
    )
    
    # Make request
    message = client.messages.create(
        model="claude-opus-4-6",
        max_tokens=1024,
        messages=[{"role": "user", "content": "Hello!"}],
    )
    print(message.content)

    Azure Entra ID 驗證允許您使用 Azure RBAC 管理存取、與組織的身分管理整合,並避免手動管理 API 金鑰。

    關聯請求 ID

    Foundry 在 HTTP 回應標頭中包含請求識別碼,用於除錯和追蹤。聯繫支援時,請提供 request-id 和 apim-request-id 值,以幫助團隊在 Anthropic 和 Azure 系統中快速定位和調查您的請求。

    支援的功能

    Foundry 上的 Claude 支援 Claude 的大部分強大功能。您可以在概覽文件中找到目前支援的所有功能。

    不支援的功能

    • Admin API(/v1/organizations/* 端點)
    • Models API(/v1/models)
    • Message Batch API(/v1/messages/batches)

    API 回應

    Foundry 上 Claude 的 API 回應遵循標準的 Claude API 回應格式。這包括回應主體中的 usage 物件,它提供請求的詳細權杖消耗資訊。usage 物件在所有平台(第一方 API、Foundry、Amazon Bedrock 和 Google Vertex AI)上保持一致。

    有關 Foundry 特定的回應標頭詳情,請參閱關聯請求 ID 區段。

    API 模型 ID 和部署

    以下 Claude 模型可透過 Foundry 使用。最新一代模型(Opus 4.6、Sonnet 4.6 和 Haiku 4.5)提供最先進的功能:

    模型預設部署名稱
    Claude Opus 4.6claude-opus-4-6
    Claude Opus 4.5claude-opus-4-5
    Claude Sonnet 4.6claude-sonnet-4-6
    Claude Sonnet 4.5claude-sonnet-4-5
    Claude Opus 4.1claude-opus-4-1
    Claude Haiku 4.5claude-haiku-4-5

    預設情況下,部署名稱與上方顯示的模型 ID 相符。但是,您可以在 Foundry 入口網站中建立具有不同名稱的自訂部署,以管理不同的配置、版本或速率限制。在 API 請求中使用部署名稱(不一定是模型 ID)。

    監控和記錄

    Azure 透過標準 Azure 模式為您的 Claude 使用提供全面的監控和記錄功能:

    • Azure Monitor:追蹤 API 使用量、延遲和錯誤率
    • Azure Log Analytics:查詢和分析請求/回應日誌
    • Cost Management:監控和預測與 Claude 使用相關的成本

    Anthropic 建議至少以 30 天滾動方式記錄您的活動,以了解使用模式並調查任何潛在問題。

    Azure 的記錄服務在您的 Azure 訂閱中配置。啟用記錄不會讓 Microsoft 或 Anthropic 存取超出計費和服務運營所需的內容。

    疑難排解

    驗證錯誤

    錯誤:401 Unauthorized 或 Invalid API key

    • 解決方案:驗證您的 API 金鑰是否正確。您可以從 Azure 入口網站中 Claude 資源的 Keys and Endpoint 下取得新的 API 金鑰。
    • 解決方案:如果使用 Azure Entra ID,請確保您的存取權杖有效且未過期。權杖通常在 1 小時後過期。

    錯誤:403 Forbidden

    • 解決方案:您的 Azure 帳戶可能缺少必要的權限。確保您已被指派適當的 Azure RBAC 角色(例如「Cognitive Services OpenAI User」)。

    速率限制

    錯誤:429 Too Many Requests

    • 解決方案:您已超過速率限制。在應用程式中實作指數退避和重試邏輯。
    • 解決方案:考慮透過 Azure 入口網站或 Azure 支援請求增加速率限制。

    速率限制標頭

    Foundry 不在回應中包含 Anthropic 的標準速率限制標頭(anthropic-ratelimit-tokens-limit、anthropic-ratelimit-tokens-remaining、anthropic-ratelimit-tokens-reset、anthropic-ratelimit-input-tokens-limit、anthropic-ratelimit-input-tokens-remaining、anthropic-ratelimit-input-tokens-reset、anthropic-ratelimit-output-tokens-limit、anthropic-ratelimit-output-tokens-remaining 和 anthropic-ratelimit-output-tokens-reset)。請改用 Azure 的監控工具管理速率限制。

    模型和部署錯誤

    錯誤:Model not found 或 Deployment not found

    • 解決方案:驗證您使用的部署名稱是否正確。如果您尚未建立自訂部署,請使用預設模型 ID(例如 claude-sonnet-4-6)。
    • 解決方案:確保模型/部署在您的 Azure 區域中可用。

    錯誤:Invalid model parameter

    • 解決方案:model 參數應包含您的部署名稱,可在 Foundry 入口網站中自訂。驗證部署是否存在且配置正確。

    其他資源

    • Foundry 文件:ai.azure.com/catalog
    • Azure 定價:azure.microsoft.com/en-us/pricing
    • Anthropic 定價詳情:定價文件
    • 驗證指南:請參閱上方的驗證區段
    • Azure 入口網站:portal.azure.com

    Was this page helpful?

    • 安裝 SDK
    • 佈建 Foundry 資源
    • 建立 Foundry 部署
    • API 金鑰驗證
    • Microsoft Entra 驗證
    • 關聯請求 ID
    • API 回應
    • API 模型 ID 和部署