# Create Dataset

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

Creates a dataset at the slug in the path. Body:
- `displayName`.
- `columns` (1 to 512, each `{name, type}` with type `string`, `int32`, `int64`, `float64`, `bool`, `date`, `timestamp`, `json`, `bytes` or `decimal(p,s)`).
- Optional `partitionBy`.
- `residencyClass` (`per-subject` or `shared`).
- Optional `storageTarget` (`{kind: "managed"}` or `{kind: "byos", bindingId}`).

A timestamp partition key needs a transform such as `:day`; `region` is added automatically. Slugs are lowercase identifiers, some words are reserved, and a slug is never reissued, even after the dataset is deleted. A project holds at most 200 datasets (`429 K9O_DATASET_LIMIT_EXCEEDED`). Returns 201 with the dataset and its endpoints.

Requires the `datasets:create` 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 |
|---|---|---|---|
| `displayName` | string | yes | The name shown for the dataset, 1 to 200 characters. |
| `columns` | array of object | yes | The dataset's columns, in order: 1 to 512, with unique names. |
| `columns.[]name` | string | yes | The column's name, unique in the dataset. |
| `columns.[]type` | string | yes | `string`, `int32`, `int64`, `float64`, `bool`, `date`, `timestamp`, `json`, `bytes`, or `decimal(p,s)` with a precision of 1 to 38 and a scale of 0 to p. |
| `partitionBy` | array of string | no | Up to 16 partition keys, each a declared column. A `timestamp` or `date` column may take a transform, `<column>:year`, `:month`, `:day` or `:hour`; a bare `timestamp` is refused. Only `string`, `bool`, `int32`, `int64` and `date` columns can be partition keys without a transform. `region` is added first automatically; don't declare it. |
| `residencyClass` | enum ("per-subject", "shared") | yes | `per-subject`: rows hold data about individual people, sealed per person and kept in that person's region. `shared`: rows are not about any one person. |
| `storageTarget` | object | no | Where to keep the dataset's files: `managed` (the default) for platform-managed storage, or `byos` with the `bindingId` of a storage location you connected. |
| _one of_ | | |  |
| `storageTarget.kind` | enum ("managed") | yes | Platform-managed storage. |
| _or_ | | |  |
| `storageTarget.kind` | enum ("byos") | yes | A storage location you connected. |
| `storageTarget.bindingId` | string | yes | The storage location's binding id. It must be live, and not the location that holds the audit anchors. |

## Responses

- **201**: Created

| Field | Type | Required | Description |
|---|---|---|---|
| `data` | object | yes | The dataset that was created, with the paths to write, query and upload to. |
| `data.id` | string | yes | `dset_` id. |
| `data.slug` | string | yes | The dataset's name, unique in the project. Queries refer to it as `dataset.<slug>`. |
| `data.displayName` | string | yes | The name shown for the dataset. |
| `data.schema` | array of object | yes | The declared columns, in order. |
| `data.schema.[]name` | string | yes | The column's name. |
| `data.schema.[]type` | string | yes | `string`, `int32`, `int64`, `float64`, `bool`, `date`, `timestamp`, `json`, `bytes`, or `decimal(p,s)`. |
| `data.partitionKeys` | array of string | yes | Always starts with `region`, then the declared `partitionBy` keys. |
| `data.residencyClass` | enum ("per-subject", "shared") | yes | `per-subject`: rows hold data about individual people, sealed per person and kept in that person's region. `shared`: rows are not about any one person. |
| `data.storageTarget` | object | yes | Where the dataset's files are kept: `managed` for platform-managed storage, or `byos` with the `bindingId` of a storage location you connected. |
| _one of_ | | |  |
| `data.storageTarget.kind` | enum ("managed") | yes | Platform-managed storage. |
| _or_ | | |  |
| `data.storageTarget.kind` | enum ("byos") | yes | A storage location you connected. |
| `data.storageTarget.bindingId` | string | yes | The storage location's binding id. |
| `data.createdAt` | string (date-time) | yes | When the dataset was created. |
| `data.retiredAt` | null | yes | Always null: a retired dataset reads as absent. |
| `data.endpoints` | object | yes | Relative paths: `<slug>/write`, `<slug>/query`, `<slug>/upload`. |
| `data.endpoints.write` | string | yes | The path to write rows to, relative to the dataset. |
| `data.endpoints.query` | string | yes | The path to query the dataset, relative to the dataset. |
| `data.endpoints.upload` | string | yes | The path to upload a CSV or JSON file to, relative to the dataset. |
| `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:create. |
| 400 | `K9O_INVALID_REQUEST_SHAPE` | The request body does not match the schema. |
| 400 | `K9O_DATASET_INVALID` | The slug is reserved, invalid or already used (slugs are never reissued), or a column, type or partition key is invalid. |
| 400 | `K9O_DATASET_STORAGE_TARGET_INVALID` | The storage location in `storageTarget` does not exist or is retired. |
| 409 | `K9O_STATE_CONFLICT` | The chosen storage location is write-once and cannot hold a dataset. |
| 429 | `K9O_DATASET_LIMIT_EXCEEDED` | The project already has the maximum number of datasets (200). |

## Code samples

### cURL

```bash
curl -X POST 'https://<org>.api-<region>.k9o.io/@storefront/analytics/<datasetSlug>' \
  -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>', {
  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 create <slug> --name <display name> --columns <json|@file|-> --residency per-subject|shared
```

### @k9o/core

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

### k9o

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

### sdk-go

```go
// ctx := context.Background()
// client, _ := k9o.NewClient(k9o.ClientOpts{OrgSlug: "playground", ProjectSlug: "storefront", APIKey: "k9o_…"})
data, _, kerr := client.Analytics.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.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().create("<datasetSlug>", Map.of())
```

### K9o.Core

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

### k9o

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

### k9o/sdk

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


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