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 使用情况和成本数据的编程和细粒度访问。此数据类似于 Claude 控制台的使用情况和成本页面中提供的信息。
此 API 使您能够更好地监控、分析和优化您的 Claude 实现:
需要管理员 API 密钥
此 API 是管理员 API的一部分。这些端点需要管理员 API 密钥(以 sk-ant-admin... 开头),与标准 API 密钥不同。只有具有管理员角色的组织成员才能通过 Claude 控制台配置管理员 API 密钥。
领先的可观测性平台为监控您的 Claude API 使用情况和成本提供现成的集成,无需编写自定义代码。这些集成提供仪表板、警报和分析,帮助您有效管理 API 使用情况。
用于跟踪和预测成本的云智能平台
具有自动跟踪和监控的 LLM 可观测性
无代理集成,可轻松实现 LLM 可观测性,具有开箱即用的仪表板和警报
通过 OpenTelemetry 进行高级查询和可视化
用于 LLM 成本和使用情况可观测性的 FinOps 平台
获取您组织过去 7 天的每日使用情况:
curl "https://api.anthropic.com/v1/organizations/usage_report/messages?\
starting_at=2025-01-08T00:00:00Z&\
ending_at=2025-01-15T00:00:00Z&\
bucket_width=1d" \
--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/messages 端点跟踪整个组织的令牌消耗,并按模型、工作区和服务层进行详细分解。
1m、1h 或 1d)聚合使用情况数据有关完整的参数详情和响应架构,请参阅使用情况 API 参考。
curl "https://api.anthropic.com/v1/organizations/usage_report/messages?\
starting_at=2025-01-01T00:00:00Z&\
ending_at=2025-01-08T00:00:00Z&\
group_by[]=model&\
bucket_width=1d" \
--header "anthropic-version: 2023-06-01" \
--header "x-api-key: $ADMIN_API_KEY"curl "https://api.anthropic.com/v1/organizations/usage_report/messages?\
starting_at=2025-01-15T00:00:00Z&\
ending_at=2025-01-15T23:59:59Z&\
models[]=claude-sonnet-4-5-20250929&\
service_tiers[]=batch&\
context_window[]=0-200k&\
bucket_width=1h" \
--header "anthropic-version: 2023-06-01" \
--header "x-api-key: $ADMIN_API_KEY"curl "https://api.anthropic.com/v1/organizations/usage_report/messages?\
starting_at=2025-01-01T00:00:00Z&\
ending_at=2025-01-08T00:00:00Z&\
api_key_ids[]=apikey_01Rj2N8SVvo6BePZj99NhmiT&\
api_key_ids[]=apikey_01ABC123DEF456GHI789JKL&\
workspace_ids[]=wrkspc_01JwQvzr7rXLA5AGx3HKfFUJ&\
workspace_ids[]=wrkspc_01XYZ789ABC123DEF456MNO&\
bucket_width=1d" \
--header "anthropic-version: 2023-06-01" \
--header "x-api-key: $ADMIN_API_KEY"| 粒度 | 默认限制 | 最大限制 | 用例 |
|---|---|---|---|
1m | 60 个桶 | 1440 个桶 | 实时监控 |
1h | 24 个桶 | 168 个桶 | 每日模式 |
1d | 7 个桶 | 31 个桶 | 每周/每月报告 |
使用 /v1/organizations/cost_report 端点检索以美元为单位的服务级成本分解。
1d)有关完整的参数详情和响应架构,请参阅成本 API 参考。
优先级层成本使用不同的计费模式,不包括在成本端点中。通过使用端点改为跟踪优先级层使用情况。
curl "https://api.anthropic.com/v1/organizations/cost_report?\
starting_at=2025-01-01T00:00:00Z&\
ending_at=2025-01-31T00:00:00Z&\
group_by[]=workspace_id&\
group_by[]=description" \
--header "anthropic-version: 2023-06-01" \
--header "x-api-key: $ADMIN_API_KEY"两个端点都支持大型数据集的分页:
has_more 为 true,在下一个请求中使用 next_page 值has_more 为 false# 第一个请求
curl "https://api.anthropic.com/v1/organizations/usage_report/messages?\
starting_at=2025-01-01T00:00:00Z&\
ending_at=2025-01-31T00:00:00Z&\
limit=7" \
--header "anthropic-version: 2023-06-01" \
--header "x-api-key: $ADMIN_API_KEY"
# 响应包括:"has_more": true, "next_page": "page_xyz..."
# 带分页的下一个请求
curl "https://api.anthropic.com/v1/organizations/usage_report/messages?\
starting_at=2025-01-01T00:00:00Z&\
ending_at=2025-01-31T00:00:00Z&\
limit=7&\
page=page_xyz..." \
--header "anthropic-version: 2023-06-01" \
--header "x-api-key: $ADMIN_API_KEY"在 anthropic-cookbook 中探索详细的实现:
使用情况和成本数据通常在 API 请求完成后 5 分钟内出现,尽管延迟有时可能更长。
该 API 支持持续使用时每分钟轮询一次。对于短突发(例如,下载分页数据),更频繁的轮询是可以接受的。为需要频繁更新的仪表板缓存结果。
代码执行成本出现在成本端点中,在描述字段中分组为 Code Execution Usage。代码执行不包括在使用端点中。
在使用端点中按 service_tier 筛选或分组,并查找 priority 值。优先级层成本在成本端点中不可用。
来自 Workbench 的 API 使用情况不与 API 密钥关联,因此即使按该维度分组,api_key_id 也将为 null。
归属于默认工作区的使用情况和成本对 workspace_id 具有 null 值。
使用 Claude Code 分析 API,它提供按用户的估计成本和生产力指标,而不会出现按许多 API 密钥分解成本的性能限制。对于具有许多密钥的一般 API 使用,使用使用情况 API 跟踪令牌消耗作为成本代理。
使用情况和成本 API 可用于帮助您为用户提供更好的体验,帮助您管理成本,并保护您的速率限制。了解有关这些其他功能的更多信息: