Loading...
    • 建構
    • 管理
    • 模型與定價
    • 客戶端 SDK
    • API 參考
    Search...
    ⌘K
    Log in
    Admin API 概覽
    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
    管理

    Admin API 概覽

    了解如何使用 Admin API 以程式方式管理您的組織資源。

    The Admin API is unavailable for individual accounts. To collaborate with teammates and add members, set up your organization in Console → Settings → Organization.

    Admin API 允許您以程式方式管理組織的資源,包括組織成員、工作區和 API 金鑰。這提供了對管理工作的程式控制,否則需要在 Claude Console 中進行手動配置。

    Admin API 需要特殊存取權限

    Admin API 需要特殊的 Admin API 金鑰(以 sk-ant-admin... 開頭),與標準 API 金鑰不同。只有具有管理員角色的組織成員才能透過 Claude Console 配置 Admin API 金鑰。

    Admin API 的運作方式

    當您使用 Admin API 時:

    1. 您在 x-api-key 標頭中使用 Admin API 金鑰發出請求
    2. API 允許您管理:
      • 組織成員及其角色
      • 組織成員邀請
      • 工作區及其成員
      • API 金鑰

    這對以下情況很有用:

    • 自動化使用者上線/離線
    • 以程式方式管理工作區存取
    • 監控和管理 API 金鑰使用情況

    組織角色和權限

    有五個組織級別的角色。有關更多詳細資訊,請參閱 API Console 角色和權限 文章。

    角色權限
    user可以使用 Workbench
    claude_code_user可以使用 Workbench 和 Claude Code
    developer可以使用 Workbench 和管理 API 金鑰
    billing可以使用 Workbench 和管理帳單詳細資訊
    admin可以執行上述所有操作,加上管理使用者

    關鍵概念

    組織成員

    您可以列出組織成員、更新成員角色和移除成員。

    Shell
    # 列出組織成員
    curl "https://api.anthropic.com/v1/organizations/users?limit=10" \
      --header "anthropic-version: 2023-06-01" \
      --header "x-api-key: $ANTHROPIC_ADMIN_KEY"
    
    # 更新成員角色
    curl "https://api.anthropic.com/v1/organizations/users/{user_id}" \
      --header "anthropic-version: 2023-06-01" \
      --header "x-api-key: $ANTHROPIC_ADMIN_KEY" \
      --data '{"role": "developer"}'
    
    # 移除成員
    curl --request DELETE "https://api.anthropic.com/v1/organizations/users/{user_id}" \
      --header "anthropic-version: 2023-06-01" \
      --header "x-api-key: $ANTHROPIC_ADMIN_KEY"

    組織邀請

    您可以邀請使用者加入組織並管理這些邀請。

    Shell
    # 建立邀請
    curl --request POST "https://api.anthropic.com/v1/organizations/invites" \
      --header "anthropic-version: 2023-06-01" \
      --header "x-api-key: $ANTHROPIC_ADMIN_KEY" \
      --data '{
        "email": "[email protected]",
        "role": "developer"
      }'
    
    # 列出邀請
    curl "https://api.anthropic.com/v1/organizations/invites?limit=10" \
      --header "anthropic-version: 2023-06-01" \
      --header "x-api-key: $ANTHROPIC_ADMIN_KEY"
    
    # 刪除邀請
    curl --request DELETE "https://api.anthropic.com/v1/organizations/invites/{invite_id}" \
      --header "anthropic-version: 2023-06-01" \
      --header "x-api-key: $ANTHROPIC_ADMIN_KEY"

    工作區

    如需工作區的完整指南,包括 Console 和 API 範例,請參閱工作區。

    工作區成員

    管理使用者對特定工作區的存取:

    Shell
    # 將成員新增到工作區
    curl --request POST "https://api.anthropic.com/v1/organizations/workspaces/{workspace_id}/members" \
      --header "anthropic-version: 2023-06-01" \
      --header "x-api-key: $ANTHROPIC_ADMIN_KEY" \
      --data '{
        "user_id": "user_xxx",
        "workspace_role": "workspace_developer"
      }'
    
    # 列出工作區成員
    curl "https://api.anthropic.com/v1/organizations/workspaces/{workspace_id}/members?limit=10" \
      --header "anthropic-version: 2023-06-01" \
      --header "x-api-key: $ANTHROPIC_ADMIN_KEY"
    
    # 更新成員角色
    curl --request POST "https://api.anthropic.com/v1/organizations/workspaces/{workspace_id}/members/{user_id}" \
      --header "anthropic-version: 2023-06-01" \
      --header "x-api-key: $ANTHROPIC_ADMIN_KEY" \
      --data '{
        "workspace_role": "workspace_admin"
      }'
    
    # 從工作區移除成員
    curl --request DELETE "https://api.anthropic.com/v1/organizations/workspaces/{workspace_id}/members/{user_id}" \
      --header "anthropic-version: 2023-06-01" \
      --header "x-api-key: $ANTHROPIC_ADMIN_KEY"

    API 金鑰

    監控和管理 API 金鑰:

    Shell
    # 列出 API 金鑰
    curl "https://api.anthropic.com/v1/organizations/api_keys?limit=10&status=active&workspace_id=wrkspc_xxx" \
      --header "anthropic-version: 2023-06-01" \
      --header "x-api-key: $ANTHROPIC_ADMIN_KEY"
    
    # 更新 API 金鑰
    curl --request POST "https://api.anthropic.com/v1/organizations/api_keys/{api_key_id}" \
      --header "anthropic-version: 2023-06-01" \
      --header "x-api-key: $ANTHROPIC_ADMIN_KEY" \
      --data '{
        "status": "inactive",
        "name": "New Key Name"
      }'

    存取組織資訊

    使用 /v1/organizations/me 端點以程式方式取得組織的相關資訊。

    例如:

    curl "https://api.anthropic.com/v1/organizations/me" \
      --header "anthropic-version: 2023-06-01" \
      --header "x-api-key: $ADMIN_API_KEY"
    {
      "id": "12345678-1234-5678-1234-567812345678",
      "type": "organization",
      "name": "Organization Name"
    }

    此端點對於以程式方式確定 Admin API 金鑰屬於哪個組織很有用。

    如需完整的參數詳細資訊和回應架構,請參閱組織資訊 API 參考。

    使用情況和成本報告

    使用使用情況和成本 API 追蹤組織的使用情況和成本。

    Claude Code 分析

    使用 Claude Code 分析 API 監控開發人員生產力和 Claude Code 採用情況。

    最佳實踐

    為了有效使用 Admin API:

    • 為工作區和 API 金鑰使用有意義的名稱和描述
    • 為失敗的操作實施適當的錯誤處理
    • 定期審計成員角色和權限
    • 清理未使用的工作區和過期的邀請
    • 監控 API 金鑰使用情況並定期輪換金鑰

    常見問題

    如需工作區特定的問題,請參閱工作區常見問題。

    Was this page helpful?

    • Admin API 的運作方式
    • API 金鑰
    • Claude Code 分析