?token=....
Flow
Generate a Token
Generate the token from trusted server code:expires_at and
create a fresh token for every new WebSocket connection. A token is
consumed when it is verified, so do not reuse it for reconnects.
Server Example
Browser TTS Example
Browser STT Notes
For microphone streaming:- Use
AudioWorkletorMediaStreamTrackProcessorto capture audio. - Convert audio to 16-bit mono PCM.
- Set
input_formatto the actual sample rate you send, for examplepcm_16000,pcm_24000, orpcm_48000. - Send small chunks, around 80-100 ms, for lower latency.
Security Checklist
- Keep
GRADIUM_API_KEYonly on your server. - Authenticate the user before issuing a token.
- Issue one token per WebSocket connection.
- Do not log tokens in analytics or browser console output.
- If reconnecting, ask your server for a fresh token before opening the next socket.
Next steps
WebSocket Lifecycle
Setup, ready, input, flush, end, multiplexing, and errors.
Browser microphone to STT
Capture microphone audio and stream it to Gradium.