Create a realtime conversation
/v1/realtimeEstablish a continuous two-way realtime session over WebSocket, stream in voice, camera, or screen frames, and receive streamed text and voice responses.
Connection and authentication
Upgrade an HTTP GET request to WebSocket. Connect to wss://api.mosi.cn/v1/realtime with the model query parameter specifying the model; place the API Key only in the Authorization request header.
Model ID. Always moss-live-1.0, passed in the model query parameter of the WebSocket URL.
Your own stable end-user ID, URL-encoded. Required when memory_scope=user; use the same user when reconnecting. Example: wss://api.mosi.cn/v1/realtime?model=moss-live-1.0&user=customer_001.
Bearer <API Key>; put it in the Authorization request header of the WebSocket handshake.
Session flow
| Stage | Client | Server events and checks |
|---|---|---|
| Connect | Complete the WebSocket handshake | Join the session after the connection opens |
| Configure | Send attach_session, then session.update | Wait for session_attached and then session.updated, and confirm data.error is an empty string |
| Send audio and video | Enable the microphone; for frames, enable media.mode and video.state | The same connection receives audio and JPEG frames |
| Answer | Display text, play voice, and send playback acknowledgements | Receive input.transcript.done, output.transcript.done, and response.ended |
| Continue or end | Keep sending input, or close the WebSocket | The connection can continue after a turn completes; closing the connection ends the session |
Client events
Joins the session; billing by online duration starts once session_attached is received.
Sets the persona and business rules; after receiving session.updated, check data.error. A non-empty value means the configuration did not take effect.
Turns microphone input on or off.
Enables tagged-v1 before video or screen sharing.
Controls camera or screen frames; turning frames off does not end the session.
Sent after each audio chunk has actually finished playing; put the fields at the top level of the message, not inside data. Acknowledge only audio that has actually finished playing, and do not wait for the answer text to finish before acknowledging.
Sent after receiving response.audio.done and finishing playback of all audio in the turn.
Sets the primary frame source to focus on.
Sent after stopping the corresponding playback on response.audio.stop.
Server events
The session has been joined; configure the persona and business rules after receiving it.
Configuration result; enable media and the microphone when data.error is an empty string.
User transcript update; data.text is the current full text, so replace the displayed text instead of appending each update.
User transcript completed.
Model answer text update; data.text is the current full text, so replace the displayed text instead of appending each update.
Model answer text completed.
The answer was interrupted; mark the matching answer as interrupted by run_id and turn_id.
Save the audio context and pair it in order with the following binary audio.
All audio for this turn has been sent; send playback.completed after playback has actually finished.
Status notification for this turn; it does not mean the session has ended.
Error event; record the cause and release the connection and media resources.
Stop the corresponding voice playback and send playback.stopped.
Protocol limits
| Item | Current protocol value and description |
|---|---|
| Audio | 16 kHz upstream and 48 kHz downstream, mono PCM S16LE; no WAV header. Keep sending silence after the user stops speaking. |
| Media framing | tagged-v1: audio 0x00, camera JPEG 0x01, screen JPEG 0x02; audio keeps the prefix after frames are turned off. |
| Frames | One binary message per JPEG; no Base64, and complete MP4 files or H.264 streams are not accepted. |
| Transport | Audio and frames share the same WebSocket. |
| Frame processing | Under load, the latest frame may be kept and pending older frames dropped; per-frame analysis is not guaranteed. 1 FPS, JPEG quality 0.8, a 640 px long edge for the camera, and 1024 px for the screen are client defaults, not hard limits. |
Error codes
For authentication, permissions, rate limiting, and general HTTP errors during connection, see Error Codes. The following are protocol errors specific to the MOSS-LIVE endpoint.
| Error codes | Trigger | Action |
|---|---|---|
| memory_scope_requires_user | The user memory scope lacks an end-user identity | Pass a stable user, or use the session scope. |
| memory_scope_immutable | Creation options changed on reconnect | Reconnect with the options used at creation; create a new session to change them. |
| invalid_memory_scope | Invalid parameter value | Check the enum values. |