# Realtime

> Kontiga is document fraud detection by Bynn Intelligence for insurers, letting agents, lenders and HR screening teams: every document is compared with a proprietary library of more than 300 million original documents, gathered over 20 years.

Documentation index: https://kontiga.com/llms.txt

Section: Reference. URL: https://kontiga.com/docs/realtime

The workspace's events as they happen, as server-sent events over one long HTTP response: the same events and the same envelope as webhooks, for a page or a script that shows live work. A browser reads it with a short-lived token that your server mints with its secret key, sent in the `Authorization` header, so the key never reaches the browser and the token never sits in a URL. A server may open it with its key. Webhooks stay the contract for servers.

Updated November 30, 2026

## How the channel works

The realtime channel

|  | What it does |
| --- | --- |
| Address | `GET https://api.kontiga.com/v1/realtime` with `Accept: text/event-stream`. Without that header the same call answers the page of events below, for a reader that cannot hold a stream. |
| Credential | A realtime token in `Authorization: Bearer`, or a secret key with `events:read` from a server. A token lasts 15 minutes, opens this stream and no other route, and carries its key's workspace and mode. |
| Channels | `workspace` for every event your role can read, or `document:{document_id}` for one document, in the `channels` parameter, at most 20. A channel of another workspace or mode, or one your access does not reach, is refused with `404 not_found` before the stream opens, the refused channels in `details.channels`. |
| Events | One event of the [catalogue](https://kontiga.com/docs/events) per message: `id` is the event id, `event` its type, `data` the webhook envelope with the `channel` that carried it. A stream is live or test, never both. |
| Order and repeats | At least once, in order. Drop an event id you have already seen. |
| Resuming | Reconnect with the `Last-Event-ID` header and every event since follows, from 2 seconds before it: drop the ids you have. An event sent again names its object by id and kind; read the object with `GET`. More than 500 behind, you get `event: resync`: read again what you show. |
| Heartbeats | A comment line every 20 seconds keeps proxies from closing a quiet stream. With no byte for 45 seconds, reconnect with backoff and resume. |
| Refusals | Before the first byte, as a plain answer: `401` for the credential, `404` for a channel, `429` when the workspace holds its most streams, `503` while a server restarts. Wait the `Retry-After` and reconnect. |
| Endings | The server ends a stream when its token ends, when its member signs out or its key is revoked, and when it restarts. Mint a fresh token and reconnect with `Last-Event-ID`. |

**On the wire**

```
retry: 3000

id: evt_0193c1a2c0027a2b8c3d4e5f60718293
event: document.checking
data: {"id":"evt_0193c1a2c0027a2b8c3d4e5f60718293","type":"document.checking","created_at":"2026-11-26T09:41:49.002Z","workspace":"ws_0193c1a2b3c44d5e8f60718293a4b5c6","mode":"live","data":{"object":{"id":"doc_0193c1a2b7d84e1f9a2b3c4d5e6f7081","object":"document","state":"checking","check":{"stage":"reading","percent":25}}},"channel":"workspace"}

:

id: evt_0193c1a2c0047a2b8c3d4e5f60718293
event: document.checked
data: {"id":"evt_0193c1a2c0047a2b8c3d4e5f60718293","type":"document.checked","created_at":"2026-11-26T09:41:58.906Z","workspace":"ws_0193c1a2b3c44d5e8f60718293a4b5c6","mode":"live","data":{"object":{"id":"doc_0193c1a2b7d84e1f9a2b3c4d5e6f7081","object":"document","state":"checked","verdict":"trusted"}},"channel":"workspace"}

event: resync
data: {}
```

**In a browser**

```typescript
// on your server: mint a token with the secret key
// POST /v1/realtime/tokens {"channels": ["workspace"]}

// in the page: read the stream with fetch, the token in the Authorization
// header (EventSource cannot set headers, and a URL would put it in logs)
let lastEventId: string | null = null;

async function follow(token: string) {
  const res = await fetch("https://api.kontiga.com/v1/realtime?channels=workspace", {
    headers: {
      Authorization: `Bearer ${token}`,
      Accept: "text/event-stream",
      ...(lastEventId ? { "Last-Event-ID": lastEventId } : {}),
    },
  });
  const reader = res.body!.pipeThrough(new TextDecoderStream()).getReader();
  let buffer = "";
  for (;;) {
    const { value, done } = await reader.read();
    if (done) break;
    buffer += value;
    const messages = buffer.split("\n\n");
    buffer = messages.pop() ?? "";
    for (const message of messages) {
      const id = /^id: (.+)$/m.exec(message)?.[1];
      const type = /^event: (.+)$/m.exec(message)?.[1];
      const data = /^data: (.+)$/m.exec(message)?.[1];
      if (id) lastEventId = id;
      if (type === "resync") reloadWhatIsShown();
      else if (type && data) handle(type, JSON.parse(data));
    }
  }
}
```

> **Nothing depends on the channel alone** When the stream is down, read the objects again with `GET`. The console does the same: it loads and refreshes in the background without the channel.

## Mint a realtime token

A short-lived token that opens the realtime channel for the channels named, so a page or a script listens without holding a secret key.

`POST /v1/realtime/tokens`. Who may: Owner, Admin and Developer. CLI: `kontiga realtime token [--channels <channel,...>]`. MCP tool: `create_realtime_token`.

**Parameters**
- `channels` (array of string, default ["workspace"]): The channels the token opens: `workspace` (any channel of the workspace your access reads), or exactly the `document:{document_id}` channels named. Left out, `workspace`. The token carries the key's workspace and mode and lasts 15 minutes. At most 20 items.

**Returns** realtime token: The token, shown once, with when it expires; it carries the key's workspace, mode and scopes.

API:

```bash
curl -X POST https://api.kontiga.com/v1/realtime/tokens \
  -H "Authorization: Bearer $KONTIGA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "channels": [
      "document:doc_0193c1a2b7d84e1f9a2b3c4d5e6f7081"
    ]
  }'
```

CLI:

```bash
kontiga realtime token \
  --channels document:doc_0193c1a2b7d84e1f9a2b3c4d5e6f7081
```

MCP tool `create_realtime_token`:

```json
{
  "name": "create_realtime_token",
  "arguments": {
    "channels": [
      "document:doc_0193c1a2b7d84e1f9a2b3c4d5e6f7081"
    ]
  }
}
```

TypeScript:

```typescript
import Kontiga from "@kontiga/sdk";

const kontiga = new Kontiga(); // reads KONTIGA_API_KEY
const result = await kontiga.realtime.createToken({
  channels: ["document:doc_0193c1a2b7d84e1f9a2b3c4d5e6f7081"],
});
```

Python:

```python
from kontiga import Kontiga

kontiga = Kontiga()  # reads KONTIGA_API_KEY
result = kontiga.realtime.create_token(channels=["document:doc_0193c1a2b7d84e1f9a2b3c4d5e6f7081"])
```

Go:

```go
client := kontiga.NewClient() // reads KONTIGA_API_KEY
result, err := client.Realtime.CreateToken(ctx, &kontiga.RealtimeCreateTokenParams{
	Channels: []string{"document:doc_0193c1a2b7d84e1f9a2b3c4d5e6f7081"},
})
if err != nil {
	return err
}
```

Java:

```java
Kontiga kontiga = Kontiga.fromEnv(); // reads KONTIGA_API_KEY
var result = kontiga.realtime().createToken(RealtimeCreateTokenParams.builder()
    .channels(List.of("document:doc_0193c1a2b7d84e1f9a2b3c4d5e6f7081"))
    .build());
```

.NET:

```csharp
var kontiga = new KontigaClient(); // reads KONTIGA_API_KEY
var result = await kontiga.Realtime.CreateTokenAsync(new RealtimeCreateTokenOptions
{
    Channels = new[] { "document:doc_0193c1a2b7d84e1f9a2b3c4d5e6f7081" },
});
```

PHP:

```php
$kontiga = new \Kontiga\Client(); // reads KONTIGA_API_KEY
$result = $kontiga->realtime->createToken([
    'channels' => ['document:doc_0193c1a2b7d84e1f9a2b3c4d5e6f7081'],
]);
```

Ruby:

```ruby
require "kontiga"

kontiga = Kontiga::Client.new # reads KONTIGA_API_KEY
result = kontiga.realtime.create_token(channels: ["document:doc_0193c1a2b7d84e1f9a2b3c4d5e6f7081"])
```

Rust:

```rust
let kontiga = kontiga::Client::from_env()?; // reads KONTIGA_API_KEY
let result = kontiga
    .realtime()
    .create_token(kontiga::realtime::CreateTokenParams {
        channels: vec!["document:doc_0193c1a2b7d84e1f9a2b3c4d5e6f7081".into()],
        ..Default::default()
    })
    .await?;
```

Response, 201 Created:

```json
{
  "object": "realtime_token",
  "token": "kt_rt_AQICAAIBAA8yXj3sY4bK1q0nT7wVd2LmRh9cPz6EaF5uG8iJxO4kB3MvNsQ7lUe",
  "expires_at": "2026-11-26T10:12:00Z",
  "channels": ["document:doc_0193c1a2b7d84e1f9a2b3c4d5e6f7081"],
  "mode": "live"
}
```

## Follow the live events

The workspace's events as they happen, one server-sent event each, resumed after a drop with the last event id so none is missed.

`GET /v1/realtime`. Who may: Owner, Admin, Analyst and Viewer; Developer in test mode. CLI: `kontiga events tail [--channels <channel,...>] [--types <event,...>] [--last-event-id <evt_id>]`. MCP tool: `read_live_events`.

**Parameters**
- `channels` (array of string, default ["workspace"]): The channels to follow. Changing them means opening the stream again with `Last-Event-ID`. At most 20 items.
- `types` (array of string): Only these event types, such as `document.checked`, or every type of a product, such as `document`. Left out, every type. At most 50 items.
- `last_event_id` (id (evt_)): The page: the events after this one, oldest first, at most 50. The stream resumes from the `Last-Event-ID` header instead.

**Returns** page of events: The events after last_event_id, oldest first, each in the webhook envelope; the stream itself keeps sending as they happen.

API:

```bash
curl -X GET "https://api.kontiga.com/v1/realtime?channels=workspace&types=document&last_event_id=evt_0193c1a2c0027a2b8c3d4e5f60718293" \
  -H "Authorization: Bearer $KONTIGA_API_KEY"
```

CLI:

```bash
kontiga events tail \
  --channels workspace \
  --types document \
  --last-event-id evt_0193c1a2c0027a2b8c3d4e5f60718293
```

MCP tool `read_live_events`:

```json
{
  "name": "read_live_events",
  "arguments": {
    "channels": [
      "workspace"
    ],
    "types": [
      "document"
    ],
    "last_event_id": "evt_0193c1a2c0027a2b8c3d4e5f60718293"
  }
}
```

TypeScript:

```typescript
import Kontiga from "@kontiga/sdk";

const kontiga = new Kontiga(); // reads KONTIGA_API_KEY
const result = await kontiga.events.stream({
  channels: ["workspace"],
  types: ["document"],
  last_event_id: "evt_0193c1a2c0027a2b8c3d4e5f60718293",
});
```

Python:

```python
from kontiga import Kontiga

kontiga = Kontiga()  # reads KONTIGA_API_KEY
result = kontiga.events.stream(
    channels=["workspace"],
    types=["document"],
    last_event_id="evt_0193c1a2c0027a2b8c3d4e5f60718293",
)
```

Go:

```go
client := kontiga.NewClient() // reads KONTIGA_API_KEY
result, err := client.Events.Stream(ctx, &kontiga.EventsStreamParams{
	Channels:    []string{"workspace"},
	Types:       []string{"document"},
	LastEventId: "evt_0193c1a2c0027a2b8c3d4e5f60718293",
})
if err != nil {
	return err
}
```

Java:

```java
Kontiga kontiga = Kontiga.fromEnv(); // reads KONTIGA_API_KEY
var result = kontiga.events().stream(EventsStreamParams.builder()
    .channels(List.of("workspace"))
    .types(List.of("document"))
    .lastEventId("evt_0193c1a2c0027a2b8c3d4e5f60718293")
    .build());
```

.NET:

```csharp
var kontiga = new KontigaClient(); // reads KONTIGA_API_KEY
var result = await kontiga.Events.StreamAsync(new EventsStreamOptions
{
    Channels = new[] { "workspace" },
    Types = new[] { "document" },
    LastEventId = "evt_0193c1a2c0027a2b8c3d4e5f60718293",
});
```

PHP:

```php
$kontiga = new \Kontiga\Client(); // reads KONTIGA_API_KEY
$result = $kontiga->events->stream([
    'channels' => ['workspace'],
    'types' => ['document'],
    'last_event_id' => 'evt_0193c1a2c0027a2b8c3d4e5f60718293',
]);
```

Ruby:

```ruby
require "kontiga"

kontiga = Kontiga::Client.new # reads KONTIGA_API_KEY
result = kontiga.events.stream(
  channels: ["workspace"],
  types: ["document"],
  last_event_id: "evt_0193c1a2c0027a2b8c3d4e5f60718293"
)
```

Rust:

```rust
let kontiga = kontiga::Client::from_env()?; // reads KONTIGA_API_KEY
let result = kontiga
    .events()
    .stream(kontiga::events::StreamParams {
        channels: vec!["workspace".into()],
        types: vec!["document".into()],
        last_event_id: "evt_0193c1a2c0027a2b8c3d4e5f60718293".into(),
        ..Default::default()
    })
    .await?;
```

Response, 200 OK:

```json
{
  "object": "event_page",
  "events": [
    {
      "id": "evt_0193c1a2c0037a2b8c3d4e5f60718293",
      "type": "document.checked_fast",
      "created_at": "2026-11-26T09:41:51.204Z",
      "workspace": "ws_0193c1a2b3c44d5e8f60718293a4b5c6",
      "mode": "live",
      "data": { "object": { "id": "doc_0193c1a2b7d84e1f9a2b3c4d5e6f7081", "object": "document" } }
    },
    {
      "id": "evt_0193c1a2c0047a2b8c3d4e5f60718293",
      "type": "document.checked",
      "created_at": "2026-11-26T09:41:58.906Z",
      "workspace": "ws_0193c1a2b3c44d5e8f60718293a4b5c6",
      "mode": "live",
      "data": { "object": { "id": "doc_0193c1a2b7d84e1f9a2b3c4d5e6f7081", "object": "document" } }
    }
  ],
  "last_event_id": "evt_0193c1a2c0047a2b8c3d4e5f60718293"
}
```

With `Accept: text/event-stream` the call is the stream: `text/event-stream`, open until it ends. Without it, a reader that cannot hold a stream, such as an MCP tool, gets the page of events after `last_event_id` shown here, each naming its object, and calls again with the newest id.
