API / get-ai-code-change-metrics-via-api

API

Get AI code change metrics with the AI Code Tracking API

Retrieve granular accepted AI changes, grouped by deterministic changeId, with GET https://api.cursor.com/analytics/ai-code/changes. Use this when you need accepted AI events independent of commits. Official reference: AI Code Tracking API → Get AI Code Change Metrics.

Authenticate with a team API key (Basic auth, key as username, empty password — same method as the Admin API). Create keys at cursor.com/dashboard → API Keys with scope admin:*. Availability: Enterprise only (contact sales for access). Status: Alpha — response shapes and fields may change. Rate limit: 20 requests per minute per endpoint. Metrics cover the git repository at the top level of the workspace root; multi-root workspaces are unsupported.

Query parameters

Parameter Rules
startDate ISO date, now, or relative days such as 7d. Default: now − 7 days
endDate ISO date, now, or relative days such as 0d. Default: now
page 1-based page number. Default: 1
pageSize Results per page. Default: 100, max: 1000
user Optional single-user filter: email, encoded id (user_…), or numeric id

Request (JSON)

curl -X GET "https://api.cursor.com/analytics/ai-code/changes?startDate=14d&endDate=now&page=1&pageSize=200" \
  -u YOUR_API_KEY:

Example response:

{
  "items": [
    {
      "changeId": "749356201",
      "userId": "user_3k9x8q...",
      "userEmail": "developer@company.com",
      "source": "COMPOSER",
      "model": null,
      "totalLinesAdded": 18,
      "totalLinesDeleted": 4,
      "createdAt": "2025-07-30T15:10:12.000Z",
      "metadata": [
        {
          "fileName": "src/analytics/report.ts",
          "fileExtension": "ts",
          "linesAdded": 12,
          "linesDeleted": 3
        },
        {
          "fileName": "src/analytics/ui.tsx",
          "fileExtension": "tsx",
          "linesAdded": 6,
          "linesDeleted": 1
        }
      ]
    }
  ],
  "totalCount": 128,
  "page": 1,
  "pageSize": 200
}

Response fields

Field Type Meaning
changeId string Deterministic id for the accepted change
userId string Encoded user id (user_…)
userEmail string User email
source "TAB" | "COMPOSER" TAB = accepted inline completion; COMPOSER = accepted Agent / Composer diff
model string | null Model used when recorded
totalLinesAdded / totalLinesDeleted number Lines for the change
createdAt string Ingestion timestamp (ISO)
metadata array Per-file entries (fileName, fileExtension, linesAdded, linesDeleted). fileName may be omitted when privacy mode is on in the client

Bulk export: changes CSV

For large extractions, stream the same window with GET https://api.cursor.com/analytics/ai-code/changes.csv (pages of 10,000 records server-side). Same startDate / endDate / user query params; response Content-Type: text/csv; charset=utf-8.

curl -L "https://api.cursor.com/analytics/ai-code/changes.csv?startDate=30d&endDate=now" \
  -u YOUR_API_KEY: \
  -o changes.csv

CSV columns: change_id, user_id, user_email, source, model, total_lines_added, total_lines_deleted, created_at, metadata_json (JSON-stringified metadata array).

Pitfalls

  • Assuming fileName is always present — privacy mode can omit it from metadata.
  • Expecting commit hashes on this route — changes are pre-commit accepted events; use Get AI commit metrics for commit-level attribution.
  • Calling from a multi-root workspace — only the top-level git repo is covered.
  • Paginating JSON for a full dump when CSV would stream faster.
  • Alpha field churn — pin the docs version you automate against.

Commit-level CSV: Download AI commit metrics CSV. Blame and conversation metadata for a hash: Get AI commit details.