Realtime Overview

Live subscriptions and optimistic mutations via Zero

The SDK includes a realtime layer powered by Zero, a local-first sync engine. Use it when you need live-updating data or instant optimistic writes.

import { setup, realtime } from '@start-chat/sdk'
import { channelMessages } from '@start-chat/sdk/queries'
await setup({ apiKey: 'sk_live_your_api_key' })
const sub = realtime.subscribe(
channelMessages,
{ serverId: 'srv_...', channelId: 'ch_...' },
(messages) => {
console.info('Messages:', messages.length)
},
)

API surface

11 subscriptions and 20 optimistic mutations — same queries and mutations as the REST API, but with instant local updates and offline support.

One-shot reads

Use run() for a single read through the realtime layer. This waits for the server to confirm the data is complete, then returns.

import { setup, run } from '@start-chat/sdk'
import { serverMembers } from '@start-chat/sdk/queries'
await setup({ apiKey: 'sk_live_your_api_key' })
const members = await run(serverMembers, { serverId: 'srv_...' }, 'complete')
ValueBehavior
'complete'Wait until server confirms all data is synced
'lazy'Resolve with whatever data is locally available

When to use which

ApproachLatencyOfflineUse case
query.*Server round-tripNoScripts, server-side, one-shot reads
mutate.*Server round-tripNoScripts, server-side, confirmed writes
realtime.subscribeInstant (local)YesLive UI, dashboards, bots with presence
realtime.mutate.*Instant (local)YesInteractive apps, chat UIs
run()Server-confirmedNoOne-shot reads that need freshness guarantee