Realtime video understanding
/v1/realtimeContinuously send image frames and questions over WebSocket and receive incremental text events. This is a visual understanding protocol, incompatible with audio Realtime, and is not SSE.
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. Pass a stable or snapshot ID in the WebSocket connection's model query parameter
Bearer <API Key>; query parameters and WebSocket subprotocols are not supported for authentication
Session flow
| Stage | Client | Server events and checks |
|---|---|---|
| Connect | Complete the WebSocket handshake | Receive session.created; the connection automatically creates a session |
| Configure | Send session.configure exactly once | Receive session.configured and wait for session.ready |
| Send an image | Send input.frame JSON followed by image binary data | Wait for input.frame.ready before sending binary data; wait for input.frame.accepted before sending the next input. Frames alone do not automatically generate answers |
| Ask a question | Send input.prompt separately | No need to attach the image again; receive accepted / processed, and possibly text, silence, or interruption events |
| Continue or finish | Continue sending frames, set final=true, or send session.abort | response.done ends one answer segment; session.done ends the session |
Client events
Send exactly once after connecting, within session.created.configure_timeout_s.
Send image frame metadata; immediately send the complete image binary data after receiving input.frame.ready.
Send a question separately. The field is prompt, not text; the question uses the most recently received scene.
End the entire session. This event does not consume seq_no and accepts no other fields.
Server events
Determine connection, configuration, readiness, and the final session state.
Determine whether frames or questions are ready to receive, submitted, or processed.
Read incremental text and determine whether an answer segment is silent, interrupted, or complete.
Read observational usage and cumulative usage for an answer or session.
Handle protocol or service failures.
Protocol limits
| Item | Current protocol value and description |
|---|---|
| Control events | Each event defaults to at most 256 KiB; calculated separately from image binary size |
| Configuration and delivery | Configure within the server deadline; deliver binary data within 10 seconds after input.frame.ready, or the server sends an error event with code=session_timeout and ends the session |
| Input queue | Defaults to 4, configurable range [1, 256]; unprocessed input capacity, not concurrent sessions |
| Context and duration | Whichever is reached first: the returned context_limit or the session duration limit |
Error codes
For authentication, permissions, rate limiting, and general HTTP errors during connection, see Error Codes. The following are protocol errors specific to realtime video understanding.
| Error codes | Trigger | Action |
|---|---|---|
| invalid_request | Invalid client event/fields/order or oversized message | Correct and resend; reconnect if disconnected |
| context_exhausted | Session context limit reached | End the session and create a new one |
| session_timeout | Session duration or idle limit reached, or binary data not delivered within 10 seconds after input.frame.ready | Check session activity and server limits; reconnect if needed |
| response_failed | Model generation or processing failed | Record the error and decide whether to retry for your use case |
| session_capacity_exceeded | Realtime session capacity exhausted | Reduce concurrency or retry later |
Connection closure
| Close code | Meaning | Client action |
|---|---|---|
| 1000 | Closed after the server sent session.done; sessions that ended with an error event also use this code | End the session without retrying; judge success by session.done.reason (such as completed, aborted, error) and any preceding error event |
| 1001 | Service shutdown or connection leaving | Reconnect as required by your use case |
| 1002 | Protocol error | Check event format and send order before retrying |
| 1009 | Binary data exceeds limits or control event is too large; an invalid_request error event may precede closure. | Reduce message size and reconnect |
| 1011 | Server failure | Retry later and record the error |
| 1013 | Service temporarily unable to process | Reduce concurrency and retry later |