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 Console 中手动配置的管理任务提供了程序化控制。

管理员 API 需要特殊访问权限

管理员 API 需要一个特殊的管理员 API 密钥(以 sk-ant-admin... 开头),这与标准 API 密钥不同。只有具有管理员角色的组织成员才能通过 Anthropic Console 配置管理员 API 密钥。

管理员 API 的工作原理

当您使用管理员 API 时:

  1. 您在 x-api-key 标头中使用管理员 API 密钥发出请求
  2. API 允许您管理:
    • 组织成员及其角色
    • 组织成员邀请
    • 工作空间及其成员
    • API 密钥

这对以下情况很有用:

  • 自动化用户入职/离职
  • 以编程方式管理工作空间访问权限
  • 监控和管理 API 密钥使用情况

组织角色和权限

有四个组织级别的角色。

角色权限
user可以使用 Workbench
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 密钥使用情况并定期轮换密钥

常见问题

Was this page helpful?