Cosmo Realtime SDK
Concepts

Realtime events

Every message on the data channel, grouped by direction and family — the protocol at a glance.

All control traffic is JSON on a reliable LiveKit data channel, discriminated by a type field. This page is the map; each SDK exposes the same events with language-native names (TypeScript session.on('transcript', …), Python RealtimeTranscriptDelta, Swift case .transcript).

Two framing rules apply to everything below:

  • Oversized messages are chunked. Anything above the ~15 KiB data-channel limit travels as envelope-chunk / server-envelope-chunk frames and is reassembled before your handler fires. You never see chunks. See Envelope chunking.
  • Unknown types are not errors. SDKs surface unrecognized type values as an explicit unknown event and keep going. New server events never break old clients.

Client → server

TypePurpose
session-configFirst frame after joining the room: protocol version + agent config + session params. The server replies with ready.
muteToggle the server-side microphone gate.
send-textA text turn instead of audio — the agent answers it.
send-contextContext the agent should have without being asked anything: no turn, no speech, no transcript entry. For live application state.
send-imageOne base64 image frame (mime_type, stream_id). See Image input.
activity-endManual end-of-turn signal when you're running your own turn detection. See Turn-taking.
bind-inputBind the agent's audio input to this participant (the SDK sends it when you publish audio).
tool_job_resultDeferred result of a background client tool (job_id, status, result).
endGraceful goodbye; the server tears down the upstream session.
pingHeartbeat; server replies pong.
envelope-chunkFraming carrier for oversized client messages.

Server → client

Session lifecycle

TypeFired whenPayload highlights
readyAgent is live and listeningsession_id, resolved agent summary, rejected_tools, max_session_seconds
reconnectingServer is rotating the upstream model session; a brief pause, not a failureseconds_remaining
session-ending-soonWall-clock cap approachingseconds_remaining, reason
session-endedServer ended the session deliberatelyreason (e.g. max_session_duration)
errorSomething went wrongcode, message, fatal — non-fatal errors do not end the session
pongReply to ping

Every SDK guarantees a terminal session-ended item as the last event on the stream, synthesized locally if the transport died before the server could say goodbye.

Transcripts and model text

TypeFired whenPayload highlights
transcriptSpeech transcribed, either speakerrole, text, is_final — streaming events append; the final event replaces the accumulated text
model-textThe model emits text alongside (or instead of) audiotext, is_final
turn-completeA turn ended; finalize UI staterole

Which one to display for which UI is covered in Transcripts.

Speech activity and model processing

These are informational, type-only markers — ideal for driving avatars, level meters, and "thinking…" indicators:

TypeMeaning
user-started-speaking / user-stopped-speakingServer VAD detected user voice start/stop
bot-started-speaking / bot-stopped-speakingFirst/last audio frame of the assistant turn
bot-llm-started / bot-llm-stoppedModel began/finished generating
bot-tts-started / bot-tts-stoppedSpeech synthesis began/finished
user-speech-timeoutA server silence-timeout hook fired: silence_ms, trigger_count, max_count, and the action the server already took

Tools

Four events cover both dispatch directions — see Tools:

TypeFired when
tool-callThe model decided to invoke a tool
tool-dispatch-startedThe server-side handler began executing
tool-resultThe handler finished (ok, summary)
tool-invocationThe server asks this client to run a local tool (request_id, name, args)

The three observability events share a tool_call_id so you can render a timeline per invocation.

First-party extensions

Cosmo-specific events are namespaced cosmo.*:

TypePurpose
cosmo.usageCumulative token usage, split by input/output and text/audio/image/cached
cosmo.session-stateThe durable session state after a cosmo.set_state write (state, updated_keys, stage) — see Session state

Ordering guarantees

  • ready always precedes transcripts, tool events, and speech markers.
  • The three tool observability events arrive in order for a given tool_call_id, but events from different tool calls interleave.
  • Transcript deltas for one turn arrive in order; turn-complete follows the final transcript of that turn.
  • The terminal session-ended item is always last; nothing follows it.

Wire reference

Exact schemas for every message live in the wire protocol reference. The protocol carries version (currently 1.0) on session-config and ready; see Protocol version for how breaking changes are signaled.

On this page