Realtime Queries

Live query references available via realtime.subscribe and run()

The same queries available as one-time REST calls can also be used in realtime. Import from @start-chat/sdk/queries and pass to realtime.subscribe for live updates or run() for a one-shot read through the sync layer.

import { setup, realtime, run } from '@start-chat/sdk'
import { channelMessages } from '@start-chat/sdk/queries'
await setup({ apiKey: 'sk_live_your_api_key' })
// live subscription
const sub = realtime.subscribe(
channelMessages,
{ serverId: 'srv_...', channelId: 'ch_...' },
(data) => console.info('updated:', data.length),
)
// or one-shot read
const messages = await run(
channelMessages,
{ serverId: 'srv_...', channelId: 'ch_...' },
'complete',
)

serverById

Get server details by ID.

ParameterTypeRequired
serverIdstringYes
import { serverById } from '@start-chat/sdk/queries'
const sub = realtime.subscribe(serverById, { serverId: 'srv_...' }, (data) => {
console.info('serverById updated:', data)
})

serverMembers

List members of a server.

ParameterTypeRequired
serverIdstringYes
limitnumberNo
import { serverMembers } from '@start-chat/sdk/queries'
const sub = realtime.subscribe(serverMembers, { serverId: 'srv_...' }, (data) => {
console.info('serverMembers updated:', data)
})

userServers

List servers the authenticated user belongs to.

ParameterTypeRequired
userIdstringNo
import { userServers } from '@start-chat/sdk/queries'
const sub = realtime.subscribe(userServers, {}, (data) => {
console.info('userServers updated:', data)
})

searchJoinableServers

Search for public servers the user can join.

ParameterTypeRequired
userIdstringNo
searchstringNo
limitnumberNo
import { searchJoinableServers } from '@start-chat/sdk/queries'
const sub = realtime.subscribe(searchJoinableServers, {}, (data) => {
console.info('searchJoinableServers updated:', data)
})

channelsByServer

List all channels in a server.

ParameterTypeRequired
serverIdstringYes
import { channelsByServer } from '@start-chat/sdk/queries'
const sub = realtime.subscribe(channelsByServer, { serverId: 'srv_...' }, (data) => {
console.info('channelsByServer updated:', data)
})

channelById

Get channel details by ID.

ParameterTypeRequired
channelIdstringYes
import { channelById } from '@start-chat/sdk/queries'
const sub = realtime.subscribe(channelById, { channelId: 'ch_...' }, (data) => {
console.info('channelById updated:', data)
})

channelMessages

Fetch messages in a channel. Supports cursor-based pagination, filtering, and limit control.

ParameterTypeRequiredDescription
serverIdstringYes
channelIdstringYes
fromOrderstringNo
around'before' | 'after'Nobefore, after
limitnumberNo
solobooleanNo
channelFilter'thread' | 'chat' | 'app' | 'pinned'Nothread, chat, app, pinned
appendingFromOrderstringNo
import { channelMessages } from '@start-chat/sdk/queries'
const sub = realtime.subscribe(
channelMessages,
{ serverId: 'srv_...', channelId: 'ch_...' },
(data) => {
console.info('channelMessages updated:', data)
},
)

messageById

Get a single message by ID.

ParameterTypeRequired
messageIdstringYes
import { messageById } from '@start-chat/sdk/queries'
const sub = realtime.subscribe(messageById, { messageId: 'msg_...' }, (data) => {
console.info('messageById updated:', data)
})

threadWithMessages

Get a thread and all its messages.

ParameterTypeRequired
threadIdstringYes
serverIdstringYes
import { threadWithMessages } from '@start-chat/sdk/queries'
const sub = realtime.subscribe(
threadWithMessages,
{ threadId: 'thr_...', serverId: 'srv_...' },
(data) => {
console.info('threadWithMessages updated:', data)
},
)

threadById

Get thread metadata by ID.

ParameterTypeRequired
threadIdstringYes
import { threadById } from '@start-chat/sdk/queries'
const sub = realtime.subscribe(threadById, { threadId: 'thr_...' }, (data) => {
console.info('threadById updated:', data)
})

userById

Get user profile by ID.

ParameterTypeRequired
userIdstringYes
import { userById } from '@start-chat/sdk/queries'
const sub = realtime.subscribe(userById, { userId: 'usr_...' }, (data) => {
console.info('userById updated:', data)
})