The Admin API is unavailable for individual accounts. To collaborate with teammates and add members, set up your organization in Console → Settings → Organization.
Claude Code 分析管理 API 提供对 Claude Code 用户每日聚合使用指标的编程访问,使组织能够分析开发者生产力并构建自定义仪表板。此 API 弥补了我们基础的分析仪表板与复杂的 OpenTelemetry 集成之间的差距。
此 API 使您能够更好地监控、分析和优化 Claude Code 的采用:
需要管理 API 密钥
此 API 是管理 API 的一部分。这些端点需要管理 API 密钥(以 sk-ant-admin... 开头),与标准 API 密钥不同。只有具有管理员角色的组织成员才能通过 Claude 控制台配置管理 API 密钥。
获取您组织特定日期的 Claude Code 分析数据:
curl "https://api.anthropic.com/v1/organizations/usage_report/claude_code?\
starting_at=2025-09-08&\
limit=20" \
--header "anthropic-version: 2023-06-01" \
--header "x-api-key: $ADMIN_API_KEY"为集成设置 User-Agent 头
如果您正在构建集成,请设置 User-Agent 头以帮助我们了解使用模式:
User-Agent: YourApp/1.0.0 (https://yourapp.com)通过 /v1/organizations/usage_report/claude_code 端点跟踪您组织中的 Claude Code 使用情况、生产力指标和开发者活动。
starting_at 参数指定的单日指标有关完整的参数详情和响应模式,请参阅 Claude Code 分析 API 参考。
curl "https://api.anthropic.com/v1/organizations/usage_report/claude_code?\
starting_at=2025-09-08" \
--header "anthropic-version: 2023-06-01" \
--header "x-api-key: $ADMIN_API_KEY"# 第一次请求
curl "https://api.anthropic.com/v1/organizations/usage_report/claude_code?\
starting_at=2025-09-08&\
limit=20" \
--header "anthropic-version: 2023-06-01" \
--header "x-api-key: $ADMIN_API_KEY"
# 使用响应中的游标进行后续请求
curl "https://api.anthropic.com/v1/organizations/usage_report/claude_code?\
starting_at=2025-09-08&\
page=page_MjAyNS0wNS0xNFQwMDowMDowMFo=" \
--header "anthropic-version: 2023-06-01" \
--header "x-api-key: $ADMIN_API_KEY"| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
starting_at | string | 是 | UTC 日期,格式为 YYYY-MM-DD。仅返回该单日的指标 |
limit | integer | 否 | 每页记录数(默认:20,最大:1000) |
page | string | 否 | 来自上一个响应的 next_page 字段的不透明游标令牌 |
每条响应记录包含单个用户在单日内的以下指标:
user_actor 包含 email_address,或 api_actor 包含 api_key_name)api 表示 API 客户,subscription 表示 Pro/Team 客户)vscode、iTerm.app、tmux)按工具类型细分的工具操作接受和拒绝率:
对于使用的每个 Claude 模型:
claude-opus-4-6)USD)API 以以下格式返回数据:
{
"data": [
{
"date": "2025-09-01T00:00:00Z",
"actor": {
"type": "user_actor",
"email_address": "[email protected]"
},
"organization_id": "dc9f6c26-b22c-4831-8d01-0446bada88f1",
"customer_type": "api",
"terminal_type": "vscode",
"core_metrics": {
"num_sessions": 5,
"lines_of_code": {
"added": 1543,
"removed": 892
},
"commits_by_claude_code": 12,
"pull_requests_by_claude_code": 2
},
"tool_actions": {
"edit_tool": {
"accepted": 45,
"rejected": 5
},
"multi_edit_tool": {
"accepted": 12,
"rejected": 2
},
"write_tool": {
"accepted": 8,
"rejected": 1
},
"notebook_edit_tool": {
"accepted": 3,
"rejected": 0
}
},
"model_breakdown": [
{
"model": "claude-opus-4-6",
"tokens": {
"input": 100000,
"output": 35000,
"cache_read": 10000,
"cache_creation": 5000
},
"estimated_cost": {
"currency": "USD",
"amount": 1025
}
}
]
}
],
"has_more": false,
"next_page": null
}API 支持基于游标的分页,适用于拥有大量用户的组织:
limit 参数发起初始请求has_more 为 true,在下一个请求中使用 next_page 值has_more 为 false游标编码了最后一条记录的位置,即使有新数据到达也能确保稳定的分页。每个分页会话维护一致的数据边界,确保您不会遗漏或重复记录。
Claude Code 分析数据通常在用户活动完成后 1 小时内出现。为确保一致的分页结果,响应中仅包含超过 1 小时的数据。
不可以,此 API 仅提供每日聚合指标。如需实时监控,请考虑使用 OpenTelemetry 集成。
用户通过 actor 字段以两种方式识别:
user_actor:包含通过 OAuth 认证的用户的 email_address(最常见)api_actor:包含通过 API 密钥认证的用户的 api_key_namecustomer_type 字段指示使用来自 api 客户(API 按量付费)还是 subscription 客户(Pro/Team 计划)。
历史 Claude Code 分析数据会被保留并可通过 API 访问。此数据没有指定的删除期限。
此 API 仅跟踪 Claude API(第一方)上的 Claude Code 使用情况。不包括 Amazon Bedrock、Google Vertex AI 或其他第三方平台上的使用情况。
Claude Code 分析 API 对所有有权访问管理 API 的组织免费使用。
工具接受率 = accepted / (accepted + rejected),按每种工具类型计算。例如,如果 edit 工具显示 45 次接受和 5 次拒绝,则接受率为 90%。
所有日期均为 UTC。starting_at 参数应为 YYYY-MM-DD 格式,表示该日的 UTC 午夜。
Claude Code 分析 API 帮助您了解和优化团队的开发工作流程。了解更多相关功能:
Was this page helpful?