# Create Rollup

`POST /analytics/{datasetSlug}/rollups` · Core · Analytics & Intelligence

Creates a continuous rollup that folds a stream into this dataset over fixed windows. Body:
- `slug`.
- `source`.
- `dimensions` (up to 16).
- `measures` (up to 64; `count`, or `last`, `sum`, `avg`, `min`, `max`, `count_distinct`, `p50`, `p95`, `p99` over a column).
- `windowSeconds` (at least 60).
- `reattestIntervalDays` (7, 30, 90 or 365; default 90).
- Exactly one of `subjectField` (per-subject data, suppressed below the cohort threshold) or `nonPersonal: true`.

The rollup keeps running only while its configuration is re-attested within the interval. Returns the rollup and its read and subscribe endpoints.

Requires the `datasets:write` permission (PROJECT_ADMIN or PROJECT_AUTHOR by default).

Callers must be members of the project (an organization role alone does not grant access); project service tokens and extension tokens cannot call it.

## Parameters

| Name | In | Required | Description |
|---|---|---|---|
| `datasetSlug` | path | yes | The Dataset's slug. Example: `"orders"`. |
| `projectSlug` | path | yes | The project's slug: the path segment after `@`. It is unique within the org. Example: `"storefront"`. |

## Request body

| Field | Type | Required | Description |
|---|---|---|---|
| `slug` | string | yes | The rollup's slug: 1 to 63 lowercase letters, digits and hyphens, unique in the project. It can't be changed later; the rollup's read and subscribe paths use it. |
| `subjectField` | string | no | The source event field that names the data subject: letters, digits and underscores, not starting with a digit. With it, each cell counts distinct subjects and a cell with too few is suppressed; the target dataset must then be a shared dataset that declares a `suppressed` column of type `bool`. Send this or `nonPersonal: true`, not both. |
| `nonPersonal` | boolean | no | Send `true` to declare that the source carries no personal data. Send this or `subjectField`, not both. |
| `source` | string | yes | The stream to fold: the slug of a Pulse Stream in this project, or `logs`, `metrics` or `traces` for the project's telemetry. |
| `dimensions` | array of string | no | The source fields each cell is grouped by: at most 16, unique, each letters, digits and underscores, not starting with a digit. `window_start` and `suppressed` are reserved. Omit it for one cell per window. |
| `measures` | array of object | yes | What each cell computes: 1 to 64 measures. |
| `measures.[]name` | string | yes | The measure's name: letters, digits and underscores, not starting with a digit, unique in the rollup. It is the measure's key in each cell. `window_start` and `suppressed` are reserved. |
| `measures.[]agg` | string | yes | The aggregation: `count`, `last`, `sum`, `avg`, `min`, `max`, `count_distinct`, `p50`, `p95` or `p99`. |
| `measures.[]column` | string | no | The source field to aggregate. Required for every aggregation except `count`, which must not send one. |
| `windowSeconds` | integer | yes | The width of each cell's time window, in seconds. At least 60. |
| `reattestIntervalDays` | object | no | How many days each attestation lasts: 7, 30, 90 or 365. Default 90. When it runs out, the rollup stops folding until someone re-attests it. |
| _one of_ | | |  |
| _or_ | | |  |
| _or_ | | |  |
| _or_ | | |  |

## Responses

- **200**: Success

| Field | Type | Required | Description |
|---|---|---|---|
| `data` | object | yes | A rollup, the state of its folding, and the paths to read it. |
| `data.id` | string | yes | `rollup_` id. |
| `data.slug` | string | yes | The rollup's slug, unique in the project. Its read and subscribe paths use it. |
| `data.subjectField` | object | yes | The source event field that names the data subject. Null when the rollup declares `nonPersonal` instead (or, for a rollup made before declarations were required, neither). |
| _one of_ | | |  |
| _or_ | | |  |
| `data.nonPersonal` | boolean | yes | True when the rollup's creator declared that its source carries no personal data. |
| `data.datasetSlug` | string | yes | The dataset the rollup writes to. |
| `data.source` | string | yes | The source the rollup folds: a Pulse Stream's slug, or a telemetry signal name. Falls back to the stored stream id when the stream has been deleted. |
| `data.dimensions` | array of string | yes | The fields each cell is grouped by, in declared order (at most 16). |
| `data.measures` | array of object | yes | The declared measures, in order (at most 64). |
| `data.measures.[]name` | string | yes | The measure's name: its key in each cell's `measures`. |
| `data.measures.[]agg` | string | yes | `count`, `last`, `sum`, `avg`, `min`, `max`, `count_distinct`, `p50`, `p95` or `p99`. |
| `data.measures.[]column` | string | no | The source field aggregated. Absent for `count`. |
| `data.windowSeconds` | integer | yes | The width of each cell's time window, in seconds. |
| `data.enabled` | boolean | yes | Whether the rollup is set to fold. |
| `data.reattestIntervalDays` | integer | yes | How many days each attestation lasts: 7, 30, 90 or 365. |
| `data.attestedAt` | string (date-time) | yes | When a person last confirmed the rollup (created or re-attested it). |
| `data.expiresAt` | string (date-time) | yes | `attestedAt` plus `reattestIntervalDays`. After it the rollup stops folding until it is re-attested. |
| `data.attestationStatus` | enum ("active", "expiring_soon", "expired") | yes | `expiring_soon` within 14 days of `expiresAt`. |
| `data.cursorSequence` | object | yes | The source sequence the last committed fold reached, as a decimal string. Null until a fold has written a cell. |
| _one of_ | | |  |
| _or_ | | |  |
| `data.lastFoldAt` | object | yes | When the last fold ran. Null if it has never run. |
| _one of_ | | |  |
| _or_ | | |  |
| `data.lastFoldStatus` | object | yes | How the last fold ended: `ok` for a clean fold, otherwise why it did not fold (for example `attestation_expired`, `stale_principal_denied`, `dataset_gone`, `write_error` or `failed`). Null if it has never run. |
| _one of_ | | |  |
| _or_ | | |  |
| `data.createdAt` | string (date-time) | yes | When the rollup was created. |
| `data.endpoints` | object | yes | Absolute paths: `/@<project>/rollups/<slug>/read` and `/subscribe`. |
| `data.endpoints.read` | string | yes | The path to read the rollup's cells. |
| `data.endpoints.subscribe` | string | yes | The path to subscribe to the rollup's cells as they change. |
| `meta` | object | yes | Request metadata: cost, timing and correlation ids. |
| `meta.cost` | object | yes | Metered usage for this request; empty when nothing was metered. |
| `meta.timing` | object | yes |  |
| `meta.timing.gatewayMs` | number | yes |  |
| `meta.timing.totalMs` | number | yes |  |
| `meta.context` | object | yes |  |
| `meta.context.requestId` | string | yes |  |
| `meta.context.traceId` | string | yes |  |
| `meta.context.projectId` | string | no |  |
| `meta.warnings` | array of object | no |  |
| `meta.warnings.[]code` | string | yes |  |
| `meta.warnings.[]message` | string | yes |  |


