Soniox
Docs
Core concepts

Connection keepalive

Learn how connection keepalive works.

Overview

In real-time transcription sessions, it's important to keep the WebSocket connection alive, even during periods when no audio is being streamed — such as during silence, pauses, or voice activity detection (VAD) on the client side.

To support this, Soniox provides a special control message:

{"type": "keepalive"}

Sending this message ensures that your WebSocket session remains active and avoids timing out when no audio is being sent.


When to use keepalive

Use the {"type": "keepalive"} message when:

  • You're using client-side VAD and only stream audio during speech
  • There's silence or inactivity between utterances
  • You want to pause streaming without losing session context

This ensures that:

  • The connection remains open
  • Session-level context (e.g., speaker labels, language tracking, prompt) is preserved

Keepalive requirements

  • You must send a {"type": "keepalive"} message at least once every 20 seconds during periods when you're not sending audio.
  • Failure to do so may result in the connection being closed due to inactivity.
  • You may send it more frequently (e.g., every 5–10 seconds) if desired.

Example

{"type": "keepalive"}

Send this during idle periods in your stream to avoid timeouts while maintaining context.


Best practices

  • Send a keepalive message at least every 20 seconds during silence
  • Use alongside {"type": "finalize"} if you're segmenting audio manually
  • Maintain your connection across short pauses to preserve context

On this page