# Messages

Every JSON message of a session: the ones you send and the ones you receive.

Audio goes in binary frames; everything else is JSON text. Ignore message types and fields you do not know: new ones may be added.

## Messages you send

| Message | Does |
|---|---|
| a binary frame | Raw audio in the session's `encoding` and `sample_rate` (with `multichannel`, both channels interleaved), at most 1 s of it. |
| `{"type": "commit"}` | Ends the current segment now, in every mode (with `multichannel`, on both channels); its `final` follows. With nothing said since the last final, that final has an empty `text`. With `manual`, a commit does not restart recognition: a word still being said at that moment is not in the commit's final, it comes whole at the start of the next final. |
| `{"type": "end"}` | No more audio: the last `final` messages come, then `session.ended`, then the server closes with 1000. After `end`, only `ping` is answered. |
| `{"type": "ping"}` | Answered with `{"type": "pong"}`. |
| `{"type": "vocabulary", "entries": [...]}` | The session's own vocabulary entries, at most 250, in place of those of the message before (an empty list removes them); answered with `vocabulary.applied` ([The session's own list](https://platform.vatis.tech/docs/realtime/vocabularies#the-sessions-own-list)). A bad entry: `error` `invalid_parameter`, close 1008. |
| any other text | Not JSON, or another `type`: `error` `invalid_parameter` (`param` `type`), close 1008. |

Any message or audio resets the idle timeout (15 s).

## Messages you receive

| type | When | Fields |
|---|---|---|
| `session.started` | first, once the session is ready | `session_id` (`sess_` and 32 hex digits), `model_id`, `config` (every parameter as applied); `client_reference` when you sent one. |
| `partial` | when the text of the open segment changes | `segment_id` (the one its `final` will have), `text` (the segment so far, replaced by the next `partial` or by its `final`), `start` (the segment's), `end` (the end of the audio it covers). With `diarize=true`: `speaker` and `words` `[{text, start, end, speaker}]`; else with `timestamps=true`: `words` `[{text, start, end}]`. With `multichannel=true`: also `speaker` (`channel_0`, `channel_1`) and `channel` (`0`, `1`), on it and on its words. |
| `final` | a segment ended | `segment_id`, `text`, `start`, `end`, `speaker` (always there; `null` without `diarize` or `multichannel`), and with `timestamps=true` `words` `[{text, start, end, confidence, speaker}]`. With `multichannel=true` also `channel`, on it and on its words. With `commit=turn` also `end_reason` (`turn`, `pause`, `commit`, `end`: [What ended the segment](https://platform.vatis.tech/docs/realtime/end-of-turn#what-ended-the-segment)). Never revised; with `speaker_updates=true` its speakers come again in `final.speakers`. |
| `final.speakers` | after each `final`, with `speaker_updates=true` | `segment_id` (its final's), `speaker` (the segment's), and with `timestamps=true` `words` `[{text, start, end, confidence, speaker}]`: the final's words again, each with its speaker. Speakers only, never text or times ([The text first, its speakers after](https://platform.vatis.tech/docs/realtime/speakers-and-channels#the-text-first-its-speakers-after)). |
| `vocabulary.applied` | after each `vocabulary` message, once its entries are in effect | `entries` (the session's own entries now), `total` (with the saved vocabulary's; an entry in both counts once). In the order of the messages ([What you get back](https://platform.vatis.tech/docs/realtime/vocabularies#what-you-get-back)). |
| `session.ended` | after your `end` | `session_id`, `duration_s` (the audio received, 3 decimals; with `multichannel`, the length of the call, once). |
| `pong` | after a `ping` |  |
| `error` | the session is refused or fails | `code`, `message`, and `param` for `invalid_parameter`; then the server closes, with the message (up to 120 characters) as the close reason ([Errors in a session](https://platform.vatis.tech/docs/realtime/errors-in-a-session)). |

- Times are seconds from the start of the session's audio.
- A partial's `text` is its words joined with spaces. Partials have no `confidence`: it comes with the final.
- While a final waits for speaker separation, the partials behind it collapse to the newest one.
