Skip to main content
Use these patterns when running the standalone WebSocket STT endpoint in production.

Connection Recovery

Treat the WebSocket session as disposable. Reconnect on network failure, server close, idle timeout, and process restart. Set all query parameters on every reconnect. STT configuration cannot be changed mid-session.

Backoff

Use bounded exponential backoff with jitter. Add random jitter of 0-500 ms per attempt. Reset the attempt counter after a stable connection. Do not retry immediately on authentication or validation errors. Fix the API key, query parameters, engine, model, or format first.

Partials

Enable interim_results=true when the application needs live captions or low-latency UI updates. Store final transcript segments separately from the current partial. This prevents duplicate text when a final result arrives after one or more interim results.

Audio Buffering

Buffer audio at the producer boundary, not inside the WebSocket send loop. Avoid unbounded queues. A slow or disconnected socket should not grow memory usage indefinitely. For live audio, prefer dropping stale buffered audio over sending it late. Late audio increases transcript delay and can make captions appear out of sync.

Keepalive

For Deepgram sessions, send {"type": "KeepAlive"} during long silence periods. Keep sending audio as binary frames when audio is available. For other engines, use the WebSocket client’s ping/pong support when available and reconnect on missed heartbeats.

Monitoring

Track connection, latency, transcript, and buffer metrics. Log the selected transcription_engine, model, input_format, sample_rate, and interim_results value with each session. Redact API keys and user audio.

Shutdown

Use graceful shutdown for planned stops.
  1. Drain the audio queue.
  2. Send {"type": "CloseStream"}.
  3. Wait for final transcript messages.
  4. Close the WebSocket.
Set a shutdown timeout. If final messages do not arrive before the timeout, close the socket and mark the transcript as incomplete.