Skip to content
Introducing STTv6See what's new
API referenceSpeech-to-Text

WebSocket API

Learn how to use and integrate Soniox Speech-to-Text WebSocket API.

Overview

The Soniox WebSocket API provides real-time transcription and translation of live audio with ultra-low latency. It supports advanced features like speaker diarization, context customization, and manual finalization — all over a persistent WebSocket connection. Ideal for live scenarios such as meetings, broadcasts, multilingual communication, and voice interfaces.


WebSocket endpoint

Connect to the API using:

wss://stt-rt.soniox.com/transcribe-websocket

Authentication

Send your API key with the connection, in the Authorization header or the protocols list. See WebSocket authentication.

The key sent with the connection is the connection's key for its whole life.

The api_key field of the start request is deprecated. From 15 January 2027 a connection that sends its key only there is refused. See Migrate WebSocket authentication.


Configuration

Before streaming audio, configure the transcription session by sending a JSON message such as:

{
  "model": "stt-rt-v6",
  "audio_format": "auto",
  "language_hints": ["en", "es"],
  "context": {
    "general": [
      { "key": "domain", "value": "Healthcare" },
      { "key": "topic", "value": "Diabetes management consultation" },
      { "key": "doctor", "value": "Dr. Martha Smith" },
      { "key": "patient", "value": "Mr. David Miller" },
      { "key": "organization", "value": "St John's Hospital" }
    ],
    "text": "Mr. David Miller visited his healthcare provider last month for a routine follow-up related to diabetes care. The clinician reviewed his recent test results, noted improved glucose levels, and adjusted his medication schedule accordingly. They also discussed meal planning strategies and scheduled the next check-up for early spring.",
    "terms": [
      "Celebrex",
      "Zyrtec",
      "Xanax",
      "Prilosec",
      "Amoxicillin Clavulanate Potassium"
    ],
    "translation_terms": [
      { "source": "Mr. Smith", "target": "Sr. Smith" },
      { "source": "St John's", "target": "St John's" },
      { "source": "stroke", "target": "ictus" }
    ]
  },
  "enable_speaker_diarization": true,
  "enable_language_identification": true,
  "translation": {
    "type": "two_way",
    "language_a": "en",
    "language_b": "es"
  }
}

Parameters

api_keystring

Deprecated. Send the API key with the connection instead; see Authentication and Migrate WebSocket authentication.

modelRequiredstring

Real-time model to use. See models.

Example: "stt-rt-v6"
audio_formatRequiredstring

Audio format of the stream. See audio formats.

num_channelsnumber

Required for raw audio formats. See audio formats.

sample_ratenumber

Required for raw audio formats. See audio formats.

language_hintsarray<string>

See language hints.

language_hints_strictbool

See language restrictions.

contextobject

See context.

enable_speaker_diarizationboolean

See speaker diarization.

enable_language_identificationboolean

See language identification.

enable_endpoint_detectionboolean

See endpoint detection.

max_endpoint_delay_msnumber

Must be between 500 and 3000. Default value is 2000. See endpoint detection.

endpoint_sensitivitynumber

Must be between -1.0 and 1.0. Default value is 0.0. Supported by stt-rt-v5 and stt-rt-v6. See endpoint detection.

endpoint_latency_adjustment_levelnumber

Must be between 0 and 3. Default value is 0. Supported by stt-rt-v5 and stt-rt-v6. See endpoint detection.

enable_agent_text_inputboolean

Lets you send your voice agent's text with agent_text messages. Supported only by stt-rt-v6. See agent text input.

client_reference_idstring

Optional client-defined identifier recorded with this request in usage logs. Does not need to be unique. Ignored if the request authenticates with a temporary API key.

idle_timeout_msnumber

How long the stream stays open without a client message, in milliseconds. A whole number between 3000 and 20000. Default value is 20000. See idle timeout. For a stream with reconnect, it is also the reconnect window.

enable_reconnectboolean

Allows the stream to continue on a new connection after the old one drops. The server then sends a reconnect message before any transcription response, and every transcription response carries seq. Without that message the stream runs without reconnect. See stream reconnect.

translationobject

See real-time translation.

One-way translation

typeRequiredstring

Must be set to one_way.

target_languageRequiredstring

Language to translate the transcript into.

Two-way translation

typeRequiredstring

Must be set to two_way.

language_aRequiredstring

First language for two-way translation.

language_bRequiredstring

Second language for two-way translation.


Connection timeouts

There is no deadline for the start request, but send a keepalive control message or a ping at least every 40 seconds until it, or the connection is closed as idle with WebSocket status 1001. The connection counts against your connection limit the whole time.

After the start request, the keepalive rules apply as usual.

Open connections, including idle ones, count against a connection limit, a multiple of your concurrent requests limit; see Limits & quotas. Full details in WebSocket authentication.

