> ## 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 or Max plan.</Note>

The Analytics API accepts your personal API key or an organization API key. Both are on
[Settings > API, CLI & MCP](https://www.cubic.dev/settings?tab=api-cli).

<Steps>
  <Step title="Get a key">
    For your personal key, click **Generate API key** under **Personal API key**. Personal keys
    start with `cbk_`. If you already use one with the cubic CLI or MCP server, use the same key,
    because regenerating it replaces the key for every tool.

    For an organization key, an organization admin clicks **Create API key** under
    **Organization API keys**. Organization keys start with `cok_`, and both **Read** and **Admin**
    access work.
  </Step>

  <Step title="Store it securely">
    cubic only shows the full value once. 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>

Use an organization key for dashboards and BI tools. It belongs to the organization, so it keeps
working when the person who set up the dashboard leaves.

Analytics API keys that start with `cak_` keep working, but cubic no longer creates them. Move your
tools to a personal or organization key, then revoke the `cak_` key on the
[cubic API page](https://www.cubic.dev/settings?tab=api-cli\&integration=api).

<Note>
  A personal key reads only the organizations and repositories you can already access in cubic. An
  organization key reads only its own organization.
</Note>

## Endpoint

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

<Note>
  Analytics responses may reflect normal read-replica lag. Recent reviews, pull request updates, and
  custom-rule changes can take a short time to appear, so do not use these responses for immediate
  read-after-write verification.
</Note>

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

### Authentication

Send a personal or organization key in the `Authorization` header as a bearer token.

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

The same keys work with the [Members API](/account/members-api). See the
[API overview](/api-reference/overview) to compare the two APIs.

Requests with personal and organization keys count toward the
[Members API rate limits](/account/members-api#rate-limits) of 1,000 requests per 15 minutes per
person, or per organization for organization keys. When you run out, cubic answers `429` with a
`Retry-After` header in seconds.

The [interactive reference](/api-reference/analytics/list-pull-requests) includes all query
parameters, response schemas, and code examples. Enter your API key to try a request.
You can also use the [OpenAPI spec](/openapi/analytics.json) to generate a client.

### 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 cbk_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 cbk_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

See the [endpoint reference](/api-reference/analytics/list-pull-requests) for the full parameter
list. `org` is required. Use `repo` to filter to one repository and `perPage` to choose a page size
from 1 to 100. Values outside that range return `400`.

String query values are trimmed before validation; blank optional values are ignored.

The date window selects completed cubic reviews created in that period. The returned pull
requests must be merged, but their merge dates can fall outside the selected review window.

<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"
}
```

See the [endpoint reference](/api-reference/analytics/list-pull-requests) for field descriptions
and nullable values. `totalAiLinesAuthored` is capped at the pull request's total added and deleted
lines; it is `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 cbk_your_api_key' \
  --header 'Accept: application/json'
```

## Errors

Analytics errors include an `error` message and may include validation `details`. Check the HTTP
status and display the message when a request fails. See the
[endpoint reference](/api-reference/analytics/list-pull-requests) for error statuses and response
schemas.

```json theme={null}
{
  "error": "Analytics API requires a Pro or Max plan"
}
```


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