> ## Documentation Index
> Fetch the complete documentation index at: https://docs.trae.cn/llms.txt?lang=zh
> Use this file to discover all available pages before exploring further.

获取指定时间范围内，指定成员的 AI 使用数据汇总与逐日趋势。

## 所需权限 {#bffd8534}

`statistics:read`

## 请求说明 {#fe3b5d5d}

* 请求方式：`POST`
* 请求地址：`{域名}/openapi/v1/statistics/user-metrics`

## 注意事项 {#htCOyoQu1}


* 时间跨度最长为 180 天。
* `user_ids` 与 `emails` 至少传入一个。系统会分别去除重复的成员 ID 和邮箱；去重后，两个数组的元素总数不得超过 100。同一成员同时通过 ID 和邮箱传入时，仍按两个元素计数，但响应中该成员只返回一次。

## 请求参数 {#请求参数}

### 请求头参数 {#请求头参数}

<!-- @cols-width: 172,122,596 -->
| **Header 参数**  | **是否必填**  | **描述**  |
| --- | --- | --- |
| `Authorization`  | 是  | 固定取值为 `Bearer {access_token}`。关于如何获取访问令牌，参考[鉴权](enterprise_authentication)。  |
| `Content-Type`  | 是  | 固定取值为 `application/json`。  |

### 请求体参数 {#65b506a9}

<!-- @cols-width: 143,120,100,159,393 -->
| **参数**  | **类型**  | **是否必填**  | **默认值**  | **描述**  |
| --- | --- | --- | --- | --- |
| `start_date`  | string  | 是  | \-  | 开始日期。格式：YYYY-MM-DD。  |
| `end_date`  | string  | 是  | \-  | 结束日期。格式：YYYY-MM-DD。  |
| `timezone`  | string  | 否  | `"Asia/Shanghai"`  | 时区。需使用 IANA 时区名称。  |
| `user_ids`  | string[]  | 条件必填  | \-  | 目标成员的 ID。与 `emails` 至少传一个。 | \
| | | | | | \
| | | | | 成员的 ID 可以通过 “[获取成员列表](/enterprise_get-user-list)” 接口获取。  |
| `emails`  | string[]  | 条件必填  | \-  | 目标成员的邮箱。与 `user_ids` 至少传一个。 | \
| | | | | | \
| | | | | 成员的邮箱可以通过 “[获取成员列表](/enterprise_get-user-list)” 接口获取。  |

## 响应参数 {#cd88df11}

响应数据按成员维度组织，返回每位指定成员各自的 AI 使用数据。

<!-- @cols-width: 244,180,490 -->
| **参数**  | **类型**  | **描述**  |
| --- | --- | --- |
| `users`  | array  | 成员维度的结果列表。  |
| `users[].user_id`  | int64  | 成员的 ID。  |
| `users[].user_id_str`  | string  | 成员 ID 的字符串形式。  |
| `users[].email`  | string  | 成员的邮箱。  |
| `users[].account_type`  | int  | 成员的账号类型，`1` 表示全端账号，`2` 表示 Work 专属账号。  |
| `users[].metrics`  | object  | 成员在时间范围内的整体汇总数据。  |
| `users[].daily_trend`  | array  | 成员的逐日数据。  |

`metrics` 对象和 `daily_trend` 数组包含的参数如下：

