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

获取指定时间范围内，企业整体的 AI 使用数据汇总与逐日数据。

## 所需权限 {#8b842c37}

`statistics:read`

## 请求说明 {#87e36d3a}

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

## 注意事项 {#hQUSz4c7v}

时间跨度最长为 180 天。

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

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

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

### 查询参数 {#6e7f87d1}

<!-- @cols-width: 174,103,100,143,347 -->
| **参数**  | **类型**  | **是否必填**  | **默认值**  | **描述**  |
| --- | --- | --- | --- | --- |
| `start_date`  | string  | 是  | \-  | 开始日期。格式：YYYY-MM-DD。  |
| `end_date`  | string  | 是  | \-  | 结束日期。格式：YYYY-MM-DD。  |
| `timezone`  | string  | 否  | `"Asia/Shanghai"`  | 时区。需使用 IANA 时区名称。  |
| `use_git_ai`  | bool  | 否  | `false`  | 是否按 Git AI 统计口径返回代码贡献数据： | \
| | | | | | \
| | | | | * `true`：按 Git AI 统计口径返回数据 | \
| | | | | * `false`：按原有统计口径返回数据  |

## 响应参数 {#e8918474}

该接口独有的响应参数如下，参数位于 `data` 中。通用响应参数参考[此文档](/enterprise_general-response-schema)。

<!-- @cols-width: 176,148,547 -->
| **参数**  | **类型**  | **描述**  |
| --- | --- | --- |
| `metrics`  | object  | 时间范围内的整体汇总数据。  |
| `daily_trend`  | array  | 按天拆分的逐日数据。  |

`metrics` 对象和 `daily_trend` 数组中共同包含以下参数：

<!-- @cols-width: 248,100,524 -->
| **参数**  | **类型**  | **描述**  |
| --- | --- | --- |
| `ai_generation_rate`  | float64  | AI 生成代码在总代码产出中的占比（%）。 | \
| | | | \
| | | ***计算公式***：（`ai_generated_code_lines` ÷ 期间内生成的总代码行数）× 100%。 | \
| | | | \
| | | ***数据来源***：TRAE、TRAE Plugin。  |
| `ai_contribution_rate`  | float64  | AI 代码贡献率。表示最终提交到仓库的代码中，AI 生成代码的占比（%）。 | \
| | | | \
| | | ***计算公式***：（`ai_commit_lines` ÷ `total_commit_lines`）× 100%。 | \
| | | | \
| | | ***数据来源***：TRAE、TRAE Plugin。  |
| `ai_generated_code_lines`  | int64  | 在问答和自动补全功能中，AI 生成的代码总行数。 | \
| | | | \
| | | ***数据来源***：TRAE、TRAE Plugin。  |
| `chat_code_gen_lines`  | int64  | 在问答功能中，AI 生成的总代码行数。 | \
| | | | \
| | | ***数据来源***：TRAE、TRAE Plugin。  |
| `chat_code_accept_lines`  | int64  | 在问答功能中，AI 生成的代码被采纳的总行数。 | \
| | | | \
| | | ***数据来源***：TRAE、TRAE Plugin。  |
| `cue_recommend_count`  | int64  | CUE 提供代码建议的总次数。 | \
| | | | \
| | | ***数据来源***：TRAE、TRAE Plugin。  |
| `cue_recommend_accepted`  | int64  | CUE 提供的代码建议被采纳的总次数。 | \
| | | | \
| | | ***数据来源***：TRAE、TRAE Plugin。  |
| `cue_code_gen_lines`  | int64  | CUE 提供的代码建议所包含的总代码行数。 | \
| | | | \
| | | ***数据来源***：TRAE、TRAE Plugin。  |
| `cue_code_accept_lines`  | int64  | CUE 提供且被采纳的代码建议所包含的总代码行数。 | \
| | | | \
| | | ***数据来源***：TRAE、TRAE Plugin。  |
| `ai_commit_lines`  | int64  | AI 生成的代码被提交到仓库的总行数。 | \
| | | | \
| | | ***数据来源***：TRAE、TRAE Plugin。  |
| `non_ai_commit_lines`  | int64  | 非 AI 生成的代码被提交到仓库的总行数。 | \
| | | | \
| | | ***数据来源***：TRAE、TRAE Plugin。  |
| `total_commit_lines`  | int64  | 提交到仓库的总代码行数。 | \
| | | | \
| | | ***数据来源***：TRAE、TRAE Plugin。  |

