Loading...
    • 开发者指南
    • API 参考
    • MCP
    • 资源
    • 发布说明
    Search...
    ⌘K
    快速开始
    Claude 简介快速入门
    模型与定价
    模型概览选择模型Claude 4.5 新功能迁移到 Claude 4.5模型弃用定价
    使用 Claude 构建
    功能概览使用 Messages API上下文窗口提示词最佳实践
    能力
    提示词缓存上下文编辑扩展思考工作量流式消息批量处理引用多语言支持Token 计数嵌入视觉PDF 支持Files API搜索结果结构化输出
    工具
    概览如何实现工具使用细粒度工具流式传输Bash 工具代码执行工具程序化工具调用计算机使用工具文本编辑器工具Web 获取工具Web 搜索工具内存工具工具搜索工具
    Agent Skills
    概览快速入门最佳实践在 API 中使用 Skills
    Agent SDK
    概览快速入门TypeScript SDKTypeScript V2(预览版)Python SDK迁移指南
    API 中的 MCP
    MCP 连接器远程 MCP 服务器
    第三方平台上的 Claude
    Amazon BedrockMicrosoft FoundryVertex AI
    提示词工程
    概览提示词生成器使用提示词模板提示词改进器清晰直接使用示例(多轮提示)让 Claude 思考(CoT)使用 XML 标签给 Claude 一个角色(系统提示词)预填充 Claude 的响应链接复杂提示词长上下文提示扩展思考提示
    测试与评估
    定义成功标准开发测试用例使用评估工具降低延迟
    加强防护栏
    减少幻觉提高输出一致性缓解越狱流式拒绝减少提示词泄露保持 Claude 的角色
    管理和监控
    Admin API 概览使用和成本 APIClaude Code Analytics API
    Console
    Log in
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...

    Solutions

    • AI agents
    • Code modernization
    • Coding
    • Customer support
    • Education
    • Financial services
    • Government
    • Life sciences

    Partners

    • Amazon Bedrock
    • Google Cloud's Vertex AI

    Learn

    • Blog
    • Catalog
    • Courses
    • Use cases
    • Connectors
    • Customer stories
    • Engineering at Anthropic
    • Events
    • Powered by Claude
    • Service partners
    • Startups program

    Company

    • Anthropic
    • Careers
    • Economic Futures
    • Research
    • News
    • Responsible Scaling Policy
    • Security and compliance
    • Transparency

    Learn

    • Blog
    • Catalog
    • Courses
    • Use cases
    • Connectors
    • Customer stories
    • Engineering at Anthropic
    • Events
    • Powered by Claude
    • Service partners
    • Startups program

    Help and security

    • Availability
    • Status
    • Support
    • Discord

    Terms and policies

    • Privacy policy
    • Responsible disclosure policy
    • Terms of service: Commercial
    • Terms of service: Consumer
    • Usage policy
    管理和监控

    Admin API 概览

    Admin API 允许您以编程方式管理组织的资源,包括组织成员、工作区和 API 密钥。

    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 控制台 中进行手动配置。

    Admin API 需要特殊访问权限

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

    Admin API 如何工作

    使用 Admin API 时:

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

    这对以下情况很有用:

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

    组织角色和权限

    有五个组织级角色。查看更多详情 此处。

    角色权限
    user可以使用 Workbench
    claude_code_user可以使用 Workbench 和 Claude Code
    developer可以使用 Workbench 和管理 API 密钥
    billing可以使用 Workbench 和管理账单详情
    admin可以执行上述所有操作,加上管理用户

    关键概念

    组织成员

    您可以列出 组织成员、更新成员角色和删除成员。

    Shell
    # 列出组织成员
    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"

    组织邀请

    您可以邀请用户加入组织并管理这些 邀请。

    Shell
    # 创建邀请
    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"

    工作区

    创建和管理 工作区(控制台)来组织您的资源:

    Shell
    # 创建工作区
    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"

    工作区成员

    管理 用户对特定工作区的访问权限:

    Shell
    # 将成员添加到工作区
    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 密钥:

    Shell
    # 列出 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 端点:

    • 使用情况端点(/v1/organizations/usage_report/messages)提供详细的使用数据,包括令牌计数和请求指标,按各种维度(如工作区、用户和模型)分组。
    • 成本端点(/v1/organizations/cost_report)提供与您的组织使用情况相关的成本数据,允许您跟踪支出并按工作区或描述分配成本。

    这些端点提供了对您的组织使用情况和相关成本的详细见解。

    访问 Claude Code 分析

    对于使用 Claude Code 的组织,Claude Code 分析 API 提供详细的生产力指标和使用见解:

    • Claude Code 分析端点(/v1/organizations/usage_report/claude_code)提供 Claude Code 使用情况的每日聚合指标,包括会话、代码行数、提交、拉取请求、工具使用统计和按用户和模型分解的成本数据。

    此 API 使您能够跟踪开发人员生产力、分析 Claude Code 采用情况,并为您的组织构建自定义仪表板。

    最佳实践

    要有效使用 Admin API:

    • 为工作区和 API 密钥使用有意义的名称和描述
    • 为失败的操作实施适当的错误处理
    • 定期审计成员角色和权限
    • 清理未使用的工作区和过期的邀请
    • 监控 API 密钥使用情况并定期轮换密钥

    常见问题

    • Admin API 如何工作
    • API 密钥
    • 访问 Claude Code 分析