Was this page helpful?
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 時:
x-api-key 標頭中使用 Admin API 金鑰發出請求這對以下情況很有用:
有五個組織級別的角色。有關更多詳細資訊,請參閱 API Console 角色和權限 文章。
| 角色 | 權限 |
|---|---|
| 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": "[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 範例,請參閱工作區。
管理使用者對特定工作區的存取:
# 將成員新增到工作區
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 金鑰
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 分析 API 監控開發人員生產力和 Claude Code 採用情況。
為了有效使用 Admin API:
如需工作區特定的問題,請參閱工作區常見問題。