Still sending api_key in the start request? Different timeouts apply; see Migrate WebSocket authentication.


Audio streaming

After configuration, start streaming audio:

  • Send audio as binary WebSocket frames.
  • Each stream supports up to 300 minutes of audio.
  • One message can carry at most 2,097,144 bytes of audio. A larger message ends the stream with a 400 error.

If you set enable_agent_text_input, you can also send your voice agent's text as text frames, in small pieces as it's played. Send end_of_segment: true at the end of each agent turn:

{"type": "agent_text", "text": "Can I have "}
{"type": "agent_text", "text": "your surname, "}
{"type": "agent_text", "text": "please?", "end_of_segment": true}

See agent text input.


Ping

Send a ping at any time to check that the connection is alive:

{"type": "ping", "id": 7}

The server answers at once, on the same connection:

{"type": "pong", "id": 7}
idOptionalnumber

Any whole number, returned in the pong. Without it, the pong has no id. Any other value, for example a string, makes the ping a malformed control request: the server answers with a 400 error and the stream ends. Before the start request such a ping also gets a 400 error, and the connection is closed. After the empty frame that ends the stream, such a ping is ignored.

  • A ping counts as activity, like a keepalive: it restarts the idle timeout.
  • Pings are answered until the empty frame that ends the stream. After that frame, they are answered only on a stream that sent a reconnect message, or if you pinged before the frame. To watch the connection until the finished response, start pinging early. Before the start request they are answered only if the API key was sent with the connection; otherwise the first message must be the start request.
  • A ping sent after the start request is answered once the stream has started, so a slow start delays its pong.
  • A pong is not a transcription response: it has no tokens and no seq.

See Ping and keepalive.


Reconnect

A stream started with enable_reconnect can be continued on a new connection after the old one drops. See stream reconnect for the full flow, its timing and its limits.

Reconnect message

Sent on such a stream before any transcription response:

{
  "type": "reconnect",
  "reconnect_token": "q9ZkT3vLm8XwR2pN...",
  "reconnect_url": "wss://stt-rt.soniox.com/transcribe-websocket?reconnect=true&r=Qx7mT2kV9pLwZ4nB"
}
reconnect_tokenstring

Token for the first reconnect. Send it back unchanged.

reconnect_urlstring

The URL to reconnect to. Use it exactly as given.

If a transcription response arrives with no reconnect message before it, the stream runs without reconnect, and its responses carry no seq.

Reconnect request

After the connection is lost, connect to reconnect_url with the stream's API key sent with the connection, and send this as the first message, right after connecting:

{
  "type": "reconnect",
  "reconnect_token": "q9ZkT3vLm8XwR2pN...",
  "last_seq": 42
}
reconnect_tokenRequiredstring

The token from the latest reconnect or reconnected message.

last_seqRequirednumber

The seq of the last response received, or 0 if none was received.

A connection to reconnect_url can only reconnect: a start request or a ping as its first message is refused. If the reconnect message doesn't arrive soon after connecting, the server closes the connection with WebSocket status 1001.

Reconnected response

The server answers, then sends every response after last_seq again, unchanged, then live responses:

{
  "type": "reconnected",
  "reconnect_token": "h4JsW7cYb1KfE6uD...",
  "last_request": 118
}
reconnect_tokenstring

A fresh token, for the next reconnect.

last_requestnumber

How many client messages after the start request the server received: audio messages, finalize, keepalive, agent_text and the empty frame that ends the stream. Pings are not counted. Resend from message number last_request + 1.

A refused reconnect gets an error response with error_type reconnect_failed instead, and the reconnect connection is closed.

Replaced connection

The connection that a reconnect replaces gets an error response with error_type connection_replaced and is closed. The stream itself continues on the newer connection.


Ending the stream

To gracefully close a streaming session:

  • Send an empty text frame, an empty string. An empty binary frame is an empty audio chunk and does not end the stream.
  • The server will return one or more responses, including finished response, and then close the connection.
  • Keep the connection open and keep reading until the finished response arrives. Closing it earlier can lose the last responses.

Response

Soniox returns responses in JSON format. A typical successful response looks like:

{
  "tokens": [
    {
      "text": "Hello",
      "start_ms": 600,
      "end_ms": 760,
      "confidence": 0.97,
      "is_final": true,
      "speaker": "1"
    }
  ],
  "final_audio_proc_ms": 760,
  "total_audio_proc_ms": 880
}

Field descriptions

tokensarray<object>

List of processed tokens (words or subwords).

Each token may include:

textstring

Token text.

start_msOptionalnumber

Start timestamp of the token (in milliseconds). Not included if translation_status is translation.

end_msOptionalnumber

End timestamp of the token (in milliseconds). Not included if translation_status is translation.

confidencenumber

Confidence score (0.0–1.0).

is_finalboolean

Whether the token is finalized.

