获取 Claude Code 用量报告

get /v1/organizations/usage_report/claude_code

获取 Claude Code 用户的每日汇总用量指标。 使组织能够分析开发者生产力并构建自定义仪表板。

查询参数

  • starting_at: string

    UTC 日期,YYYY-MM-DD 格式。仅返回该单日的指标。

  • limit: optional number

    每页记录数(默认:20,最大:1000)。

  • page: optional string

    来自上一次响应 next_page 字段的不透明游标令牌。

返回值

  • ClaudeCodeUsageReport object { data, has_more, next_page }

    • data: array of object { actor, core_metrics, customer_type, 6 more }

      请求日期的 Claude Code 用量记录列表。

      • actor: object { email_address, type } or object { api_key_name, type }

        执行 Claude Code 操作的用户或 API 密钥。

        • UserActor object { email_address, type }

          • email_address: string

            执行 Claude Code 操作的用户的电子邮件地址。

          • type: "user_actor"

            • "user_actor"
        • APIActor object { api_key_name, type }

          • api_key_name: string

            用于执行 Claude Code 操作的 API 密钥名称。

          • type: "api_actor"

            • "api_actor"
      • core_metrics: object { commits_by_claude_code, lines_of_code, num_sessions, pull_requests_by_claude_code }

        衡量 Claude Code 使用情况和影响的核心生产力指标。

        • commits_by_claude_code: number

          通过 Claude Code 的提交功能创建的 git 提交数量。

        • lines_of_code: object { added, removed }

          通过 Claude Code 进行的代码变更统计。

          • added: number

            Claude Code 在所有文件中添加的代码行总数。

          • removed: number

            Claude Code 在所有文件中删除的代码行总数。

        • num_sessions: number

          此参与者发起的独立 Claude Code 会话数量。

        • pull_requests_by_claude_code: number

          通过 Claude Code 的 PR 功能创建的拉取请求数量。

      • customer_type: "api" or "subscription"

        客户账户类型(api 为 API 客户,subscription 为 Pro/Team 客户)。

        • "api"

        • "subscription"

      • date: string

        用量指标的 UTC 日期,YYYY-MM-DD 格式。

      • model_breakdown: array of object { estimated_cost, model, tokens }

        按使用的 AI 模型分类的 token 用量和费用明细。

        • estimated_cost: object { amount, currency }

          使用此模型的预估费用

          • amount: number

            预估费用金额,以最小货币单位表示(例如 USD 的美分)。

          • currency: string

            预估费用的货币代码(例如 'USD')。

        • model: string

          用于 Claude Code 交互的 AI 模型名称。

        • tokens: object { cache_creation, cache_read, input, output }

          此模型的 token 用量明细

          • cache_creation: number

            此模型消耗的缓存创建 token 数量。

          • cache_read: number

            此模型消耗的缓存读取 token 数量。

          • input: number

            此模型消耗的输入 token 数量。

          • output: number

            此模型生成的输出 token 数量。

      • organization_id: string

        拥有 Claude Code 用量的组织 ID。

      • terminal_type: string

        使用 Claude Code 的终端或环境类型。

      • tool_actions: map[object { accepted, rejected } ]

        按工具类型分类的工具操作接受和拒绝率明细。

        • accepted: number

          用户接受的工具操作建议数量。

        • rejected: number

          用户拒绝的工具操作建议数量。

      • subscription_type: optional "enterprise" or "team"

        订阅客户的订阅层级。API 客户为 null

        • "enterprise"

        • "team"

    • has_more: boolean

      如果当前页之后还有更多记录则为 true。

    • next_page: string

      用于获取下一页结果的不透明游标令牌,如果没有更多页面则为 null。

示例

curl https://api.anthropic.com/v1/organizations/usage_report/claude_code \
    -H 'anthropic-version: 2023-06-01' \
    -H "X-Api-Key: $ANTHROPIC_ADMIN_API_KEY"

响应

{
  "data": [
    {
      "actor": {
        "email_address": "user@emaildomain.com",
        "type": "user_actor"
      },
      "core_metrics": {
        "commits_by_claude_code": 8,
        "lines_of_code": {
          "added": 342,
          "removed": 128
        },
        "num_sessions": 15,
        "pull_requests_by_claude_code": 2
      },
      "customer_type": "api",
      "date": "2025-08-08T00:00:00Z",
      "model_breakdown": [
        {
          "estimated_cost": {
            "amount": 186,
            "currency": "USD"
          },
          "model": "claude-sonnet-4-20250514",
          "tokens": {
            "cache_creation": 2340,
            "cache_read": 8790,
            "input": 45230,
            "output": 12450
          }
        },
        {
          "estimated_cost": {
            "amount": 42,
            "currency": "USD"
          },
          "model": "claude-3-5-haiku-20241022",
          "tokens": {
            "cache_creation": 890,
            "cache_read": 3420,
            "input": 23100,
            "output": 5680
          }
        }
      ],
      "organization_id": "12345678-1234-5678-1234-567812345678",
      "terminal_type": "iTerm.app",
      "tool_actions": {
        "edit_tool": {
          "accepted": 25,
          "rejected": 3
        },
        "multi_edit_tool": {
          "accepted": 12,
          "rejected": 1
        },
        "notebook_edit_tool": {
          "accepted": 5,
          "rejected": 2
        },
        "write_tool": {
          "accepted": 8,
          "rejected": 0
        }
      },
      "subscription_type": "enterprise"
    }
  ],
  "has_more": true,
  "next_page": "page_MjAyNS0wNS0xNFQwMDowMDowMFo="
}