connect(), automatic reconnection, and typed message events.
Connecting
Both WebSocket APIs require a handshake before audio can flow. After the connection opens, the client must send a configuration message and wait for the server to respond withCONFIG_ACCEPTED. Only then is it safe to start streaming audio. If configuration is rejected, the session cannot be used.
By default, the SDK handles this handshake for you. Pass configuration to connect() and the promise resolves only after CONFIG_ACCEPTED is received — or rejects (and closes the socket) if the configuration is refused.
- Stream
- Transcribe
Getting the socket before the handshake completes
By defaultconnect() waits for CONFIG_ACCEPTED before resolving. Set awaitConfiguration: false to get the socket returned immediately — before the WebSocket even opens. This lets you attach event handlers right away and guarantees you won’t miss any messages, including early config status events. You are then responsible for waiting for CONFIG_ACCEPTED before sending audio. If configuration is rejected, error events are emitted on the socket rather than the promise rejecting.
awaitConfiguration: false was the default behavior prior to v1.0.0. If you are migrating from an older version, set it explicitly to preserve the previous behavior.Connecting without configuration
If you want to manage the whole handshake flow manually and only use the SDK for types and reconnection, omitconfiguration from connect(). The socket opens asynchronously, so wait for it to reach OPEN and then call sendConfiguration() manually — you are responsible for waiting for CONFIG_ACCEPTED before sending audio.
Sending audio
Both APIs accept raw audio chunks viasendAudio():
Full example
- Stream
- Transcribe
JavaScript
Next steps (sending messages, lifecycle)
After the socket is OPEN and configuration has been accepted, you can use the SDK’s methods to send audio, flush, end, and subscribe to typed messages.- SDK method reference: See the socket methods and
connect()parameters in the JavaScript SDK reference. - Protocol behavior & message semantics: If you want to understand what each message means (and the underlying wire format), refer to the WebSocket API docs.
Resources
- Stream API reference — WebSocket protocol details and message schemas
- Transcribe API reference — Transcribe protocol and configuration options
- Proxy Guide — Route WebSocket connections through your own server
- Authentication Guide — All auth flows including scoped tokens for WebSocket
For support or questions, contact us