> ## 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 使用数据汇总与逐日数据。

## 所需权限 {#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 时区名称。  |

## 响应参数 {#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%。 | \
| | | | \
| | | ***数据来源***：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。  |

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

<!-- @cols-width: 209,100,564 -->
| **参数**  | **类型**  | **描述**  |
| --- | --- | --- |
| `date`  | string  | 日期。格式：YYYY-MM-DD。  |
| `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 移动端中产生的问答次数。  |

## 示例 {#示例}

### 请求示例 {#c16fdbbc}

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

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

```JSON
{
  "code": 0,
  "message": "success",
  "request_id": "req_xxx",
  "data": {
    "metrics": {
      "ai_generation_rate": 0.42,
      "ai_contribution_rate": 0.31,
      "ai_generated_code_lines": 120000,
      "chat_code_gen_lines": 80000,
      "chat_code_accept_lines": 52000,
      "cue_recommend_count": 90000,
      "cue_recommend_accepted": 41000,
      "ai_commit_lines": 30000,
      "non_ai_commit_lines": 66000,
      "total_commit_lines": 96000
    },
    "daily_trend": [
      {
        "date": "2026-08-01",
        "ai_generation_rate": 0.4,
        "ai_contribution_rate": 0.3,
        "ai_generated_code_lines": 8000,
        "chat_code_gen_lines": 5200,
        "chat_code_accept_lines": 3400,
        "cue_recommend_count": 6000,
        "cue_recommend_accepted": 2700,
        "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)文档进行排查。