speakerOptionalstring

Speaker label (if diarization enabled).

translation_statusOptionalstring

See real-time translation.

languageOptionalstring

Language of the token.text.

source_languageOptionalstring

See real-time translation.

final_audio_proc_msnumber

Audio processed into final tokens.

total_audio_proc_msnumber

Audio processed into final + non-final tokens.

seqOptionalnumber

Number of this response within the stream, counting from 1 with no gaps. Present only on a stream that got a reconnect message, on every transcription response including the finished response. Error responses carry no seq. See stream reconnect.


Finished response

At the end of a stream, Soniox sends a final message to indicate the session is complete:

{
  "tokens": [],
  "final_audio_proc_ms": 1560,
  "total_audio_proc_ms": 1680,
  "finished": true
}

After this, the server closes the WebSocket connection.


Error response

If an error occurs, the server returns an error message and immediately closes the connection:

{
  "tokens": [],
  "error_code": 503,
  "error_type": "service_unavailable",
  "error_message": "Cannot continue request (code 11). Please restart the request. Refer to: https://soniox.com/url/cannot-continue-request (request ID 3d37a3bd-5078-47ee-a369-b204e3bbedda)",
  "more_info": "https://docs.soniox.com/api-reference/errors#service-unavailable",
  "request_id": "3d37a3bd-5078-47ee-a369-b204e3bbedda"
}
error_codenumber

Standard HTTP status code of the error.

error_typestring

Stable, machine-readable identifier of the error. Branch on this, not on error_message. See the Errors reference for the full catalog and recovery steps.

error_messagestring

Human-readable description of the error.

more_infostring

Link to the section on the Errors page describing this error_type.

request_idstring

Unique identifier of this request. Include it when contacting support@soniox.com; server logs are keyed on it.

For the full catalog of error_type values across all Soniox APIs, see the Errors reference.

Full list of possible error codes and messages:

The request is malformed or contains invalid parameters, a reconnect was refused, or the connection was replaced by a reconnect. error_type is one of invalid_request, model_not_available, reconnect_failed, or connection_replaced.

  • A reconnect must send the API key with the connection: the Authorization header "Bearer <api_key>", or soniox-api-key and the key in the WebSocket protocols list.
  • Agent text is too long. Maximum length is N characters.
  • Agent text requires enable_agent_text_input in the start request.
  • Audio data channels must be specified for PCM formats
  • Audio data sample rate must be specified for PCM formats
  • Audio decode error
  • Audio is too long.
  • Audio frame is not valid base64. Send audio as either a binary WebSocket frame, or a text frame containing standard base64-encoded bytes.
  • `client_reference_id` is N characters, which exceeds the maximum allowed length of 256.
  • Context is too long.
  • Context is too long: N tokens, the maximum is 8000 tokens.
  • Control request is malformed.
  • Control request type is invalid.
  • Field endpoint_latency_adjustment_level must be between 0 and N.
  • Field endpoint_sensitivity cannot be less than -1.
  • Field endpoint_sensitivity cannot be more than 1.
  • Field max_non_final_tokens_duration_ms cannot be less than N.
  • Field max_non_final_tokens_duration_ms cannot be more than N.
  • Field translation.exclude_source_languages is not supported by model X.
  • Field translation.source_languages cannot be empty.
  • Field translation.source_languages for model X should be empty or it can be one element list having string '*'.
  • Invalid audio data format: avi
  • Invalid language hint.
  • Invalid language in translation.exclude_source_languages: X.
  • Invalid language in translation.language_a.
  • Invalid language in translation.language_b.
  • Invalid language in translation.source_languages: X.
  • Invalid language in translation.target_language.
  • Language hints must be unique.
  • Languages in translation.exclude_source_languages must be unique.
  • Languages in translation.source_languages must be unique.
  • Message is too large. Send at most N bytes of audio in one message.
  • Missing audio format. Specify a valid audio format (e.g. s16le, f32le, wav, ogg, flac...) or "auto" for auto format detection.
  • Model does not support endpoint_latency_adjustment_level.
  • Model does not support endpoint_sensitivity.
  • Model does not support language_hints_strict.
  • Model does not support max_endpoint_delay_ms.
  • Model does not support one way translation.
  • Model does not support two way translation.
  • No audio received.
  • Parameter 'idle_timeout_ms' must be at least N.
  • Parameter 'idle_timeout_ms' must be at most N.
  • Parameter 'last_seq' is ahead of the stream. Start a new stream.
  • Parameter 'last_seq' is required; send 0 if no response was received.
  • Prompt too long for model
  • Received too much audio data in total.
  • Reconnect is not available on this server.
  • Reconnect to the stream is not possible. Start a new stream.
  • Specified model X does not support real-time transcription. If you wish to use real-time transcription, specify model Y.
  • Send the API key either in the Authorization header or in the WebSocket protocols list, not both.
  • Authorization header must be "Bearer <api_key>".
  • soniox-api-key must be sent in the WebSocket protocols list together with exactly one other entry, the API key.
  • The api_key in the start request does not match the API key sent with the connection. Send the same key or omit it.
  • Start request is malformed.
  • Start request must be a text message.
  • The API key does not match the stream's.
  • The first message on a reconnect must be a reconnect control request.
  • The reconnect parameters are for a reconnect only; connect to the reconnect URL as given.
  • The reconnect token is invalid or expired. Start a new stream.
  • The reconnect token is too long. Send the token exactly as received.
  • The reconnect token was already used. Reconnect with the newest token.
  • The reconnect token was used too many times. Start a new stream.
  • The requested model is not available. See https://docs.soniox.com/stt/models for the list of supported models.
  • The responses after 'last_seq' are no longer available. Start a new stream.
  • The stream has ended. Start a new stream.
  • The stream was reconnected to too many times. Start a new stream.
  • This connection was replaced by a newer one for the same stream. Use the newest connection; do not reconnect from this one.
  • translation.language_a and translation.language_b must be different (both are X).
  • translation.language_a must be present if translation.language_b is present.
  • translation.language_b must be present if translation.language_a is present.
  • Two way translation between translation.language_a=X and translation.language_b=Y is not supported.

