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

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

管理 API 需要特殊存取權限

管理 API 需要一個特殊的管理 API 金鑰(以 sk-ant-admin... 開頭),它與標準 API 金鑰不同。只有具有管理員角色的組織成員才能通過 Anthropic 控制台提供管理 API 金鑰。

管理 API 的工作原理

當您使用管理 API 時:

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

這對以下情況很有用:

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

組織角色和權限

有五種組織級別的角色。

角色權限
user可以使用 Workbench
claude_code_user可以使用 Workbench 和 Claude Code
developer可以使用 Workbench 和管理 API 金鑰
billing可以使用 Workbench 和管理帳單詳情
admin可以執行以上所有操作,並管理用戶

關鍵概念

組織成員

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

# 列出組織成員
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"

組織邀請

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

# 創建邀請
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": "newuser@domain.com",
    "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"

工作區

創建和管理工作區以組織您的資源:

# 創建工作區
curl --request POST "https://api.anthropic.com/v1/organizations/workspaces" \
  --header "anthropic-version: 2023-06-01" \
  --header "x-api-key: $ANTHROPIC_ADMIN_KEY" \
  --data '{"name": "Production"}'

# 列出工作區
curl "https://api.anthropic.com/v1/organizations/workspaces?limit=10&include_archived=false" \
  --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}/archive" \
  --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" \
  --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 金鑰:

# 列出 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"
  }'

最佳實踐

要有效使用管理 API:

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

常見問題