`ai_commit_lines`、`non_ai_commit_lines` 和 `total_commit_lines` 按以下规则统计：

* 查询时间范围内仅包含按原有口径上报的数据时，按原有口径计算。
* 查询时间范围内同时包含两种口径的数据时，聚合后再计算。例如，前三天按原有口径上报、从第四天起按 Git AI 口径上报时，响应结果会聚合整个查询时间范围内的数据。

除上述参数外，`daily_trend` 数组中额外包含以下参数：

<!-- @cols-width: 209,100,564 -->
| **参数**  | **类型**  | **描述**  |
| --- | --- | --- |
| `date`  | string  | 日期。格式：YYYY-MM-DD。  |
| `total_requests`  | int64  | 总问答次数。 | \
| | | | \
| | | ***数据来源***：TRAE、TRAE Plugin、TRAE CLI、TraeWork 桌面版与网页版、TRAE 移动端。  |
| `chat_requests`  | int64  | 与内置智能体 “Chat” 产生的问答次数。 | \
| | | | \
| | | ***数据来源***：TRAE、TRAE Plugin。  |
| `agent_requests`  | int64  | 含以下两部分指标： | \
| | | | \
| | | * 在 TRAE 中，与内置智能体 “Agent” 与 “SOLO Agent”，以及自定义智能体产生的问答次数。 | \
| | | * 在 TRAE Plugin 中，与内置智能体 “Agent” 与自定义智能体产生的问答次数。  |
| `agent_accepted_requests`  | int64  | 含以下两部分指标： | \
| | | | \
| | | * 在 TRAE 中，内置智能体 “Agent” 与 “SOLO Agent”，以及自定义智能体的输出被采纳的次数。 | \
| | | * 在 TRAE Plugin 中，内置智能体 “Agent” 与自定义智能体的输出被采纳的次数。  |
| `cli_requests`  | int64  | 在 TRAE CLI 中产生的问答次数。  |
| `work_requests`  | int64  | 在 TraeWork 桌面版与网页版，以及 TRAE 移动端中产生的问答次数。  |

## 示例 {#示例}

### 请求示例 {#c16fdbbc}

```Bash
curl -X GET "${HOST}/openapi/v1/statistics/core-metrics?start_date=2026-08-01&end_date=2026-08-01&use_git_ai=true" \
  -H "Authorization: Bearer ${ACCESS_TOKEN}"
```

### 响应示例 {#4638c3c5}

以下示例仅查询 2026-08-01，因此 `metrics` 与 `daily_trend` 中当天的对应指标一致。假设当天生成的总代码为 20000 行，其中 AI 生成 8000 行，则 `ai_generation_rate` 为 `40`（即 40%）。

```JSON
{
  "code": 0,
  "message": "success",
  "request_id": "req_xxx",
  "data": {
    "metrics": {
      "ai_generation_rate": 40,
      "ai_contribution_rate": 31.25,
      "ai_generated_code_lines": 8000,
      "chat_code_gen_lines": 5200,
      "chat_code_accept_lines": 3400,
      "cue_recommend_count": 2000,
      "cue_recommend_accepted": 900,
      "cue_code_gen_lines": 2800,
      "cue_code_accept_lines": 1260,
      "ai_commit_lines": 2000,
      "non_ai_commit_lines": 4400,
      "total_commit_lines": 6400
    },
    "daily_trend": [
      {
        "date": "2026-08-01",
        "ai_generation_rate": 40,
        "ai_contribution_rate": 31.25,
        "ai_generated_code_lines": 8000,
        "chat_code_gen_lines": 5200,
        "chat_code_accept_lines": 3400,
        "cue_recommend_count": 2000,
        "cue_recommend_accepted": 900,
        "cue_code_gen_lines": 2800,
        "cue_code_accept_lines": 1260,
        "ai_commit_lines": 2000,
        "non_ai_commit_lines": 4400,
        "total_commit_lines": 6400,
        "total_requests": 12000,
        "chat_requests": 7000,
        "agent_requests": 4000,
        "agent_accepted_requests": 2600,
        "cli_requests": 600,
        "work_requests": 400
      }
    ]
  }
}
```

## 错误码 {#错误码}

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


