Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions api-reference/asyncapi-asr-realtime.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@ channels:
type: string
enum:
- transcribe-stream-1
- transcribe-stream-2
default: transcribe-stream-1
description: Realtime speech-to-text model. Optional; `transcribe-stream-1` (Preview) is the default and the only realtime model. The legacy name `transcribe-1-pro-realtime` reaches the same model.
description: Realtime speech-to-text model. Optional; `transcribe-stream-1` (Preview) is the default. Without the header, or with any other value, the session runs on `transcribe-stream-1`. `session_started.config.model` names the session's model.
description: |
Realtime speech-to-text channel. Clients stream audio and receive
transcripts turn by turn, with turn detection, optional live drafts and
Expand All @@ -102,6 +103,7 @@ channels:
## Connection Headers
- `Authorization: Bearer <api_key>` - Required for authentication (see security section)
- `model: transcribe-stream-1` (Preview) - Optional; the default
- `model: transcribe-stream-2` - Optional; the only model that takes `results.text_format`

Every message in both directions is one MessagePack map in a binary
frame, with a `type` field. Send `config` first, wait for
Expand Down Expand Up @@ -477,7 +479,7 @@ components:
description: Same as the `x-request-id` response header. Include it when you contact support.
config:
type: object
description: The effective configuration, with defaults filled in.
description: The effective configuration, with defaults filled in. `model` names the session's model.
limits:
$ref: "#/components/schemas/AsrLimits"
description: |
Expand Down Expand Up @@ -1180,6 +1182,21 @@ components:
type: boolean
default: true
description: Sound tags such as `[laughter]` in the text; `false` removes them. Only `true` or `false`.
text_format:
oneOf:
- type: string
enum:
- spoken
- written
- type: "null"
default: written
description: |
`transcribe-stream-2` only; choose it in `config`, for the
whole session. The style for numbers, amounts and times:
`spoken` (words, the way they were said) or `written` (digits
and symbols). `null` is the same as leaving it out.
`transcribe-stream-1` refuses this field, whatever its value,
`null` included, with `invalid_config`.
vad_events:
type: boolean
default: false
Expand Down
64 changes: 48 additions & 16 deletions api-reference/endpoint/websocket/asr-realtime.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
asyncapi: "/api-reference/asyncapi-asr-realtime.yml asrRealtime"

Check failure on line 2 in api-reference/endpoint/websocket/asr-realtime.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

Vale.Spelling

Did you really mean 'asrRealtime'?

Check failure on line 2 in api-reference/endpoint/websocket/asr-realtime.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

Vale.Spelling

