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 標頭中發送請求這適用於:
共有五個組織層級的角色。請參閱更多詳細資訊此處。
| 角色 | 權限 |
|---|---|
| user | 可以使用 Workbench |
| claude_code_user | 可以使用 Workbench 和 Claude Code |
| developer | 可以使用 Workbench 和管理 API 金鑰 |
| billing | 可以使用 Workbench 和管理帳單詳情 |
| admin | 可以執行以上所有操作,加上管理使用者 |
您可以列出組織成員、更新成員角色和移除成員。
# List organization members
curl "https://api.anthropic.com/v1/organizations/users?limit=10" \
--header "anthropic-version: 2023-06-01" \
--header "x-api-key: $ANTHROPIC_ADMIN_KEY"
# Update member role
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"}'
# Remove member
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"您可以邀請使用者加入組織並管理這些邀請。
# Create invite
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"
}'
# List invites
curl "https://api.anthropic.com/v1/organizations/invites?limit=10" \
--header "anthropic-version: 2023-06-01" \
--header "x-api-key: $ANTHROPIC_ADMIN_KEY"
# Delete invite
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"如需工作區的完整指南,請參閱工作區。
# Create workspace
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"}'
# List workspaces
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"
# Archive workspace
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"# Add member to workspace
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"
}'
# List workspace members
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"
# Update member role
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"
}'
# Remove member from workspace
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 金鑰:
# List API keys
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"
# Update API key
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 端點:
/v1/organizations/usage_report/messages)提供詳細的使用量資料,包括 token 計數和請求指標,按工作區、使用者和模型等各種維度分組。/v1/organizations/cost_report)提供與組織使用量相關的費用資料,讓您能夠按工作區或描述追蹤支出和分配成本。這些端點提供了對組織使用量和相關費用的詳細洞察。
對於使用 Claude Code 的組織,Claude Code Analytics API 提供詳細的生產力指標和使用量洞察:
/v1/organizations/usage_report/claude_code)提供 Claude Code 使用量的每日彙總指標,包括工作階段、程式碼行數、提交、拉取請求、工具使用統計資料,以及按使用者和模型細分的費用資料。此 API 讓您能夠追蹤開發者生產力、分析 Claude Code 採用情況,並為組織建立自訂儀表板。
為了有效使用 Admin API:
Was this page helpful?