Streaming TTS and STT

Streaming STT

Connect directly to wss://api.x.ai/v1/stt, wait for transcript.created, send binary audio frames, then send finalize when needed and finish with audio.done.

For browser clients, mint a new one-use secret through same-origin POST /v1/realtime/client_secrets for every connection and reconnect, then pass it only as xai-client-secret.<token> in the WebSocket subprotocol list.

Treat transcript.partial with speech_final=true as final evidence. In the 2026-09-18 live probe it carried the completed text while transcript.done.text was empty, followed by transport close 1006.

Streaming TTS

Connect directly to wss://api.x.ai/v1/tts with a server-side bearer. Configure voice, required language, codec, sample rate, MP3 bit rate, latency optimization, speed, normalization, and timestamps in the query string.

Send text.delta and text.done. The typed client yields JSON audio.delta events with encoded audio and optional timestamps, followed by audio.done.

Browser ephemeral authentication has not been verified for TTS, so progrok documents bearer auth only for this socket.