Did you really mean 'asrRealtime'?
title: "WebSocket Realtime Speech to Text"
description: "Stream audio over a WebSocket and receive transcripts turn by turn, with turn detection, live drafts and conversation context"
icon: "webhook"
Expand Down Expand Up @@ -30,14 +30,14 @@
model: transcribe-stream-1
```

| Header | Required | Description |
| --------------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
| `Authorization` | Yes | `Bearer <API key>`. Write the scheme exactly as `Bearer`, followed by a space and the key. |
| `model` | No | `transcribe-stream-1` (Preview), the default and the only realtime model. The legacy name `transcribe-1-pro-realtime` reaches the same model. |
| Header | Required | Description |
| --------------- | -------- | ------------------------------------------------------------------------------------------------------------------ |
| `Authorization` | Yes | `Bearer <API key>`. Write the scheme exactly as `Bearer`, followed by a space and the key. |
| `model` | No | The realtime model: `transcribe-stream-1` (Preview), the default, or `transcribe-stream-2`. See [Models](#models). |

Each open connection counts against the same concurrency limit as your other API requests, from the moment it opens until it closes, even while you send no audio. See [Concurrent request limits](/developer-guide/models-pricing/pricing-and-rate-limits#concurrent-request-limits). A session cannot be resumed: a new connection is a new session.

Sessions are billed per second of session duration, as Realtime ASR. See [ASR pricing](/developer-guide/models-pricing/pricing-and-rate-limits#automatic-speech-recognition-asr-models).
Sessions are billed per second of session duration, as Realtime ASR, at the price of the session's model. See [ASR pricing](/developer-guide/models-pricing/pricing-and-rate-limits#automatic-speech-recognition-asr-models).

If the server refuses the upgrade, it answers with a plain HTTP response whose JSON body is `{"status": <int>, "message": <str>}`:

Expand All @@ -46,9 +46,24 @@
| 401 | The API key is missing or invalid, or the `Authorization` header does not start with `Bearer `. | Check the key and the header. |
| 402 | Insufficient API credit. | Top up your balance. |
| 429 | Your team is at its concurrency limit, or the service is at capacity. | Retry with backoff. Honor `Retry-After` when present. |
| 503 | The service is restarting. | Retry. |
| 502 | The service could not be reached. | Retry with backoff. |
| 503 | The service is restarting or temporarily unavailable. | Retry with backoff. |
| 504 | The service did not answer in time. | Retry with backoff. |

The `101 Switching Protocols` response carries an `x-request-id` header, and so do the capacity 429 and 503 refusals. It is the same value as `request_id` in `session_started`, `error` and `session_done`. Log it, and include it when you contact support. Refusals for the key, balance and your concurrency limit (401, 402 and concurrency 429) happen before a session is assigned and carry no `x-request-id`.
The `101 Switching Protocols` response carries an `x-request-id` header, and so does the capacity 429 refusal. It is the same value as `request_id` in `session_started`, `error` and `session_done`. Log it, and include it when you contact support. Refusals for the key, balance and your concurrency limit (401, 402 and concurrency 429) happen before a session is assigned and carry no `x-request-id`. A 502, 503 or 504 refusal can come with or without one.

### Models

| Model | Price | Notes |
| ------------------------------- | -------------------- | ----------------------------------------------------------------------------- |
| `transcribe-stream-1` (Preview) | $0.36 / session hour | The default. |
| `transcribe-stream-2` | $0.12 / session hour | Takes [`results.text_format`](#text-format), the style for numbers and times. |

Both models use this endpoint and the protocol on this page: the same messages, turn detection modes, errors and limits. The one difference is `results.text_format`, which only `transcribe-stream-2` takes.

Choose the model with the `model` header, written exactly as shown. A connection without the header, or with any other value, gets a `transcribe-stream-1` session, billed as `transcribe-stream-1`, and no error is returned.

A connection that names `transcribe-stream-2` is meant to be served by `transcribe-stream-2`. While that model is temporarily unavailable, the handshake can be [refused](#connect) with a 5xx status; connect again with backoff. Or the session can start, and its turns can get `error` with [`engine_error`](#errors-and-close-codes), each followed by a [degraded `committed`](#degraded-commits); the session continues. `session_started.config.model` names the model that serves the session, and the session is billed at that model's price, so check it when the session starts.

## Framing

Expand Down Expand Up @@ -115,17 +130,18 @@
| `results.ignore_timestamps` | No | `true` | `false` adds word timings (`words`) to `committed`. |
| `results.diarize` | No | `true` | `true`, `false` or `"auto"` (same as `true`); the strings `"true"` and `"false"` are accepted too. `false` removes speaker tags from the text. See [Speakers](#speakers). |
| `results.tag_audio_events` | No | `true` | `false` removes sound tags such as `[laughter]` from the text. See [Sound tags](#sound-tags). |
| `results.text_format` | No | `"written"` | `transcribe-stream-2` only. The style for numbers, amounts and times: `"spoken"` (words) or `"written"` (digits and symbols). See [Text format](#text-format). |
| `results.vad_events` | No | `false` | `true` sends [`vad`](#vad) messages. |
| `results.eot_events` | No | `false` | `true` sends [`eot_prob`](#eot_prob) messages. |
| `context.history` | No | `[]` | Earlier conversation, oldest first: up to 32 items of `{ "role": "user" \| "assistant", "text": str }`, each up to 2,000 characters. |
| `context.terms` | No | `[]` | Up to 100 terms of up to 32 characters each: names, products and jargon to recognize. |
| `client_reference_id` | No | | Your own ID for the session, up to 256 characters. It is recorded with the session and not sent back. |

A value of the wrong type for `ignore_timestamps` or `tag_audio_events` (both take only `true` or `false`), or a `diarize` value other than those listed, is `invalid_config`. So is an unknown field, including a misspelled one; the error's `message` names the field. `invalid_config` closes the connection with 4400. Send only the fields listed here: not every other field is refused, so check `session_started.config`, which shows the settings in effect.
A value of the wrong type for `ignore_timestamps` or `tag_audio_events` (both take only `true` or `false`), a `diarize` value other than those listed, or a `text_format` other than `"spoken"`, `"written"` or `null`, is `invalid_config`. So is an unknown field, including a misspelled one; the error's `message` names the field. `invalid_config` closes the connection with 4400. Send only the fields listed here: not every other field is refused, so check `session_started.config`, which shows the settings in effect.

#### Audio format

Send 16-bit little-endian PCM, mono, at one of the listed sample rates. Other encodings (such as μ-law, A-law or Opus) and stereo audio are `unsupported_audio`; decode phone audio in μ-law or A-law to 16-bit PCM first, and send it at 8000 Hz as is. Audio at 16000 Hz is used as is; every other rate is converted on the server, so you never need to resample. The conversion adds at most about 20 ms of delay. Every `*_ms` value is in milliseconds of your audio, whatever its rate.

Check failure on line 144 in api-reference/endpoint/websocket/asr-realtime.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

Vale.Spelling

Did you really mean 'resample'?

Check failure on line 144 in api-reference/endpoint/websocket/asr-realtime.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

Vale.Spelling

Did you really mean 'resample'?

An `audio` message can hold any number of bytes; an odd trailing byte waits for the next message. Anything from 20 to 100 ms of audio per message works and gives the same results, but each result waits for the message that carries its audio, so smaller messages give lower latency. For live audio, 20–40 ms per message is a good size. A message can be at most 1 MiB, which holds 65.5 seconds of audio at 8 kHz or 10.9 seconds at 48 kHz.

Expand All @@ -134,8 +150,8 @@
| Mode | A turn ends when | Use it for |
| -------- | --------------------------------------------------------------------------------------------- | -------------------------------------------- |
| `auto` | The server's turn detection judges that the speaker has finished, from what was said and how. | Voice agents and conversations. The default. |
| `vad` | `silence_timeout_ms` of silence has passed (default 700 ms). | Fixed silence-based endpointing. |

Check failure on line 153 in api-reference/endpoint/websocket/asr-realtime.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

Vale.Spelling

Did you really mean 'endpointing'?

Check failure on line 153 in api-reference/endpoint/websocket/asr-realtime.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

Vale.Spelling

Did you really mean 'endpointing'?
| `manual` | You send `finalize`. | Push-to-talk, or your own endpointing. |

Check failure on line 154 in api-reference/endpoint/websocket/asr-realtime.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

Vale.Spelling

Did you really mean 'endpointing'?

Check failure on line 154 in api-reference/endpoint/websocket/asr-realtime.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

Vale.Spelling

Did you really mean 'endpointing'?

**`auto`.** A turn opens as soon as voice activity is detected. The server then judges whether this is the user taking their turn. If it is, the server sends `user_turn_taken`, and it ends the turn when the speaker has finished, not on silence alone. A short pause in the middle of a sentence usually does not end the turn; a speaker who stops mid-sentence and does not go on has the turn ended about 2 seconds after they stopped. `silence_timeout_ms` is only a safety net here.

Expand Down Expand Up @@ -175,7 +191,7 @@

Audio in the format from `config`. `data` must be MessagePack `bin` holding the raw PCM bytes. Do not base64-encode the audio, and do not send it as a string or an array of numbers. If you do, you receive a recoverable `invalid_request`, and those messages are dropped: nothing in them is transcribed or counted as received audio.

Send audio after `session_started` (see [`config`](#config) for audio sent earlier). For live audio, send it as it is captured, 20–40 ms per message (see [Audio format](#audio-format)). If your client batches small writes (Nagle's algorithm), turn that off with `TCP_NODELAY`; browsers and common WebSocket libraries already send each message right away. You can send faster than real time, for example from a file: the server accepts it and reads it at a bounded rate, and results keep following the audio.

Check failure on line 194 in api-reference/endpoint/websocket/asr-realtime.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

Vale.Spelling

Did you really mean 'Nagle's'?

Check failure on line 194 in api-reference/endpoint/websocket/asr-realtime.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

Vale.Spelling

Did you really mean 'Nagle's'?

### `finalize`

Expand All @@ -198,7 +214,7 @@
}
```

