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 Console 中用量和成本页面提供的信息类似。
此 API 使您能够更好地监控、分析和优化您的 Claude 实现:
需要管理 API 密钥
此 API 是管理 API 的一部分。这些端点需要管理 API 密钥(以 sk-ant-admin... 开头),与标准 API 密钥不同。只有具有管理员角色的组织成员才能通过 Claude Console 配置管理 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 端点,按模型、工作区和服务层级详细分类跟踪组织内的 token 消耗。
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-opus-4-6&\
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"通过使用 inference_geo 维度对用量进行分组和过滤来跟踪您的数据驻留控制。这对于验证组织内的地理路由非常有用。
curl "https://api.anthropic.com/v1/organizations/usage_report/messages?\
starting_at=2026-02-01T00:00:00Z&\
ending_at=2026-02-08T00:00:00Z&\
group_by[]=inference_geo&\
group_by[]=model&\
bucket_width=1d" \
--header "anthropic-version: 2023-06-01" \
--header "x-api-key: $ADMIN_API_KEY"您还可以过滤到特定地理位置。有效值为 global、us 和 not_available:
curl "https://api.anthropic.com/v1/organizations/usage_report/messages?\
starting_at=2026-02-01T00:00:00Z&\
ending_at=2026-02-08T00:00:00Z&\
inference_geos[]=us&\
group_by[]=model&\
bucket_width=1d" \
--header "anthropic-version: 2023-06-01" \
--header "x-api-key: $ADMIN_API_KEY"2026 年 2 月之前发布的模型(Claude Opus 4.6 之前)不支持 inference_geo 请求参数,因此其用量报告在此维度上返回 "not_available"。您可以在 inference_geos[] 中使用 not_available 作为过滤值来定位这些模型。
| 粒度 | 默认限制 | 最大限制 | 使用场景 |
|---|---|---|---|
1m | 60 个桶 | 1440 个桶 | 实时监控 |
1h | 24 个桶 | 168 个桶 | 每日模式 |
1d | 7 个桶 | 31 个桶 | 每周/每月报告 |
通过 /v1/organizations/cost_report 端点检索以美元为单位的服务级别成本明细。
description 分组时,响应包含解析后的字段,如 model 和 inference_geo1d)有关完整的参数详情和响应模式,请参阅成本 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"在 Claude 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 跟踪 token 消耗作为成本代理。
用量和成本 API 可以帮助您为用户提供更好的体验、管理成本并保护您的速率限制。了解更多关于这些其他功能的信息:
Was this page helpful?