<!-- @cols-width: 244,180,488 -->
| **参数**  | **类型**  | **描述**  |
| --- | --- | --- |
| `date`  | string  | 日期。格式：YYYY-MM-DD。该参数为 `daily_trend` 数组独有。  |
| `ai_generation_rate`  | float64  | AI 生成代码在总代码产出中的占比（%）。 | \
| | | | \
| | | ***计算公式***：（`ai_generated_code_lines` ÷ 期间内生成的总代码行数）× 100%。 | \
| | | | \
| | | ***数据来源***：TraeCode、TraeCode Plugin。  |
| `ai_contribution_rate`  | float64  | AI 代码贡献率。表示最终提交到仓库的代码中，AI 生成代码的占比（%）。 | \
| | | | \
| | | ***计算公式***：（`ai_commit_lines` ÷ `total_commit_lines`）× 100%。 | \
| | | | \
| | | ***数据来源***：TraeCode、TraeCode Plugin。  |
| `ai_generated_code_lines`  | int64  | 在问答和自动补全功能中，AI 生成的代码总行数。 | \
| | | | \
| | | ***数据来源***：TraeCode、TraeCode Plugin。  |
| `chat_code_gen_lines`  | int64  | 在问答功能中，AI 生成的总代码行数。 | \
| | | | \
| | | ***数据来源***：TraeCode、TraeCode Plugin。  |
| `chat_code_accept_lines`  | int64  | 在问答功能中，AI 生成的代码被采纳的总行数。 | \
| | | | \
| | | ***数据来源***：TraeCode、TraeCode Plugin。  |
| `cue_recommend_count`  | int64  | CUE 提供代码建议的总次数。 | \
| | | | \
| | | ***数据来源***：TraeCode、TraeCode Plugin。  |
| `cue_recommend_accepted`  | int64  | CUE 提供的代码建议被采纳的总次数。 | \
| | | | \
| | | ***数据来源***：TraeCode、TraeCode Plugin。  |
| `ai_commit_lines`  | int64  | AI 生成的代码被提交到仓库的总行数。 | \
| | | | \
| | | ***数据来源***：TraeCode、TraeCode Plugin。  |
| `non_ai_commit_lines`  | int64  | 非 AI 生成的代码被提交到仓库的总行数。 | \
| | | | \
| | | ***数据来源***：TraeCode、TraeCode Plugin。  |
| `total_commit_lines`  | int64  | 提交到仓库的总代码行数。 | \
| | | | \
| | | ***数据来源***：TraeCode、TraeCode Plugin。  |
| `total_requests`  | int64  | 总问答次数。 | \
| | | | \
| | | ***数据来源***：TraeCode、TraeCode Plugin、TraeCode CLI、TraeWork 桌面版与网页版、TRAE 移动端。  |
| `chat_requests`  | int64  | 与内置智能体 “Chat” 产生的问答次数。 | \
| | | | \
| | | ***数据来源***：TraeCode、TraeCode Plugin。  |
| `agent_requests`  | int64  | 含以下两部分指标： | \
| | | | \
| | | * 在 TraeCode 中，与内置智能体 “Agent” 与 “SOLO Agent”，以及自定义智能体产生的问答次数。 | \
| | | * 在 TraeCode Plugin 中，与内置智能体 “Agent” 与自定义智能体产生的问答次数。  |
| `agent_accepted_requests`  | int64  | 含以下两部分指标： | \
| | | | \
| | | * 在 TraeCode 中，内置智能体 “Agent” 与 “SOLO Agent”，以及自定义智能体的输出被采纳的次数。 | \
| | | * 在 TraeCode Plugin 中，内置智能体 “Agent” 与自定义智能体的输出被采纳的次数。  |
| `cli_requests`  | int64  | 在 TraeCode CLI 中产生的问答次数。  |
| `work_requests`  | int64  | 在 TraeWork 桌面版与网页版，以及 TRAE 移动端中产生的问答次数。  |

## 示例 {#示例}

### 请求示例 {#9a726557}

```Bash
curl -X POST "${HOST}/openapi/v1/statistics/user-metrics" \
  -H "Authorization: Bearer ${ACCESS_TOKEN}" \
  -H "Content-Type: application/json" \
  -d '{
    "start_date": "2026-08-01",
    "end_date": "2026-08-02",
    "user_ids": ["123456"]
  }'
```

### 响应示例 {#7df3e269}

```JSON
{
  "code": 0,
  "message": "success",
  "request_id": "req_abc123xyz",
  "data": {
    "users": [
      {
        "user_id": 123456,
        "user_id_str": "123456",
        "email": "name@example.com",
        "account_type": 1,
        "metrics": {
          "ai_generation_rate": 35.5,
          "ai_contribution_rate": 22,
          "ai_generated_code_lines": 120000,
          "chat_code_gen_lines": 500,
          "chat_code_accept_lines": 350,
          "cue_recommend_count": 50000,
          "cue_recommend_accepted": 150,
          "ai_commit_lines": 10000,
          "non_ai_commit_lines": 10000,
          "total_commit_lines": 20000,
          "total_requests":5,
          "chat_requests":2,
          "agent_requests":3,
          "agent_accepted_requests":1,
          "cli_requests":1,
          "work_requests":1
        },
        "daily_trend": [
          {
            "date": "2026-08-01",
            "ai_generation_rate": 25.5,
            "ai_contribution_rate": 18,
            "ai_generated_code_lines": 5000,
            "chat_code_gen_lines": 130,
            "chat_code_accept_lines": 100,
            "cue_recommend_count": 60,
            "cue_recommend_accepted": 30,
            "ai_commit_lines": 1000,
            "non_ai_commit_lines": 1000,
            "total_commit_lines": 2000,
            "total_requests":5,
            "chat_requests":2,
            "agent_requests":3,
            "agent_accepted_requests":1,
            "cli_requests":1,
            "work_requests":1
          }
        ]
      }
    ]
  }
}
```

## 错误码 {#错误码}

若该接口的请求返回错误码，参考[错误码](/enterprise_error-codes)文档进行排查。
