# Replay Realtime Events

`POST /realtime/replay` · Core · Realtime Feeds & Streams

Returns one page of past events for a topic. The request body accepts `topic` (required), `fromSequence`, `untilSequence`, `afterAuditEventId` and `limit` (at most 10,000 events per call).

Only the audit tail keeps a ledger: for every other project topic the answer has no events and `resync: "reread-source"`, so re-read current state through the data API, then subscribe. An unrecognised topic returns `K9O_INVALID_FILTER` (400).

For the live audit tail (`audit.project.*`), the replay reads the project's audit log in order, so it includes every audit event, `warden.checkpoint` included: pass `afterAuditEventId` (the last `auditEventId` you received) or `fromSequence`. Each event carries the same five fields as a live frame plus its `sequence`.

The audit tail needs the audit log's access (`K9O_RBAC_DENY` (403) otherwise). An `afterAuditEventId` that is not in the log returns `K9O_INVALID_CURSOR` (400).

## Parameters

| Name | In | Required | Description |
|---|---|---|---|
| `projectSlug` | path | yes | The project's slug, as in `/@<projectSlug>/…`. Example: `"storefront"`. |

## Request body

| Field | Type | Required | Description |
|---|---|---|---|
| `topic` | string | yes | The topic to catch up on: an exact topic or a prefix ending in `.*`. Only `audit.project.*` (or `audit.project.<type>`) keeps a ledger; any other project topic answers with no events and `resync: "reread-source"`. Example: `"audit.project.*"`. |
| `fromSequence` | object | no | `audit.project.*` only: start at this ledger sequence (inclusive). An integer or a string of digits; 0 by default. Example: `0`. |
| _one of_ | | |  |
| _or_ | | |  |
| `untilSequence` | object | no | `audit.project.*` only: stop at this ledger sequence (inclusive). An integer or a string of digits; the end of the ledger by default. Example: `5000`. |
| _one of_ | | |  |
| _or_ | | |  |
| `limit` | integer | no | The most events to return, 1 to 10000. Page on with `nextCursor` while `hasMore` is true. Example: `100`. |
| `afterAuditEventId` | string | no | `audit.project.*` only: return the events after this one, the `auditEventId` of the last live frame or replayed event received. An id that is not in the audit log answers 400 `K9O_INVALID_CURSOR`. Example: `"evt_4fQ2nX8pLm1z"`. |

```json
{
  "topic": "audit.project.*",
  "afterAuditEventId": "evt_4fQ2nX8pLm1z",
  "limit": 100
}
```

## Responses

- **200**: Success

| Field | Type | Required | Description |
|---|---|---|---|
| `data` | object | yes | The replayed page: the audit log for `audit.project.*`, or an empty page with `resync` for any other topic. |
| _one of_ | | |  |
| `data.topic` | string | yes | The topic the request named. Example: `"audit.project.*"`. |
| `data.events` | array of object | yes | The audit events in the requested range, oldest first. |
| `data.events.[]sequence` | string | yes | The event's place in the project's audit log (the replay cursor). Example: `"4182"`. |
| `data.events.[]topic` | string | yes | `audit.project.<type>`. Example: `"audit.project.data.write.access.update"`. |
| `data.events.[]eventType` | string | yes | The audit event type, the same as `payload.type`. Example: `"data.write.access.update"`. |
| `data.events.[]payload` | object | yes | The same five fields as a live audit frame. Read the full event from the audit log by `auditEventId`. |
| `data.events.[]payload.auditEventId` | string | yes | The audit event's id; pass the last one received as `afterAuditEventId` to resume. Example: `"evt_4fQ2nX8pLm1z"`. |
| `data.events.[]payload.type` | string | yes | The audit event type. Example: `"data.write.access.update"`. |
| `data.events.[]payload.actorType` | enum ("user", "extension", "end_user", "token", "agent", "service", "system", "other") | yes | What kind of principal acted. |
| `data.events.[]payload.occurredAt` | string (date-time) | yes | When the audited action happened. Example: `"2026-11-02T14:05:31.512Z"`. |
| `data.events.[]payload.outcome` | object | yes | How the action ended; null when the event records no outcome. Example: `"success"`. |
| _one of_ | | |  |
| _or_ | | |  |
| _or_ | | |  |
| _or_ | | |  |
| `data.events.[]occurredAt` | string (date-time) | yes | When the audited action happened. Example: `"2026-11-02T14:05:31.512Z"`. |
| `data.nextCursor` | object | yes | Pass as `fromSequence` to read the next page; null at the end of the log. Example: `"4283"`. |
| _one of_ | | |  |
| _or_ | | |  |
| `data.hasMore` | boolean | yes | Whether more events follow this page. Example: `true`. |
| _or_ | | |  |
| `data.topic` | string | yes | The topic the request named. Example: `"audit.project.*"`. |
| `data.events` | array of object | yes | Always empty: this topic keeps no ledger. |
| `data.nextCursor` | null | yes | Always null. Example: `null`. |
| `data.hasMore` | enum (false) | yes | Always false. |
| `data.resync` | enum ("reread-source") | yes | Re-read current state through the data API, then subscribe. |
| `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_SESSION_EXPIRED` | Your session has expired; sign in again before requesting an event replay. |
| 401 | `K9O_INVALID_CREDENTIALS` | The credentials provided are not valid; the replay request was rejected. |
| 403 | `K9O_ACCESS_DENIED` | Your role does not permit requesting a replay on this resource. |
| 400 | `K9O_INVALID_FILTER` | The replay filter contains an unsupported operator and could not be processed. |
| 404 | `K9O_COLLECTION_NOT_FOUND` | The collection referenced in the replay request does not exist in this project. |
| 403 | `K9O_RBAC_DENY` | The audit topics (audit.project.*) need GET /audit-log's authority: PROJECT_AUDITOR or PROJECT_ADMIN (or an org admin or owner). |
| 403 | `K9O_IAM_POLICY_DENIED` | The bound IAMPolicy ceiling denies audit_log:query, which the audit topics (audit.project.*) require. |
| 400 | `K9O_INVALID_CURSOR` | afterAuditEventId is not an event in this project's audit log. |

