TRAE 企业版获取部门的 AI 使用数据

2026-12-02 18:35 更新

获取指定时间范围内,指定部门的 AI 使用数据汇总与逐日数据。

所需权限

statistics:read

请求说明

  • 请求方式:POST
  • 请求地址:{域名}/openapi/v1/statistics/department-metrics

注意事项

  • 统计数据按照用量发生时的部门归属聚合。成员变更部门后,变更前的数据仍归属原部门;同一天内变更部门时,当日数据归入新部门。
  • 时间跨度最长为 180 天。

请求参数

请求头参数

Header 参数 是否必填 描述
Authorization 是 固定取值为 Bearer {access_token}。关于如何获取访问令牌,参考鉴权。
Content-Type 是 固定取值为 application/json。

请求体参数

参数 类型 是否必填 默认值 描述
start_date string 是 - 开始日期。格式:YYYY-MM-DD。
end_date string 是 - 结束日期。格式:YYYY-MM-DD。
timezone string 否 "Asia/Shanghai" 时区。需使用 IANA 时区名称。
department_ids string[] 是 - 目标部门的 ID 列表。范围为 1 至 100 个。
部门 ID 可以通过 “获取单个父部门的子部门” 接口或 ”按关键词搜索部门“ 接口获取。
include_subtree bool 否 true 是否返回目标部门的所有后代部门的数据:
- true / null / 省略:包含目标部门的所有后代部门的数据
- false:仅包含目标部门的数据

响应参数

响应数据按部门维度组织,返回每个指定部门各自的 AI 使用数据。

参数 类型 描述
departments array 部门维度的结果列表。
departments[].department_id string 部门的 ID,以十进制字符串返回。
departments[].department_name string 部门的名称。
departments[].full_path string 部门的完整归属路径。各级部门名称以 / 分隔。
departments[].metrics object 部门在统计周期内的汇总数据。
departments[].daily_trend array 部门的逐日数据。

metrics 对象和 daily_trend 数组中的每个对象包含以下参数(date 仅在逐日数据中返回):

参数 类型 描述
date string 日期。格式:YYYY-MM-DD。该参数为 daily_trend 数组独有。
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。
ai_commit_lines int64 AI 生成的代码被提交到仓库的总行数。
数据来源:TRAE、TRAE Plugin。
non_ai_commit_lines int64 非 AI 生成的代码被提交到仓库的总行数。
数据来源:TRAE、TRAE Plugin。
total_commit_lines int64 提交到仓库的总代码行数。
数据来源:TRAE、TRAE Plugin。
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 中产生的问答次数。
cli_code_accept_lines int64 在 TRAE CLI 中,AI 生成的代码被采纳的总行数。CLI 中推荐即采纳,因此该值也等于 CLI 推荐的代码行数。
数据来源:TRAE CLI(0.218.0 及以上版本)。
work_requests int64 在 TraeWork 桌面版与网页版,以及 TRAE 移动端中产生的问答次数。
total_code_gen_lines int64 TRAE、TRAE Plugin 中 Agent 和 CUE 推荐的代码行数,加上 TRAE CLI 采纳的代码行数。
计算公式:agent_code_gen_lines + cue_code_gen_lines + cli_code_accept_lines。
数据来源:TRAE、TRAE Plugin、TRAE CLI(0.218.0 及以上版本)。
total_code_accept_lines int64 TRAE、TRAE Plugin 中 Agent 和 CUE 推荐且被采纳的代码行数,加上 TRAE CLI 采纳的代码行数。
计算公式:agent_code_accept_lines + cue_code_accept_lines + cli_code_accept_lines。
数据来源:TRAE、TRAE Plugin、TRAE CLI(0.218.0 及以上版本)。
agent_code_gen_lines int64 Agent 推荐代码行数。
数据来源:TRAE、TRAE Plugin。
agent_code_accept_lines int64 Agent 采纳代码行数。
数据来源:TRAE、TRAE Plugin。
cue_code_gen_lines int64 CUE 推荐代码行数。
数据来源:TRAE、TRAE Plugin。
cue_code_accept_lines int64 CUE 采纳代码行数。
数据来源:TRAE、TRAE Plugin。

示例

请求示例

curl -X POST "${HOST}/openapi/v1/statistics/department-metrics"
  -H "Authorization: Bearer ${ACCESS_TOKEN}"
  -H "Content-Type: application/json"
  -d '{
    "start_date": "2026-08-01",
    "end_date": "2026-08-15",
    "department_ids": [
      "20001"
    ],
    "include_subtree": false
  }'

响应示例

{
  "code": 0,
  "message": "success",
  "request_id": "req_xxx",
  "data": {
    "departments": [
      {
        "department_id": "10001",
        "department_name": "研发部",
        "full_path": "公司/研发部",
        "metrics": {
          "ai_generation_rate": 0.68,
          "ai_contribution_rate": 0.42,
          "ai_generated_code_lines": 12000,
          "chat_code_gen_lines": 8600,
          "chat_code_accept_lines": 5200,
          "cue_recommend_count": 3400,
          "cue_recommend_accepted": 2100,
          "ai_commit_lines": 7600,
          "non_ai_commit_lines": 10400,
          "total_commit_lines": 18000,
          "total_requests": 9800,
          "chat_requests": 6200,
          "agent_requests": 2300,
          "agent_accepted_requests": 1500,
          "cli_requests": 900,
          "cli_code_accept_lines": 600,
          "work_requests": 400,
          "total_code_gen_lines": 12600,
          "total_code_accept_lines": 8400,
          "agent_code_gen_lines": 8000,
          "agent_code_accept_lines": 5200,
          "cue_code_gen_lines": 4000,
          "cue_code_accept_lines": 2600
        },
        "daily_trend": [
          {
            "date": "2026-08-01",
            "ai_generation_rate": 0.65,
            "ai_contribution_rate": 0.4,
            "ai_generated_code_lines": 420,
            "chat_code_gen_lines": 300,
            "chat_code_accept_lines": 180,
            "cue_recommend_count": 120,
            "cue_recommend_accepted": 80,
            "ai_commit_lines": 260,
            "non_ai_commit_lines": 390,
            "total_commit_lines": 650,
            "total_requests": 360,
            "chat_requests": 220,
            "agent_requests": 90,
            "agent_accepted_requests": 60,
            "cli_requests": 35,
            "cli_code_accept_lines": 25,
            "work_requests": 15,
            "total_code_gen_lines": 445,
            "total_code_accept_lines": 285,
            "agent_code_gen_lines": 300,
            "agent_code_accept_lines": 180,
            "cue_code_gen_lines": 120,
            "cue_code_accept_lines": 80
          }
        ]
      }
    ]
  }
}

错误码

若该接口的请求返回错误码,参考错误码文档进行排查。

编程狮笔记

  • 获取指定时间范围内,指定部门的 AI 使用数据汇总与逐日数据。

  • 请求地址:{域名}/openapi/v1/statistics/department-metrics…
  • 统计数据按照用量发生时的部门归属聚合。成员变更部门后,变更前的数据仍归属原部门;同一天内变更部门时,当日数据归入新部门。
  • 时间跨度最长为 180 天。

来源:TRAE 企业版获取部门的 AI 使用数据 - TRAE 官方文档

想直接上手体验 TRAE:TRAE 官网

以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号