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

# Analytics API

> Analyze cubic adoption using your own tools.

You may need to measure impact of cubic, but already have a set of analytics tools. The Analytics API gives you PR-level data on how many issues were flagged, how many were fixed, how much AI code was authored, etc.

## Get an API key

<Note>
  Analytics API access requires a Pro plan.
</Note>

<Steps>
  <Step title="Open the Analytics API integration">
    Go to [Settings → Integrations → Analytics API](https://www.cubic.dev/settings?tab=integrations\&integration=analytics).
  </Step>

  <Step title="Generate a personal key">
    Click **Generate API key**. Analytics API keys start with `cak_`, and cubic only shows the full value once.
  </Step>

  <Step title="Store it securely">
    Save the key in your secret manager or local environment. If you revoke or regenerate the key, the previous value stops working immediately.
  </Step>
</Steps>

<Note>
  API keys are personal. Each team member should generate their own key, and every request is limited to the organizations and repositories that key owner can already access in cubic.
</Note>

## Endpoint

Use this endpoint to fetch merged pull requests that have completed cubic reviews in the selected time window.

| Method | Endpoint                                     |
| ------ | -------------------------------------------- |
| `GET`  | `https://www.cubic.dev/api/analytics/v1/prs` |

### Authentication

Send the Analytics API key in the `Authorization` header as a bearer token.

```http theme={null}
Authorization: Bearer cak_your_api_key
```

### Example requests

<CodeGroup>
  ```bash cURL theme={null}
  curl --request GET \
    --url 'https://www.cubic.dev/api/analytics/v1/prs?org=your-org&perPage=100' \
    --header 'Authorization: Bearer cak_your_api_key' \
    --header 'Accept: application/json'
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch(
    'https://www.cubic.dev/api/analytics/v1/prs?org=your-org&perPage=100',
    {
      headers: {
        Authorization: 'Bearer cak_your_api_key',
        Accept: 'application/json',
      },
    },
  );

  if (!response.ok) {
    throw new Error('Failed to fetch pull request analytics');
  }

  const payload = await response.json();

  console.log(payload.data);
  console.log(payload.nextCursor);
  ```
</CodeGroup>

## Query parameters

| Parameter   | Required | Description                                                                                    |
| ----------- | -------- | ---------------------------------------------------------------------------------------------- |
| `org`       | Yes      | GitHub organization or owner whose pull request analytics you want to fetch.                   |
| `repo`      | No       | Limit the request to a single repository inside the selected owner.                            |
| `startDate` | No       | Start of the time window. Supports ISO 8601 timestamps and date-only values like `2026-04-01`. |
| `endDate`   | No       | End of the time window. Supports ISO 8601 timestamps and date-only values like `2026-04-30`.   |
| `perPage`   | No       | Number of results per page. Defaults to `100` and is capped at `100`.                          |
| `cursor`    | No       | Cursor from the previous response. Use it to fetch the next page.                              |

<Info>
  If you do not send `startDate` or `endDate`, cubic picks a default window based on how much data is available for that installation: the last 30 days, last 7 days, or last 24 hours.
</Info>

<Note>
  Date-only values are interpreted in UTC. For example, `endDate=2026-04-30` includes the full day through `23:59:59.999Z`.
</Note>

If you send only one date bound, cubic fills in the other one for you:

* `startDate` only: `endDate` defaults to the current time
* `endDate` only: `startDate` defaults to the start of available data

## Response format

The API returns one page of PR rows plus an optional cursor for the next page.

```json theme={null}
{
  "data": [
    {
      "org": "acme",
      "repo": "backend",
      "prNumber": 4645,
      "author": "john-doe",
      "createdAt": "2026-04-16T12:00:00.000Z",
      "mergedAt": "2026-04-17T12:00:00.000Z",
      "linesAdded": 543,
      "linesDeleted": 12,
      "numberOfCubicIssuesFlagged": 5,
      "numberOfCubicIssuesFixed": 4,
      "cubicFirstReviewedAt": "2026-04-17T00:00:00.000Z",
      "totalAiLinesAuthored": 523
    }
  ],
  "nextCursor": "2026-04-16T12:00:00.000Z|102"
}
```

### Top-level fields

| Field        | Description                                                         |
| ------------ | ------------------------------------------------------------------- |
| `data`       | The current page of pull request analytics rows.                    |
| `nextCursor` | Cursor for the next page, or `null` when there are no more results. |

### Pull request row fields

| Field                        | Description                                                                                                |
| ---------------------------- | ---------------------------------------------------------------------------------------------------------- |
| `org`                        | GitHub owner used for the request.                                                                         |
| `repo`                       | Repository name.                                                                                           |
| `prNumber`                   | Pull request number.                                                                                       |
| `author`                     | GitHub login of the pull request author.                                                                   |
| `createdAt`                  | Pull request creation timestamp in ISO 8601 format.                                                        |
| `mergedAt`                   | Pull request merge timestamp in ISO 8601 format.                                                           |
| `linesAdded`                 | Lines added in the pull request, or `null` when unavailable.                                               |
| `linesDeleted`               | Lines deleted in the pull request, or `null` when unavailable.                                             |
| `numberOfCubicIssuesFlagged` | Number of cubic issues flagged on the pull request.                                                        |
| `numberOfCubicIssuesFixed`   | Number of cubic issues fixed on the pull request.                                                          |
| `cubicFirstReviewedAt`       | Timestamp of the first completed cubic review for the pull request.                                        |
| `totalAiLinesAuthored`       | Total AI-authored lines attributed to the pull request, or `null` when no AI authorship data is available. |

## Pagination

When `nextCursor` is present, send it back in the next request to continue from the previous page.

```bash theme={null}
curl --request GET \
  --url 'https://www.cubic.dev/api/analytics/v1/prs?org=your-org&perPage=100&cursor=2026-04-16T12%3A00%3A00.000Z%7C102' \
  --header 'Authorization: Bearer cak_your_api_key' \
  --header 'Accept: application/json'
```

## Common errors

| Status | When it happens                                                                                                                  |
| ------ | -------------------------------------------------------------------------------------------------------------------------------- |
| `400`  | Missing `org`, invalid query parameters, invalid cursor, or invalid date range.                                                  |
| `401`  | Missing bearer token, invalid API key, or expired API key.                                                                       |
| `403`  | The API key owner does not have access to the requested organization or repository, or the requested organization is not on Pro. |
| `404`  | cubic cannot resolve the `org` to an installation.                                                                               |