## Code samples

### cURL

```bash
curl -X POST 'https://<org>.api-<region>.k9o.io/@storefront/realtime/replay' \
  -H 'Authorization: Bearer $K9O_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{
  "topic": "audit.project.*",
  "afterAuditEventId": "evt_4fQ2nX8pLm1z",
  "limit": 100
}'
```

### fetch

```javascript
const res = await fetch('https://<org>.api-<region>.k9o.io/@storefront/realtime/replay', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${process.env.K9O_TOKEN}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
  "topic": "audit.project.*",
  "afterAuditEventId": "evt_4fQ2nX8pLm1z",
  "limit": 100
}),
});
const { data, meta } = await res.json();
```

### @k9o/core

```typescript
// const k9o = new K9o({ orgSlug: 'playground', projectSlug: 'storefront', apiKey: 'k9o_…' })
const { data } = await k9o.realtime.replay({
  topic: 'audit.project.*',
  afterAuditEventId: 'evt_4fQ2nX8pLm1z',
  limit: 100
})
```

### k9o

```python
# k9o = create_client(org_slug="playground", project_slug="storefront", api_key="k9o_…")
response = k9o.realtime.replay({
    "topic": "audit.project.*",
    "afterAuditEventId": "evt_4fQ2nX8pLm1z",
    "limit": 100
})
```

### sdk-go

```go
// ctx := context.Background()
// client, _ := k9o.NewClient(k9o.ClientOpts{OrgSlug: "playground", ProjectSlug: "storefront", APIKey: "k9o_…"})
data, _, kerr := client.Realtime.Replay(ctx, map[string]any{"topic": "audit.project.*", "afterAuditEventId": "evt_4fQ2nX8pLm1z", "limit": 100})
```

### k9o

```rust
// let k9o = Client::new(ClientOpts { org_slug: "playground".into(), project_slug: "storefront".into(), api_key: "k9o_…".into() })?;
let resp = k9o.realtime.replay(json!({"topic": "audit.project.*", "afterAuditEventId": "evt_4fQ2nX8pLm1z", "limit": 100})).await?
```

### dev.k9o:core

```java
// K9o k9o = K9o.createClient(K9o.Opts.builder().orgSlug("playground").projectSlug("storefront").apiKey("k9o_…").build());
var response = k9o.realtime().replay(Map.of("topic", "audit.project.*", "afterAuditEventId", "evt_4fQ2nX8pLm1z", "limit", 100))
```

### K9o.Core

```c#
// var k9o = K9oClient.Create(new K9oOptions { OrgSlug = "playground", ProjectSlug = "storefront", ApiKey = "k9o_…" });
var response = await k9o.Realtime.ReplayAsync(new Dictionary<string, object> { ["topic"] = "audit.project.*", ["afterAuditEventId"] = "evt_4fQ2nX8pLm1z", ["limit"] = 100 })
```

### k9o

```ruby
# k9o = K9o.create_client(org_slug: "playground", project_slug: "storefront", api_key: "k9o_…")
response = k9o.realtime.replay({ topic: "audit.project.*", afterAuditEventId: "evt_4fQ2nX8pLm1z", limit: 100 })
```

### k9o/sdk

```php
// $k9o = K9oClient::create(['org_slug' => 'playground', 'project_slug' => 'storefront', 'api_key' => 'k9o_…']);
$response = $k9o->realtime->replay(['topic' => 'audit.project.*', 'afterAuditEventId' => 'evt_4fQ2nX8pLm1z', 'limit' => 100])
```

### K9o

```swift
// let k9o = try K9o.createClient(orgSlug: "playground", projectSlug: "storefront", apiKey: "k9o_…")
let result = try await k9o.realtime.replay({
  topic: "audit.project.*",
  afterAuditEventId: "evt_4fQ2nX8pLm1z",
  limit: 100
})
```

### core-kotlin

```kotlin
// val k9o = createClient { orgSlug = "playground"; projectSlug = "storefront"; apiKey = "k9o_…" }
val result = k9o.realtime.replay({
  topic: "audit.project.*",
  afterAuditEventId: "evt_4fQ2nX8pLm1z",
  limit: 100
})
```

### k9o (Flutter)

```dart
// final k9o = K9o.createClient(orgSlug: 'playground', projectSlug: 'storefront', apiKey: 'k9o_…');
final result = await k9o.realtime.replay({
  topic: 'audit.project.*',
  afterAuditEventId: 'evt_4fQ2nX8pLm1z',
  limit: 100
})
```

### @k9o/react-native

```javascript
// const k9o = createClient({ orgSlug: 'playground', projectSlug: 'storefront', apiKey: 'k9o_…' })  // RN, secure storage
const { data } = await k9o.realtime.replay({
  topic: 'audit.project.*',
  afterAuditEventId: 'evt_4fQ2nX8pLm1z',
  limit: 100
})
```


Canonical page: https://docs.kilimanjaro.dev/api-playground/core/replay-realtime-events
