• 訊息
  • 託管代理
  • 管理
Search...
⌘K
組織
Admin API工作區
驗證
概覽工作負載身分聯合WIF 參考
監控
用量與成本 API速率限制 APIClaude Code 分析 API
資料與合規
資料駐留API 與資料保留
合規 API
概覽取得存取權活動動態對話、檔案與專案組織、使用者、角色與群組設計您的整合錯誤常見問題
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
  • 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
  • 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
管理/驗證

身份驗證

使用 API 金鑰或 Workload Identity Federation 向 Claude API 進行身份驗證。

Claude API 支援兩種驗證請求的方式:

方法憑證最適用於
API 金鑰在 x-api-key 標頭中傳送的長期有效 sk-ant-api... 密鑰本機開發、原型設計、指令碼,以及您可控制密鑰儲存的單一租戶伺服器
Workload Identity Federation從您的身份提供者的身份權杖交換而來的短期 bearer token雲端平台(AWS、Google Cloud、Azure)上的生產工作負載、CI/CD 管線,以及 Kubernetes,適用於您希望消除靜態密鑰的情境

這兩種方法都能授予對 Claude API 端點的相同存取權限。選擇 API 金鑰以快速開始使用,當您的工作負載已具備可聯合的平台核發身份時,再轉換至 Workload Identity Federation。

API 金鑰

API 金鑰是您在 Claude Console 中產生的靜態密鑰,並在每次請求時傳送。

  • 建立金鑰: 前往 Claude Console 中的 Settings → API keys。使用 workspaces 依專案或環境來限定金鑰的範圍。
  • 傳送金鑰: 在直接的 HTTP 請求上設定 x-api-key 標頭,或設定 ANTHROPIC_API_KEY 環境變數,用戶端 SDK 會自動讀取該變數。
POST /v1/messages
x-api-key: YOUR_API_KEY
anthropic-version: 2023-06-01
content-type: application/json

API 金鑰沒有到期日。請將其儲存在密鑰管理工具中、定期輪替,並撤銷任何您懷疑已外洩的金鑰。

client = Anthropic(api_key="my-anthropic-api-key")
# 或者,若環境中已設定 ANTHROPIC_API_KEY:
client = Anthropic()

Workload Identity Federation

「Workload Identity Federation」(工作負載身份聯合),即 WIF,讓工作負載能夠使用由您已信任的「identity provider」(身份提供者),即 IdP(例如 AWS IAM、Google Cloud,或任何符合標準的 OIDC 發行者,如 GitHub Actions、Kubernetes 服務帳戶、SPIFFE、Microsoft Entra ID 或 Okta)所核發的短期身份權杖進行身份驗證。工作負載會在 POST /v1/oauth/token 端點將其 IdP 核發的 JWT 交換為短期的 Claude API 存取權杖,而 SDK 會在該權杖到期前自動重新整理。無需產生、分發或輪替任何 sk-ant-api... 字串。

聯合機制可從您的環境中移除長期有效的 Claude API 金鑰,這能縮小憑證外洩時的影響範圍,並讓您使用與管理雲端資源相同的 IdP 控制機制來管理存取權限。然而,它本身並不能保證端對端的安全性:信任鏈的強度取決於您的身份提供者的設定,而上游一個環節的長期密鑰(例如,可產生 IdP 權杖的靜態雲端憑證)仍可能破壞整個機制。請將聯合機制與您的提供者的控制措施搭配使用,例如 IP 允許清單、MFA 和稽核記錄。

若要設定聯合,您需要在 Claude Console 中建立三個資源(一個服務帳戶、一個聯合發行者,以及一個聯合規則),然後將您的 SDK 指向該規則。請參閱 Workload Identity Federation 以取得完整的設定逐步說明。

後續步驟

設定 Workload Identity Federation

設定發行者、規則和服務帳戶,然後交換權杖

身份提供者指南

適用於 AWS、Google Cloud、Azure、GitHub Actions、Kubernetes、SPIFFE 和 Okta 的逐步指南

WIF 參考

環境變數、驗證規則、設定檔組態和錯誤參考

用戶端 SDK

Python、TypeScript、C#、Go、Java、PHP、Ruby 和 CLI

Was this page helpful?

  • API 金鑰
  • Workload Identity Federation
  • 後續步驟