Skip to content

ReferenceEvents and webhooks

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

Ask about this pageRead this page as Markdown

How the channel works

The realtime channel
What it does
AddressGET 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.
CredentialA 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.
Channelsworkspace 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.
EventsOne event of the catalogue 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 repeatsAt least once, in order. Drop an event id you have already seen.
ResumingReconnect 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.
HeartbeatsA comment line every 20 seconds keeps proxies from closing a quiet stream. With no byte for 45 seconds, reconnect with backoff and resume.
RefusalsBefore 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.
EndingsThe 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
// 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));
    }
  }
}

Mint a realtime token

Changes data

POST/v1/realtime/tokens

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.

Who may
Owner, Admin and Developer
CLI
kontiga realtime token [--channels <channel,...>]
MCP tool
create_realtime_token
Returns
The token, shown once, with when it expires; it carries the key’s workspace, mode and scopes.

Parameters

  • channelsarray of stringDefault ["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.

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"
    ]
  }'

POST /v1/realtime/tokens

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

Follow the live events

Reads only

GET/v1/realtime

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.

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
Returns
The events after last_event_id, oldest first, each in the webhook envelope; the stream itself keeps sending as they happen.

Parameters

  • channelsarray of stringDefault ["workspace"]

    The channels to follow. Changing them means opening the stream again with Last-Event-ID. At most 20 items.

  • typesarray 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_idid (evt_)

    The page: the events after this one, oldest first, at most 50. The stream resumes from the Last-Event-ID header instead.

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

GET /v1/realtime

Response, 200 OK
{
  "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.