# Create Stream

`POST /data-streams/user` · Core · Realtime Feeds & Streams

Creates a user stream in the project: a named, append-only message log that the project's own producers publish to and consumers read from. The slug is derived from `displayName`. `maxBytes` reserves storage from the organization's Pulse Stream allotment and `retentionSeconds` sets how long each message is kept. Answers 201 with the stream. Needs PROJECT_ADMIN. Audited as `data.write.pulse_stream.created`.

## Parameters

| Name | In | Required | Description |
|---|---|---|---|
| `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 | A single line of text, 1 to 80 characters. The stream's slug (its address under `/data-streams/user/<slug>`) is derived from it and must be unique among the project's active streams. |
| `retentionSeconds` | integer | no | Retention (max_age) in whole hours: 3600 to 86400 is Warm, above 86400 is Cold. Default 86400. 900 (Hot, 15 min) is reserved for platform system streams and answers 403 K9O_STREAM_TIER_FORBIDDEN; any other value that is not a whole number of hours answers 400 K9O_STREAM_INVALID. A project's stream retention ceiling may refuse a long window. |
| `maxBytes` | integer | yes | The stream's reserved storage ceiling in bytes (required). Legal sizes: 10 MiB to 1 GiB in 10 MiB steps; above 1 GiB to 10 GiB in 100 MiB steps; above 10 GiB to 64 GiB in 1 GiB steps. The band edges 1 GiB and 10 GiB are legal. Anything else is 400 K9O_INVALID_FIELD_VALUE naming the band. The org's storage allotment also bounds the sum over its active streams. |

## Responses

- **201**: Created

| Field | Type | Required | Description |
|---|---|---|---|
| `data` | object | yes | A user stream: an append-only message log in the project. |
| `data.id` | string | yes | The stream's internal id (`pstr_...`). Address the stream by `slug`. |
| `data.slug` | string | yes | The stream's address in the project, derived from `displayName`. |
| `data.projectId` | string | yes | The project the stream belongs to (`proj_...`). |
| `data.displayName` | string | yes | The name given at creation. |
| `data.subjectPrefix` | string | yes | The message subject namespace the platform assigned to the stream: `k9o.<region>.<org>.<project>.user.<id>`. Published messages carry subjects under it. |
| `data.region` | string | yes | The region the stream's data lives in. |
| `data.retentionSeconds` | integer | yes | How long each message is kept, in seconds: 900 or a whole number of hours. |
| `data.retentionClass` | enum ("hot", "warm", "cold") | yes | The retention class `retentionSeconds` falls in, which sets the storage rate: `hot` is 15 minutes, `warm` is 1 to 24 hours, `cold` is above 24 hours. |
| `data.maxBytes` | object | yes | The storage the stream reserves, in bytes. Null only on a stream created before a size was required. |
| _one of_ | | |  |
| _or_ | | |  |
| `data.status` | enum ("active") | yes | Always `active`: a deleted stream is not returned. |
| `data.createdAt` | string (date-time) | yes | When the stream was created. |
| `data.createdBy` | object | yes | The id of the caller that created the stream; null if not recorded. |
| _one of_ | | |  |
| _or_ | | |  |
| `meta` | object | yes |  |


## Errors

| HTTP | Code | When |
|---|---|---|
| 400 | `K9O_INVALID_REQUEST_SHAPE` | The request body did not match the expected shape (displayName required; retentionSeconds/maxBytes must be positive integers if supplied). |
| 400 | `K9O_STREAM_INVALID` | The displayName does not yield a valid slug (needs at least one alphanumeric character), the requested retentionSeconds is not a valid quantized value, or a stream with the derived slug already exists in this project. |
| 403 | `K9O_IAM_POLICY_DENIED` | The bound IAMPolicy ceiling denies streams:create for this principal. |
| 404 | `K9O_NOT_FOUND` | The project this stream would belong to could not be found, or the caller has no project membership. |
| 409 | `K9O_PULSE_STREAM_ORG_QUOTA_EXCEEDED` | The organization is at its tier's org-wide active Pulse Stream quota; raise the quota or retire an existing stream elsewhere in the org before creating another. |
| 429 | `K9O_STREAM_LIMIT_EXCEEDED` | This project is at its active Pulse Stream cap; retire an existing stream in this project before creating another. |

## Code samples

### cURL

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

### fetch

```javascript
const res = await fetch('https://<org>.api-<region>.k9o.io/@storefront/data-streams/user', {
  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 stream create --name <display name> --max-bytes <size>
```

### @k9o/core

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

### k9o

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

### sdk-go

```go
// ctx := context.Background()
// client, _ := k9o.NewClient(k9o.ClientOpts{OrgSlug: "playground", ProjectSlug: "storefront", APIKey: "k9o_…"})
data, _, kerr := client.Streams.Create(ctx, 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.streams.create(json!({})).await?
```

### dev.k9o:core

```java
// K9o k9o = K9o.createClient(K9o.Opts.builder().orgSlug("playground").projectSlug("storefront").apiKey("k9o_…").build());
var response = k9o.streams().create(Map.of())
```

### K9o.Core

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

### k9o

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

### k9o/sdk

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

### K9o

```swift
// let k9o = try K9o.createClient(orgSlug: "playground", projectSlug: "storefront", apiKey: "k9o_…")
let result = try await k9o.streams.create({})
```

### core-kotlin

```kotlin
// val k9o = createClient { orgSlug = "playground"; projectSlug = "storefront"; apiKey = "k9o_…" }
val result = k9o.streams.create({})
```

### k9o (Flutter)

```dart
// final k9o = K9o.createClient(orgSlug: 'playground', projectSlug: 'storefront', apiKey: 'k9o_…');
final result = await k9o.streams.create({})
```

### @k9o/react-native

```javascript
// const k9o = createClient({ orgSlug: 'playground', projectSlug: 'storefront', apiKey: 'k9o_…' })  // RN, secure storage
const { data } = await k9o.streams.create({})
```


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