## Errors

| HTTP | Code | When |
|---|---|---|
| 401 | `K9O_UNAUTHENTICATED` | The caller is not signed in. |
| 403 | `K9O_ACCESS_DENIED` | The caller is not a member of this project; an organization role alone does not grant access. |
| 404 | `K9O_NOT_FOUND` | The project was not found for this caller (project service tokens and extension tokens cannot call this endpoint). |
| 403 | `K9O_IAM_POLICY_DENIED` | The caller's role or IAM policy does not grant datasets:write. |
| 400 | `K9O_INVALID_REQUEST_SHAPE` | The request body does not match the schema. |
| 400 | `K9O_INVALID_FIELD_VALUE` | A field is invalid: slug, source, dimensions, measures, window, re-attest interval, or neither / both of `subjectField` and `nonPersonal`. |
| 404 | `K9O_DATASET_NOT_FOUND` | No active dataset with this slug exists in the project. |
| 409 | `K9O_ALREADY_EXISTS` | A rollup with this slug already exists. |
| 409 | `K9O_PENDING_CHANGE_ALREADY_EXISTS` | A rollup for this dataset and source already exists. |

## Code samples

### cURL

```bash
curl -X POST 'https://<org>.api-<region>.k9o.io/@storefront/analytics/<datasetSlug>/rollups' \
  -H 'Authorization: Bearer $K9O_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{}'
```

### fetch

```javascript
const res = await fetch('https://<org>.api-<region>.k9o.io/@storefront/analytics/<datasetSlug>/rollups', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${process.env.K9O_TOKEN}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({}),
});
const { data, meta } = await res.json();
```

### k9o CLI

```bash
k9o analytics rollups create <dataset> --slug <s> --source <stream> --measures <json|@file> --window-seconds N --subject-field <f>
```

### @k9o/core

```typescript
// const k9o = new K9o({ orgSlug: 'playground', projectSlug: 'storefront', apiKey: 'k9o_…' })
const { data } = await k9o.analytics.rollups.create('<datasetSlug>', {})
```

### k9o

```python
# k9o = create_client(org_slug="playground", project_slug="storefront", api_key="k9o_…")
response = k9o.analytics.rollups.create("<datasetSlug>", {})
```

### sdk-go

```go
// ctx := context.Background()
// client, _ := k9o.NewClient(k9o.ClientOpts{OrgSlug: "playground", ProjectSlug: "storefront", APIKey: "k9o_…"})
data, _, kerr := client.Analytics.Rollups.Create(ctx, "<datasetSlug>", map[string]any{})
```

### k9o

```rust
// let k9o = Client::new(ClientOpts { org_slug: "playground".into(), project_slug: "storefront".into(), api_key: "k9o_…".into() })?;
let resp = k9o.analytics.rollups.create("<datasetSlug>", json!({})).await?
```

### dev.k9o:core

```java
// K9o k9o = K9o.createClient(K9o.Opts.builder().orgSlug("playground").projectSlug("storefront").apiKey("k9o_…").build());
var response = k9o.analytics().rollups().create("<datasetSlug>", Map.of())
```

### K9o.Core

```c#
// var k9o = K9oClient.Create(new K9oOptions { OrgSlug = "playground", ProjectSlug = "storefront", ApiKey = "k9o_…" });
var response = await k9o.Analytics.Rollups.CreateAsync("<datasetSlug>", new Dictionary<string, object> {  })
```

### k9o

```ruby
# k9o = K9o.create_client(org_slug: "playground", project_slug: "storefront", api_key: "k9o_…")
response = k9o.analytics.rollups.create("<datasetSlug>", {  })
```

### k9o/sdk

```php
// $k9o = K9oClient::create(['org_slug' => 'playground', 'project_slug' => 'storefront', 'api_key' => 'k9o_…']);
$response = $k9o->analytics->rollups->create('<datasetSlug>', [])
```


Canonical page: https://docs.kilimanjaro.dev/api-playground/core/create-rollup
