# Start a live session

Opens a WebSocket that takes your audio and sends back partial and final text as it is spoken.

`WS /v1/speech-to-text/realtime` on `wss://api.eu.vatis.tech`

## Headers

| header | values | default | meaning |
|---|---|---|---|
| `Authorization` | `Bearer <api key>` | required | Your API key, on the handshake ([Authentication and API keys](https://platform.vatis.tech/docs/authentication)). A web page sends `token` instead. |

## Query parameters

| parameter | values | default | meaning |
|---|---|---|---|
| `model_id` | `vatis_ro_v9_realtime` | required | The real-time model: [List models](https://platform.vatis.tech/docs/endpoints/list-models) lists those your workspace can use. Missing, or one not listed: `invalid_parameter`. |
| `token` | a single-use `realtime` token |  | Instead of the `Authorization` header, for a web page ([Create a token](https://platform.vatis.tech/docs/endpoints/create-a-token)). An empty one counts as not sent. |
| `encoding` | `pcm_s16le`, `pcm_f32le`, `mulaw`, `alaw` | `pcm_s16le` | The audio you send, mono, or two channels with `multichannel`: [Audio formats](https://platform.vatis.tech/docs/realtime/sending-audio#audio-formats). |
| `sample_rate` | `pcm_s16le`, `pcm_f32le`: 8000, 16000, 22050, 24000, 44100, 48000; `mulaw`, `alaw`: 8000 | 16000; `mulaw`, `alaw`: 8000 | The audio's sample rate, in Hz. The API converts every rate to 16 kHz. |
| `language_code` | `ro` (also `ron`, `rum`, in any case) | the model's | Must match the model. |
| `commit` | `vad`, `manual`, `turn` | `vad` | What ends a segment: a pause (`vad`), your `commit` message (`manual`), or the end of the speaker's turn (`turn`): [Partial and final text](https://platform.vatis.tech/docs/realtime/partial-and-final-text). `turn` is for Romanian models only (else `invalid_parameter`, `param` `commit`), and each `final` then says what ended it in `end_reason`: [End of turn](https://platform.vatis.tech/docs/realtime/end-of-turn). |
| `vad_silence_s` | 0.2 to 3.0 | 1.5 | With `vad`: the pause, in seconds, that ends a segment. A shorter one gives faster finals, but cuts more of them in the middle of a sentence. With `turn`: the longest pause, after which a segment ends whatever the speaker sounds like. |
| `turn_sensitivity` | 0.0 to 1.0 | 0.5 | Only with `commit=turn` (else `invalid_parameter`, `param` `turn_sensitivity`). Higher answers sooner, and cuts more pauses inside a sentence; lower waits until the speaker sounds more clearly finished. |
| `timestamps` | `true`, `false` | `false` | `final` and `partial` messages carry their `words`, with times. |
| `diarize` | `true`, `false` | `false` | Speakers on `final` and `partial` messages and on their words: [Speakers in a session](https://platform.vatis.tech/docs/realtime/speakers-and-channels#speakers-in-a-session). |
| `num_speakers` | 1 to 8 |  | The number of speakers, when you know it. Only with `diarize=true` (else `invalid_parameter`). |
| `speaker_updates` | `true`, `false` | `false` | Only with `diarize=true` (else `invalid_parameter`). `true`: a `final` comes as soon as its text is done, and its speakers follow in a `final.speakers` message: [The text first, its speakers after](https://platform.vatis.tech/docs/realtime/speakers-and-channels#the-text-first-its-speakers-after). |
| `multichannel` | `true`, `false` | `false` | The audio has two channels, interleaved, each transcribed on its own; the channel is the speaker. Counts as 2 live sessions. Not with `diarize`: [Two-channel calls](https://platform.vatis.tech/docs/realtime/speakers-and-channels#two-channel-calls). |
| `remove_fillers` | `true`, `false` | `false` | `true`: filler words and hesitations are left out. |
| `punctuation` | `true`, `false` | `true` | Punctuation and capitals in final text, and in the finished part of a partial. `false`: lowercase words without punctuation. |
| `numbers` | `digits`, `words` | `digits` | Numbers in final text as digits, with times and units in their short form (`30`, `3:30`, `70km/h`). `words`: in words (`treizeci`). The words being spoken in a partial have numbers in words either way. |
| `entities` | `true`, `false` | the value of `punctuation` | Names, dates and the like. Given as `true`, each word of a `final` carries `entity`, the kind found or `null` (words come with `timestamps=true`). `false` turns the marking off. |
| `vocabulary_id` | a vocabulary id, `voc_...` |  | A saved list of names and terms to get right, in effect from the first word ([Vocabularies](https://platform.vatis.tech/docs/realtime/vocabularies)). An id that names no vocabulary of your workspace: `invalid_parameter`, message `vocabulary_id: no vocabulary with this id`. |
| `vocabulary_strength` | 0 to 2, a decimal number | `1.0` | How hard the service leans towards the vocabulary's entries, of both lists. Higher finds more of them, and also writes more of them where they were not said ([Strength](https://platform.vatis.tech/docs/realtime/vocabularies#strength)). |
| `client_reference` | at most 200 printable characters |  | Repeated in `session.started`, for your own logs. |
| `store` | `true`, `false` | `true` | `false`: nothing about the session is kept but its usage. Its Activity row has no id, model or key ([List activity](https://platform.vatis.tech/docs/endpoints/list-activity)). |

## Messages

1. **You receive `session.started`** once the session is ready. A refused session gets one `error` message instead, then the server closes.
2. **You send audio** in binary frames, at the pace of real time: 100 ms a frame gives the lowest latency, and 1 s is the most a frame can hold ([Sending audio](https://platform.vatis.tech/docs/realtime/sending-audio)).
3. **You receive `partial`** while a segment is spoken, each one replacing the last, and **`final`** when the segment ends ([Partial and final text](https://platform.vatis.tech/docs/realtime/partial-and-final-text)). With `speaker_updates=true`, each final's speakers follow in a `final.speakers`. With `commit=turn`, each final carries `end_reason`: `turn` when the speaker sounded finished ([End of turn](https://platform.vatis.tech/docs/realtime/end-of-turn)).
4. **You can send** `{"type": "commit"}` to end the segment now, and `{"type": "ping"}` while the source is paused. The server answers a ping with `{"type": "pong"}`. `{"type": "vocabulary", "entries": [...]}` sets the session's own vocabulary entries, answered with `vocabulary.applied` ([Vocabularies](https://platform.vatis.tech/docs/realtime/vocabularies)).
5. **You send `{"type": "end"}`** when the audio is over. The last `final` messages come, then `session.ended`, then the server closes with 1000 ([Ending a session](https://platform.vatis.tech/docs/realtime/ending-a-session)).

Every field of every message: [Messages you send](https://platform.vatis.tech/docs/realtime/messages#messages-you-send) and [Messages you receive](https://platform.vatis.tech/docs/realtime/messages#messages-you-receive).

## Responses

`101`: The WebSocket opens, and a good session starts with `session.started`. Every refusal comes after this point, as an `error` message and a close code, so a browser can read the reason too ([Errors in a session](https://platform.vatis.tech/docs/realtime/errors-in-a-session)).

```json
{
  "type": "session.started",
  "session_id": "sess_8d41c2a7e09b4f6a9c03d5e1b2a7f480",
  "model_id": "vatis_ro_v9_realtime",
  "config": {
    "model_id": "vatis_ro_v9_realtime",
    "encoding": "pcm_s16le",
    "sample_rate": 16000,
    "language_code": "ro",
    "commit": "vad",
    "vad_silence_s": 1.5,
    "timestamps": false,
    "diarize": true,
    "num_speakers": null,
    "multichannel": false,
    "remove_fillers": false,
    "punctuation": true,
    "numbers": "digits",
    "store": true
  }
}
```

`1000`: The normal end, after your `end` and `session.ended`.

`1008` `unauthorized`: No key or token, or one that is not valid: a wrong, revoked or expired key; a used, expired or wrong-type token.

`1008` `invalid_parameter`: A query parameter that is unknown, empty, not supported or out of range (`param` names it), one sent without the one it needs (`turn_sensitivity` without `commit=turn`), `commit=turn` with a model that is not Romanian, a `vocabulary_id` that names no vocabulary of your workspace, a `vocabulary` message with a bad entry (`param` `entries[3]`), or a text message the server does not know (`param` `type`).

```json
{
  "type": "error",
  "code": "invalid_parameter",
  "message": "diarise: unknown parameter",
  "param": "diarise"
}
```

`1013` `capacity`: Every live session your workspace may have open is in use (a two-channel session needs 2), or there is no free capacity for a new session. A workspace runs 10 at a time ([Work at once](https://platform.vatis.tech/docs/limits#work-at-once)).

```json
{
  "type": "error",
  "code": "capacity",
  "message": "This account can run 10 real-time sessions at a time: try again when one ends."
}
```

`1013` `account_paused`: An `error` before `session.started`, or in an open session about a minute after the pause, after its last finals: the workspace is paused, its credit used up or over its hourly spend limit. The message says which ([While a workspace is paused](https://platform.vatis.tech/docs/limits#while-a-workspace-is-paused)).

```json
{
  "type": "error",
  "code": "account_paused",
  "message": "The account's credit is used up: add credit on platform.vatis.tech to continue."
}
```

`1008` `idle_timeout`: 15 s without any message or audio. While your source is paused, send silence or `{"type": "ping"}`.

`1008` `session_time_limit`: The session reached the longest a session runs: 4 hours. Its last finals come before the error. Open a new session to go on.

`1009` `audio_chunk_too_large`: A frame of more than 1 s of audio. Send smaller frames: 100 ms is best.

`1009`: A WebSocket message over 1 MiB closes the connection at once, without an error message.

`1011` `transcriber_error`: The speech service or speaker separation failed, was not available at the start, or did not finish within 30 s of your `end`. The close code is 1012 when a speech service stopped for an update.

`1011` `internal_error`: An error on our side, or a saved vocabulary (`vocabulary_id`) that cannot be read for a moment. Connect again in a few seconds.

`1012` `service_restart`: The service restarts, for an update. The `final` messages of all the audio it received come first, and `resume_s` says from which second to send the audio again ([Reconnect after a restart](https://platform.vatis.tech/docs/realtime/reconnect-after-a-restart)).

```json
{
  "type": "error",
  "code": "service_restart",
  "message": "The service is restarting: connect again in a few seconds.",
  "resume_s": 62
}
```

`1006`: No error message: the connection dropped, or it failed before the WebSocket opened (a wrong host or path).

## Notes

- **Example address:** `wss://api.eu.vatis.tech/v1/speech-to-text/realtime?model_id=vatis_ro_v9_realtime&sample_rate=16000&timestamps=true&diarize=true`
- **Booleans** are `true` or `false` (also `1` or `0`).
- **Strict query:** an unknown parameter or an empty value is refused with `invalid_parameter`, message `<name>: unknown parameter` or `<name>: empty`, and `param` names it ([Strict parameters](https://platform.vatis.tech/docs/errors#strict-parameters)). An empty `token` counts as not sent. A parameter given twice takes the last value.
- `session.started` repeats every parameter as applied, in `config`, without the token. With `vocabulary_id` or `vocabulary_strength` it also has `vocabulary_entries`, the saved vocabulary's entries when the session started, never the entries themselves. With `commit=turn` it has `turn_sensitivity` too, `"commit": "turn", "turn_sensitivity": 0.5` (the key is absent in other modes).
- **`multichannel`:** every message and word carries `channel` (`0`, `1`) and the speaker `channel_0` or `channel_1`. With `diarize` it is `invalid_parameter` (`param` `diarize`). It needs 2 of your workspace's live sessions free.
- **Romanian only** on the cloud for now: an English model is not listed yet ([Not in this release](https://platform.vatis.tech/docs/limits#not-in-this-release)).
- **No transcript is kept** of a live session: keep the finals you receive. The session counts as usage when it ends, the audio it received ([Get usage](https://platform.vatis.tech/docs/endpoints/get-usage)).
- **A session that ends early** (a restart, a dropped connection) can go on in a new one, from where its finals end: [Reconnect after a restart](https://platform.vatis.tech/docs/realtime/reconnect-after-a-restart).
