Skip to main content
HTTP and WebSocket are two ways to move audio between your code and a model. They reach the same models; they differ in timing. HTTP sends a whole input and returns a whole output. A WebSocket keeps a connection open and streams both directions in real time. If you run a managed agent or use the LiveKit or Pipecat integration, the transport is handled for you. This page is for direct API calls.

How each one works

  • HTTP. One request, one response. You send the whole input, a full audio file to transcribe or the full text to synthesize, and get the whole result back, a JSON transcript or an audio file. Each request is independent and easy to retry.
  • WebSocket. A connection that stays open. You stream audio or text in chunks and receive results as they are ready, so the model can start returning output before the input ends and can handle an interruption mid-utterance. Open the connection, stream, then close it when the turn or session ends. Unlike HTTP, which closes after each response, a WebSocket stays open until you close it, so an open connection holds resources and counts against connection limits. An idle connection can also be dropped, so reconnect if that happens.
A WebSocket session streams both ways over one open connection. Text to speech takes text and streams audio back: Speech to text mirrors this: you stream audio up and receive transcripts back over the same open connection.

When to use which

  • Use HTTP when the whole input already exists and you can wait for the whole output: transcribing a recorded file, generating a fixed piece of speech such as a prompt, a voicemail, or a video voiceover, or any one-shot, server-to-server job.
  • Use WebSocket when the audio is live and latency matters: interactive voice agents, live captioning, or any turn-by-turn exchange where the caller can interrupt.
Reach for WebSocket when you are building an interactive voice experience, and HTTP when you are processing files or generating speech one-shot. Managed agents and the framework integrations already stream over WebSocket.
For large recordings that are not latency-sensitive, transcribe them asynchronously with the Batch API and the slng/speechmatics/batch model instead of holding a connection open.

How to call each

Text to speech over WebSocket

Keep the connection healthy

  • Close the socket when the turn or session ends. Leaving it open holds resources and counts against your connection limit.
  • If the connection drops, reconnect with an exponential backoff: 1s, 2s, 4s, and so on, up to 30s.
  • Handle both frame types: JSON text for control messages, binary for audio.
For the message format and every field, see the WebSocket API reference: text to speech and speech to text, and the unified TTS and STT.
The Unified API uses the same WebSocket protocol across every supported model.

Next steps