Change settings during the session. `turn_detection`, `results` and `context` take the same values as in `config`; every field is optional, and a field you leave out keeps its current value. `context` accepts `terms` only, and the new list replaces the old one; send earlier lines with [`context_add`](#context_add). The server answers with [`configured`](#configured). If any value is invalid, nothing in the message is applied.
Change settings during the session. `turn_detection`, `results` and `context` take the same values as in `config`, except `results.text_format`, which is set in `config` for the whole session. Every field is optional, and a field you leave out keeps its current value. `context` accepts `terms` only, and the new list replaces the old one; send earlier lines with [`context_add`](#context_add). The server answers with [`configured`](#configured). If any value is invalid, nothing in the message is applied.

`audio` is fixed for the session: to change the audio format, open a new session. A `configure` with an unknown field, with an `audio` that differs from the session's, or with `context.history` gets `configured` with `ok: false`, and nothing in it is applied. An `audio` identical to the session's is accepted. As with `config`, send only the fields listed here; `configured.config` shows the settings in effect.

Expand Down Expand Up @@ -258,12 +274,12 @@

### `session_started`

| Field | Type | Description |
| ------------ | ------ | --------------------------------------------------------------------------------- |
| `session_id` | string | The session's ID. |
| `request_id` | string | The same value as the `x-request-id` header. Include it when you contact support. |
| `config` | map | The effective configuration, with defaults filled in. |
| `limits` | map | `max_session_ms`, `max_turn_ms` and `max_frame_bytes`. See [Limits](#limits). |
| Field | Type | Description |
| ------------ | ------ | ----------------------------------------------------------------------------------------------- |
| `session_id` | string | The session's ID. |
| `request_id` | string | The same value as the `x-request-id` header. Include it when you contact support. |
| `config` | map | The effective configuration, with defaults filled in. `config.model` names the session's model. |
| `limits` | map | `max_session_ms`, `max_turn_ms` and `max_frame_bytes`. See [Limits](#limits). |

Send audio after this message.

Expand Down Expand Up @@ -333,7 +349,7 @@
| `turn_index` | integer | The open turn, or, if no turn is open, the index the next turn will get. |
| `audio_ms` | integer | Where the acknowledgement is in the audio. |

`auto` mode only, while your agent is speaking (see [`agent_speaking`](#agent_speaking)): the user acknowledged ("mm-hm", "yeah", "right") without taking the turn. Keep talking. One message per acknowledgement. It always comes before the named turn's `committed`, and it can come before that turn's `speech_start`. A backchannel counts for the turn that contains it; that turn commits with `user_turn: false` and `turn_kind: "backchannel"` unless the user goes on to take the turn. A turn that opened in `vad` or `manual` mode never counts an acknowledgement. When your agent is not speaking, an acknowledgement takes the turn (`user_turn_taken`).

Check failure on line 352 in api-reference/endpoint/websocket/asr-realtime.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

Vale.Spelling

Did you really mean 'backchannel'?

Check failure on line 352 in api-reference/endpoint/websocket/asr-realtime.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

Vale.Spelling

Did you really mean 'backchannel'?

### `committed`

Expand Down Expand Up @@ -453,6 +469,22 @@

Speaker tags still depend on `diarize` alone. A turn that holds only tags still gets its `committed`, without a language, and with a `text` that is empty with `diarize: false`, or holds only the turn's speaker tags with `diarize` on.

## Text format

With `transcribe-stream-2`, `results.text_format` sets the style for numbers, amounts, times and similar in the transcript:

| Value | Style | Example |
| --------------------- | ----------------------------- | ----------------------------------------------- |
| `"written"` (default) | Digits and symbols | "I paid $25 at 3:30 pm" |
| `"spoken"` | Words, the way they were said | "I paid twenty five dollars at three thirty pm" |

- Choose it in `config`, for the whole session.
- It applies to `draft`, `eager_end_of_turn` and `committed` alike.
- `session_started.config.results` shows the value in effect. `null` is the same as not sending the field.
- Any other value, such as another string (`"Written"` included), a number or a boolean, is `invalid_config`, which closes the connection with 4400. The message is `results.text_format must be "spoken" or "written"`.

Only `transcribe-stream-2` takes `text_format`. `transcribe-stream-1` refuses a `config` that sends it, whatever its value, `null` included, with `invalid_config` and close 4400; the error's `message` names the field. With `transcribe-stream-1`, `session_started.config.results` and `configured` have no `text_format`.

## Language

`draft`, `eager_end_of_turn` and `committed` carry the language of their own `text`. Use `language_code` (ISO 639-1) in your code; `language` is its English name, for display, with the same names as [`POST /v1/asr`](/api-reference/endpoint/openapi-v1/speech-to-text). The language is detected from that message's text alone, ignoring speaker tags, sound tags in `[` and `]`, and interjections such as "okay", "hmm" or "uh". With `tag_audio_events: false`, the label can also reflect text that is not shown: the rest of a draft after an unclosed opening bracket, the inside of a tag that holds another tag, or a tag in full-width or lenticular brackets. It is one of:
Expand Down Expand Up @@ -543,7 +575,7 @@

## Related

- [Realtime Speech to Text](/features/speech-to-text/realtime): what the realtime model does and when to use it.
- [Realtime Speech to Text](/features/speech-to-text/realtime): what the realtime models do and when to use them.
- [Transcribe a live audio stream](/developer-guide/sdk-guide/cookbook/realtime-transcription): a complete client in Python and Node.js, and a browser microphone relay.
- [Build a realtime voice agent](/developer-guide/sdk-guide/cookbook/realtime-voice-agent): turn-taking, barge-in and backchannels.

Check failure on line 580 in api-reference/endpoint/websocket/asr-realtime.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

Vale.Spelling

Did you really mean 'backchannels'?

Check failure on line 580 in api-reference/endpoint/websocket/asr-realtime.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

Vale.Spelling

Did you really mean 'backchannels'?
- [Speech to Text](/api-reference/endpoint/openapi-v1/speech-to-text): transcribe a complete audio file with `POST /v1/asr`.
Loading
Loading