Admin API 不适用于个人账户。 如需与团队成员协作并添加成员,请在 Console → Settings → Organization 中设置您的组织。
Usage & Cost Admin API 为您的组织提供对历史 API 用量和成本数据的编程化、细粒度访问。这些数据与 Claude Console 中用量和成本页面上提供的信息类似。
此 API 使您能够更好地监控、分析和优化您的 Claude 实现:
需要 Admin API 密钥。 这些端点需要 Admin API 密钥,它与标准的 Claude API 密钥不同。请参阅创建 Admin API 密钥,了解如何为您的组织类型创建密钥以及应选择哪些权限范围。
Claude Enterprise 组织使用 Analytics API 密钥配合另一个不同的 API;请参阅您需要哪个 API?。
AWS 上的 Claude Platform: 编程式的用量与成本 API 端点目前不可用。请改为在 Claude Console 的用量和成本页面上查看用量和成本数据。
Anthropic 通过两个 API 提供成本和用量报告,具体取决于您的组织管理的是哪个 Claude 产品:
| 您的组织 | API | 密钥类型 |
|---|---|---|
| Claude Console(Claude Platform) | 本页面描述的用量与成本 Admin API | Admin API 密钥(sk-ant-admin01-...) |
| Claude Enterprise(claude.ai) | Claude Enterprise Analytics API 的成本和用量端点 | Analytics API 密钥 |
Claude Enterprise 父组织不会出现在 Claude Console 中,也没有 Admin API 密钥,因此对它们而言,Analytics API 密钥是获取这些数据的唯一途径。请参阅分析 API,了解如何创建每种密钥类型以及 Claude Enterprise 成本数据适用于哪些计划。
领先的可观测性平台提供了开箱即用的集成,用于监控您的 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" \
-H "anthropic-version: 2023-06-01" \
-H "x-api-key: $ANTHROPIC_ADMIN_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" \
-H "anthropic-version: 2023-06-01" \
-H "x-api-key: $ANTHROPIC_ADMIN_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-5&\
service_tiers[]=batch&\
context_window[]=0-200k&\
bucket_width=1h" \
-H "anthropic-version: 2023-06-01" \
-H "x-api-key: $ANTHROPIC_ADMIN_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" \
-H "anthropic-version: 2023-06-01" \
-H "x-api-key: $ANTHROPIC_ADMIN_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" \
-H "anthropic-version: 2023-06-01" \
-H "x-api-key: $ANTHROPIC_ADMIN_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" \
-H "anthropic-version: 2023-06-01" \
-H "x-api-key: $ANTHROPIC_ADMIN_KEY"2026 年 2 月之前发布的模型(Claude Opus 4.6 和 Claude Sonnet 4.6 之前)不支持 inference_geo 请求参数,因此它们的用量报告在此维度上返回 "not_available"。您可以在 inference_geos[] 中使用 not_available 作为过滤值来定位这些模型。
通过使用 speed 维度进行分组和过滤,跟踪快速模式的用量。这对于监控标准模式与快速模式的用量非常有用。
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[]=speed&\
group_by[]=model&\
bucket_width=1d" \
-H "anthropic-version: 2023-06-01" \
-H "anthropic-beta: fast-mode-2026-02-01" \
-H "x-api-key: $ANTHROPIC_ADMIN_KEY"您也可以过滤到特定的速度。有效值为 standard 和 fast:
curl "https://api.anthropic.com/v1/organizations/usage_report/messages?\
starting_at=2026-02-01T00:00:00Z&\
ending_at=2026-02-08T00:00:00Z&\
speeds[]=fast&\
group_by[]=model&\
bucket_width=1d" \
-H "anthropic-version: 2023-06-01" \
-H "anthropic-beta: fast-mode-2026-02-01" \
-H "x-api-key: $ANTHROPIC_ADMIN_KEY"speeds[] 过滤器和 speed group_by 值都需要 fast-mode-2026-02-01 测试版标头。
| 粒度 | 默认限制 | 最大限制 | 使用场景 |
|---|---|---|---|
1m | 60 个桶 | 1,440 个桶 | 实时监控 |
1h | 24 个桶 | 168 个桶 | 每日模式 |
1d | 7 个桶 | 31 个桶 | 每周/每月报告 |
通过 /v1/organizations/cost_report 端点检索以美元计的服务级别成本细分。
description 分组时,响应包含已解析的字段,如 model 和 inference_geo1d)有关完整的参数详情和响应模式,请参阅成本 API 参考。
Priority Tier 成本使用不同的计费模型,不包含在成本端点中。请改为通过用量端点跟踪 Priority Tier 用量。
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" \
-H "anthropic-version: 2023-06-01" \
-H "x-api-key: $ANTHROPIC_ADMIN_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" \
-H "anthropic-version: 2023-06-01" \
-H "x-api-key: $ANTHROPIC_ADMIN_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..." \
-H "anthropic-version: 2023-06-01" \
-H "x-api-key: $ANTHROPIC_ADMIN_KEY"在 Claude Cookbook 中探索详细的实现:
用量和成本数据通常在 API 请求完成后 5 分钟内出现,但偶尔延迟可能会更长。
该 API 支持每分钟轮询一次以供持续使用。对于短时间的突发请求(例如,下载分页数据),更频繁的轮询是可以接受的。对于需要频繁更新的仪表板,请缓存结果。
代码执行成本出现在成本端点中,在描述字段中归类于 Code Execution Usage 下。代码执行不包含在用量端点中。
在用量端点中按 service_tier 过滤或分组,并查找 priority 值。Priority Tier 成本在成本端点中不可用。
来自 Workbench 的 API 用量不与 API 密钥关联,因此即使按该维度分组,api_key_id 也将为 null。
归属于默认工作区的用量和成本的 workspace_id 值为 null。
请使用 Claude Code Analytics API,它提供按用户的估算成本和生产力指标,而不会有按大量 API 密钥细分成本所带来的性能限制。对于使用大量密钥的一般 API 用量,请使用用量 API 跟踪令牌消耗作为成本的代理指标。
使用用量和成本 API 为您的用户提供更好的体验、管理成本并保护您的速率限制。了解更多其他功能:
Was this page helpful?