> ## 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 代码贡献数据。

## 所需权限 {#所需权限}

`statistics`

## 请求说明 {#请求说明}

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

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

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

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

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

<!-- @cols-width: 163,112,100,151,379 -->
| **参数**  | **类型**  | **是否必填**  | **默认值**  | **描述**  |
| --- | --- | --- | --- | --- |
| `start_date`  | string  | 是  | \-  | 开始日期。格式：YYYY-MM-DD。  |
| `end_date`  | string  | 是  | \-  | 结束日期。格式：YYYY-MM-DD。  |
| `timezone`  | string  | 否  | `"Asia/Shanghai"`  | 时区。需使用 IANA 时区名称。  |
| `repo_urls`  | string[]  | 否  | \-  | 仓库 URL 列表，用于筛选指定仓库。最多传入 100 个。未传入时，查询范围包括企业下的所有仓库。  |
| `commit_ids`  | string[]  | 否  | \-  | 提交 ID 列表，用于筛选指定提交记录。  |
| `emails`  | string[]  | 否  | \-  | 提交者邮箱列表，用于筛选指定提交者。最多传入 100 个。  |
| `page`  | int  | 否  | `1`  | 页码。  |
| `page_size`  | int  | 否  | `100`  | 每页数量，最大为 500。  |

## 响应参数 {#响应参数}

以下为该接口特有的响应参数。通用响应参数参考[通用响应格式](/enterprise_general-response-schema)。

<!-- @cols-width: 274,142,482 -->
| **参数**  | **类型**  | **描述**  |
| --- | --- | --- |
| `data.items`  | array  | 按提交记录维度返回的查询结果。  |
| `data.items[].commit_id`  | string  | 提交哈希。  |
| `data.items[].repo_url`  | string  | 仓库 URL。  |
| `data.items[].email`  | string  | 提交者邮箱。  |
| `data.items[].user_id`  | int64  | 成员的 ID。  |
| `data.items[].commit_time`  | int64  | 提交时间，以 Unix 毫秒时间戳表示。  |
| `data.items[].ai_commit_lines`  | int64  | 该提交中由 AI 生成的代码行数。  |
| `data.items[].non_ai_commit_lines`  | int64  | 该提交中非 AI 生成的代码行数。  |
| `data.items[].total_commit_lines`  | int64  | 该提交包含的代码总行数，即 `ai_commit_lines` 与 `non_ai_commit_lines` 之和。  |
| `data.items[].ai_contribution_rate`  | float64  | 该提交的 AI 代码贡献率（%）。计算公式：`ai_commit_lines` ÷ `total_commit_lines` × 100%。  |

## 示例 {#示例}

### 请求示例 {#请求示例}

```JSON
curl -X POST "${HOST}/openapi/v1/statistics/commit-metrics" \
  -H "Authorization: Bearer ${ACCESS_TOKEN}" \
  -H "Content-Type: application/json" \
  -d '{
    "start_date": "2026-08-01",
    "end_date": "2026-08-07",
    "repo_urls": ["https://git.example.com/org/trae-server"],
    "commit_ids": ["a1b2c3d4e5f60789xxxxxx1234567890abcdef12"],
    "emails": ["name@example.com"],
    "page": 1,
    "page_size": 100
  }'
```

### 响应示例 {#响应示例}

```JSON
{
  "code": 0,
  "message": "success",
  "request_id": "req_abc123xyz", 
  "data": {
    "items": [
      {
        "commit_id": "a1b2c3d4e5f60789xxxxxx1234567890abcdef12",
        "repo_url": "https://git.example.com/org/trae-server",
        "user_id": 12314124,
        "email": "name@example.com",
        "commit_time": 1737000000000,
        "ai_commit_lines": 128,
        "non_ai_commit_lines": 32,
        "total_commit_lines": 160,
        "ai_contribution_rate": 80.0
      }
    ],
    "pagination": {
      "page": 1,
      "page_size": 100,
      "total": 356,
      "total_pages": 4
    }
  }
}
```

## 错误码 {#错误码}

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