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:
有关工作区特定的问题,请参阅工作区常见问题。
Was this page helpful?