Authentication is missing or incorrect. Ensure a valid API key is provided before retrying. error_type: unauthenticated.

  • Incorrect API key provided. You can get an API key at https://console.soniox.com
  • Invalid or expired temporary API key. Create a new temporary API key and retry. See https://docs.soniox.com/authentication/temporary-api-keys for details.
  • Missing API key. Provide API key as a header (i.e. Authorization: Bearer <SONIOX_API_KEY>). You can get an API key at https://console.soniox.com
  • Missing API key. Send it with the connection: the Authorization header "Bearer <api_key>", or soniox-api-key and the key in the WebSocket protocols list. (from 15 January 2027, for a connection that sends no key with the connection; see Migrate WebSocket authentication)
  • The temporary API key cannot be used for this action. Each temporary API key is scoped to a specific `usage_type`; create a new key with the correct usage type.

The organization's balance or monthly usage limit has been reached. Additional credits are required before making further requests. error_type is one of organization_balance_exhausted, organization_monthly_budget_exhausted, or project_monthly_budget_exhausted.

  • Organization balance exhausted. Please either add funds manually or enable autopay.
  • Organization monthly budget exhausted. Please increase it.
  • Project monthly budget exhausted. Please increase it.

The API key does not have the permission for real-time speech-to-text, or the temporary API key in use was created with a max_session_duration_seconds cap and that duration has elapsed for the current session. error_type is one of permission_denied or temp_api_key_session_expired.

  • The API key does not have permission for this product. Edit the key's permissions at https://console.soniox.com
  • Temporary API key session duration limit exceeded. Create a new temporary API key to start a new session.

No message was received within the idle timeout, or a backend call exceeded its deadline before completing. Retry the request. error_type: request_timeout.

  • Audio data decode timeout
  • Input too slow
  • No message received for N ms (idle_timeout_ms).
  • Request timeout.
  • Timed out while waiting for the first audio chunk

The connection reached the maximum allowed session duration and was closed. Open a new WebSocket connection to continue streaming. error_type: max_duration_reached.

  • This WebSocket connection has reached the maximum allowed duration and was closed. Please open a new WebSocket connection to continue transcribing.

A usage or rate limit has been exceeded. You may retry after a delay or request an increase in limits via the Soniox Console. error_type is one of limit_exceeded or max_concurrent_connections_reached.

  • Concurrent requests limit for real-time transcription has been exceeded for your organization.
  • Concurrent requests limit for real-time transcription has been exceeded for your project.
  • Requests per minute limit for real-time transcription has been exceeded for your organization.
  • Requests per minute limit for real-time transcription has been exceeded for your project.
  • Concurrent WebSocket connections limit for real-time transcription has been exceeded for your organization. Close connections you are not using, or start streams on the ones you hold: the limit is a multiple of your concurrent streams limit.
  • Concurrent WebSocket connections limit for real-time transcription has been exceeded for your project. Close connections you are not using, or start streams on the ones you hold: the limit is a multiple of your concurrent streams limit.

An unexpected server-side error occurred. The request may be retried. error_type: internal_error.

  • The server had an error processing your request. Sorry about that! You can retry your request, or contact us through our support email support@soniox.com if you keep seeing this error.

The service cannot accept the request right now (upstream overload, cache exhausted, shutdown). Retry with backoff. The numeric (code N) in the message identifies the sub-cause for support triage. error_type: service_unavailable.

  • Cannot continue request (code N). Please restart the request. Refer to: https://soniox.com/url/cannot-continue-request

On this page