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

# 获取 Agent 产出（代码行数）

> query Devin Desktop 和 Devin CLI 中 Agent 插入和删除的代码行数，以及你的团队接受的代码行数，支持过滤、分组和分页。

<Note>
  这是一个 **v2 端点**，使用 Bearer token 身份验证和 query 参数，而 v1 分析 API 则是在请求体中传入服务密钥。详见下方的[身份验证](#authentication)。
</Note>

<Warning>
  此端点**不**适用于实时用量监控。数据按小时聚合，且速率限制较低 (每个团队每小时 10 次请求) 。请将其用于定期报告和批量导出。
</Warning>

<h2 id="authentication">
  身份验证
</h2>

此端点采用 **Bearer token** 身份验证。请在 `Authorization` 标头中附上你的令牌：

```
Authorization: Bearer <your_token>
```

请使用具有 **Use Local Analytics API** 权限的 Devin 服务用户 API 密钥，或具有 **Analytics Read** 权限的 Windsurf
服务密钥。有关这两种密钥的
创建方法，请参阅[身份验证](/zh/desktop/accounts/api-reference/analytics-v2-introduction#authentication)。

<h2 id="metrics">
  指标
</h2>

`metric` query 参数为必填项，取值为以逗号分隔的指标列表，用于指定要返回的指标。
每个请求的指标都会作为整数字段出现在每一行中：

| 指标 | 描述 |
| - | - |
| `loc_inserted` | 由 Agent 插入且被用户接受的行数 |
| `loc_deleted` | 由 Agent 删除且被用户接受的行数 |

例如，`?metric=loc_inserted,loc_deleted` 会同时返回这两项指标；`?metric=loc_inserted` 则仅返回
`loc_inserted`。如果请求未提供 `metric`，或指定了未知指标，将返回 `400` 错误。

无论使用哪个模型，只要用户在 [Devin Desktop](/zh/desktop/introducing-devin-desktop) 或
[Devin CLI](/zh/cli) 中接受了 Agent 的编辑，相应的行数就会被计入。`product` 参数同样为必填项，目前仅支持
`agent`。

<h2 id="grouping-and-granularity">
  分组与粒度
</h2>

使用 `granularity` 和 `group_by` 控制返回数据的结构：

* **不指定粒度或分组** — 返回整个日期范围的单条聚合行
* **`granularity=daily`** — 每行包含一个 `YYYY-MM-DD` 格式的 `timestamp`
* **`granularity=monthly`** — 每行包含一个 `YYYY-MM` 格式的 `timestamp`
* **`group_by=user`** — 每行包含 `user_id` 和 `user_email`
* **`group_by=session`** — 每行包含一个 `session_id` (即接受这些代码行时所在的 Devin Desktop 对话或 CLI 会话)
* **`group_by=model_uid`** — 每行包含一个 `model_uid`
* **`group_by=ide`** — 每行包含一个 `ide`
* **`group_by=ide,ide_version`** — 每行包含 `ide` 和 `ide_version` (按 `ide_version` 分组时必须同时包含 `ide`)
* **`group_by=os`** — 每行包含一个 `os`，例如 `darwin` (macOS) 、`windows` 或 `linux`
* **`group_by=source`** — 每行包含一个 `source`：`CASCADE_CLIENT` 表示在 Devin Desktop 中接受的代码行，`CHISEL` 表示在 Devin CLI 中接受的代码行 (包括在其他编辑器中作为 Agent 运行的 CLI)

各维度可组合使用，例如 `group_by=user,source,model_uid`。[Get Consumption](/zh/desktop/accounts/api-reference/get-consumption) 中的 `models`、
`group_id` 和 `user_id` 过滤器
在此同样适用。

<h2 id="pagination">
  分页
</h2>

结果以分页形式返回，默认每页 1,000 行 (最多 10,000 行) 。如果还有更多结果，
响应的 `pagination` 对象中会包含 `next_page_cursor`。将其作为 `page_cursor` query
参数传入即可获取下一页，同时须使用与原始请求相同的 `metric` 列表。游标与签发它的
端点及指标绑定；来自 `/consumption` 的游标，或针对不同 `metric` 列表签发的游标，
都会被拒绝并返回 `400`。

页面游标的有效期为 24 小时。获取后续分页的请求不会作为新的 query 计入你的速率限制。

<h2 id="rate-limits">
  速率限制
</h2>

此端点的速率限制为每个团队**每小时 10 次请求**。超出此限制时，
服务器将返回 `429 Too Many Requests`，并附带 `Retry-After` 标头。

对先前的 query 进行分页 (即沿 `next_page_cursor` 继续获取) **不**计入此限制——
只有每份报告的首次 query 才会计入。限制之所以较低，是因为此端点用于
定期报告，而非实时用量监控。


## OpenAPI

````yaml zh/desktop/accounts/api-reference/analytics-v2-openapi.yaml GET /api/v2alpha/analytics/output
openapi: 3.1.0
info:
  title: Devin Desktop Analytics API v2
  version: 2.0.0
  description: |
    分析 API v2 为企业团队提供积分和 ACU 用量、活跃用户以及 Agent 输出
    （已接受的代码行数）分析。数据来自按小时聚合的结果，并支持灵活筛选、分组和基于游标的分页。
servers:
  - url: https://server.codeium.com
security:
  - bearerAuth: []
paths:
  /api/v2alpha/analytics/output:
    get:
      summary: 获取 Agent 输出分析（代码行数）
      description: >
        查询已通过身份验证的团队的 Agent 输出。必填参数 `metric` 用于指定要返回的指标，以逗号分隔：

        `loc_inserted` 和/或 `loc_deleted`，即 Agent 在 Devin Desktop 和 Devin CLI
        中插入或删除、

        并被用户接受的代码行数。

        请求的每个指标都会以整数字段的形式出现在每一行中。结果来自按小时

        聚合的数据，可按日期范围、产品、模型、组和用户进行筛选，分组

        维度与用量相同，另外还支持 `session` 和 `source`（Devin Desktop 或 CLI）。


        这些端点适用于定期报告和批量导出。它们**不**适用于实时用量监控：数据按小时聚合，且速率限制较低（每个团队每小时 10 个请求）。
      operationId: getOutput
      parameters:
        - name: metric
          in: query
          required: true
          schema:
            type: string
          description: |
            要返回的输出指标列表，以逗号分隔；每个指标都会以字段的形式出现在每一行中。支持的指标：
            - `loc_inserted` — Agent 插入且被用户接受的代码行数
            - `loc_deleted` — Agent 删除且被用户接受的代码行数
          example: loc_inserted,loc_deleted
        - name: start_date
          in: query
          required: true
          schema:
            type: string
            format: date
          description: 日期范围的起始日期（含当日），格式为 `YYYY-MM-DD`。
          example: '2026-06-01T00:00:00.000Z'
        - name: end_date
          in: query
          required: true
          schema:
            type: string
            format: date
          description: 日期范围的结束日期（含当日），格式为 `YYYY-MM-DD`。日期范围不得超过 90 天。
          example: '2026-06-30T00:00:00.000Z'
        - name: product
          in: query
          required: true
          schema:
            type: string
            enum:
              - agent
          description: 要查询其输出数据的产品。
          example: agent
        - name: granularity
          in: query
          required: false
          schema:
            type: string
            enum:
              - daily
              - monthly
          description: |
            用于对结果分组的时间粒度。指定后，每行都包含一个 `timestamp` 字段。
            如果省略，则汇总整个日期范围内的结果。
        - name: group_by
          in: query
          required: false
          schema:
            type: string
          description: >
            用于对结果分组的维度列表，以逗号分隔。支持的维度：

            - `user` — 每行包含 `user_id` 和 `user_email`

            - `session` — 每行包含 `session_id`

            - `model_uid` — 每行包含 `model_uid`

            - `ide` — 每行包含 `ide`

            - `ide_version` — 每行包含 `ide_version`；必须同时包含 `ide`

            - `os` — 每行包含 `os`

            - `source` — 每行包含 `source`（Devin Desktop 对应 `CASCADE_CLIENT`，Devin
            CLI 对应 `CHISEL`）
          example: source,model_uid
        - name: models
          in: query
          required: false
          schema:
            type: string
          description: 用于筛选结果的模型 UID 列表，以逗号分隔。
          example: claude-4-sonnet,gpt-4.1
        - name: group_id
          in: query
          required: false
          schema:
            type: string
          description: 仅返回特定组中用户的结果。服务密钥必须具有该组的访问权限。不支持使用 Devin 服务用户 API 密钥。
        - name: user_id
          in: query
          required: false
          schema:
            type: string
          description: 仅返回特定用户（身份验证 UID）的结果。
        - name: page_size
          in: query
          required: false
          schema:
            type: integer
            minimum: 1
            maximum: 10000
            default: 1000
          description: 每页返回的最大行数。
        - name: page_cursor
          in: query
          required: false
          schema:
            type: string
          description: >-
            用于获取下一页的不透明游标，取自上一个响应的 `pagination.next_page_cursor`。请传入与生成该游标的请求相同的
            `metric` 列表；由其他端点生成或针对不同 `metric` 列表生成的游标将被拒绝。
      responses:
        '200':
          description: 已成功返回输出数据。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OutputResponse'
              examples:
                by_source:
                  summary: 按客户端统计的每日代码行数
                  value:
                    data:
                      - timestamp: '2026-06-15T00:00:00.000Z'
                        source: CASCADE_CLIENT
                        loc_inserted: 18420
                        loc_deleted: 3105
                      - timestamp: '2026-06-15T00:00:00.000Z'
                        source: CHISEL
                        loc_inserted: 92310
                        loc_deleted: 11874
                    pagination:
                      next_page_cursor: null
                    metadata:
                      data_freshness: '2026-06-16T03:00:00.000Z'
                      query_time_ms: 1311
                      team_id: team_abc123
                by_user_model:
                  summary: metric=loc_inserted 按用户和模型分组
                  value:
                    data:
                      - user_id: user_abc123
                        user_email: alice@example.com
                        model_uid: claude-4-sonnet
                        loc_inserted: 4210
                    pagination:
                      next_page_cursor: null
                    metadata:
                      data_freshness: '2026-06-16T03:00:00.000Z'
                      query_time_ms: 980
                      team_id: team_abc123
        '400':
          description: 请求参数无效。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              examples:
                missing_metric:
                  value:
                    error: metric is required
                bad_metric:
                  value:
                    error: >-
                      unsupported metric: acus (supported: loc_inserted,
                      loc_deleted)
                missing_product:
                  value:
                    error: product is required
                bad_group_by:
                  value:
                    error: 'unsupported group_by dimension for output: foobar'
        '401':
          description: 身份验证失败或权限不足。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              examples:
                missing_auth:
                  value:
                    error: missing Authorization header
                invalid_key:
                  value:
                    error: invalid service key
                insufficient_permissions:
                  value:
                    error: insufficient permissions
        '403':
          description: 提供的页面游标不属于已通过身份验证的团队或所请求的组。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              examples:
                cursor_team_mismatch:
                  value:
                    error: page cursor does not belong to this team
        '405':
          description: 不允许使用此 HTTP 方法（仅支持 `GET`）。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '429':
          description: 已超出速率限制（每个团队每小时 10 次请求）。对先前 query 的分页请求不计入此限制。
          headers:
            Retry-After:
              schema:
                type: string
              description: 建议在重试前等待的时间。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              examples:
                rate_limited:
                  value:
                    error: rate limit exceeded
        '503':
          description: 分析服务不可用（例如在自托管部署中）。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
      security:
        - bearerAuth: []
components:
  schemas:
    OutputResponse:
      type: object
      required:
        - data
        - pagination
        - metadata
      properties:
        data:
          type: array
          items:
            $ref: '#/components/schemas/OutputRow'
          description: 由输出数据行组成的数组。
        pagination:
          type: object
          properties:
            next_page_cursor:
              type:
                - string
                - 'null'
              description: |
                用于获取下一页结果的不透明游标。在后续请求中，将此值作为 `page_cursor`
                query 参数传入。没有更多页面时为 `null`。
                页面游标在 24 小时后过期。
        metadata:
          type: object
          properties:
            data_freshness:
              type: string
              format: date-time
              description: 底层数据最近一次刷新的时间戳（截断至整点）。
            query_time_ms:
              type: integer
              format: int64
              description: 服务端 query 执行耗时，单位为毫秒。
            team_id:
              type: string
              description: 从已通过身份验证的服务密钥解析出的团队 ID。
            group_id:
              type: string
              description: 结果所属的组 ID。仅当提供了 `group_id` 时返回。
    Error:
      type: object
      required:
        - error
      properties:
        error:
          type: string
          description: 便于人工阅读的错误消息。
    OutputRow:
      type: object
      properties:
        timestamp:
          type: string
          description: |
            该行对应的时间桶。格式取决于 `granularity`：按日为 `YYYY-MM-DD`，按月为 `YYYY-MM`。
            仅在指定 `granularity` 时返回。
          examples:
            - '2026-05-01T00:00:00.000Z'
            - 2026-05
        user_id:
          type: string
          description: 用户标识符（身份验证 UID）。仅在 `group_by` 包含 `user` 时返回。
        user_email:
          type: string
          description: 用户的电子邮件地址。仅在 `group_by` 包含 `user` 时返回。
          examples:
            - alice@example.com
        session_id:
          type: string
          description: Devin Desktop 对话或 Devin CLI 会话的标识符。仅在 `group_by` 包含 `session` 时返回。
        model_uid:
          type: string
          description: 模型标识符。仅在 `group_by` 包含 `model_uid` 时返回。
          examples:
            - claude-4-sonnet
        ide:
          type: string
          description: IDE 名称。仅在 `group_by` 包含 `ide` 时返回。
          examples:
            - windsurf
            - devin-cli
        ide_version:
          type: string
          description: IDE 版本。仅在 `group_by` 包含 `ide_version`（同时还需包含 `ide`）时返回。
          examples:
            - 1.0.0
        os:
          type: string
          description: 发起请求的操作系统。仅在 `group_by` 包含 `os` 时返回。
          examples:
            - darwin
            - windows
            - linux
        source:
          type: string
          enum:
            - CASCADE_CLIENT
            - CHISEL
          description: >
            用户接受代码行时使用的客户端：Devin Desktop 对应 `CASCADE_CLIENT`，Devin CLI 对应
            `CHISEL`

            （包括在其他编辑器中作为 Agent 运行的 CLI）。仅在 `group_by` 包含 `source` 时返回。
        loc_inserted:
          type: integer
          format: int64
          description: Agent 插入且用户已接受的代码行。仅当 `metric` 包含 `loc_inserted` 时返回。
        loc_deleted:
          type: integer
          format: int64
          description: Agent 删除且用户已接受的代码行。仅当 `metric` 包含 `loc_deleted` 时返回。
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >
        需要一个具有 **Analytics Read** 权限的服务密钥，并通过 `Authorization` 标头以 Bearer
        令牌的形式传递。


        你可以在[团队设置](https://windsurf.com/team/settings)中的“Service Keys”部分创建服务密钥。

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.