How it works
Your app holds a single WebSocket session and exchanges JSON events with the model: That’s the whole loop. When you stream microphone audio instead of text, turn detection makes the last step automatic — the model replies on its own when you stop speaking, noresponse.create needed.
Before you begin
You need:- A Boson API key stored in
BOSON_API_KEY - Available credit — new accounts must claim their free trial credit before their first API call
- Python 3.10 or later with the
websocketsandsounddevicepackages - Speakers or headphones — the reply plays as audio
Connect and play a reply
Connect, configure the session, send a text message, and play the model’s spoken reply:response.output_audio.delta events (base64 24 kHz 16-bit mono PCM) alongside response.output_audio_transcript.delta text, ending with response.done. To talk instead of type, stream microphone audio with input_audio_buffer.append — with server_vad turn detection the model detects when you stop speaking and responds on its own, no response.create needed.
Building for the browser or mobile? Don’t ship your API key: mint a short-lived key with
POST /v1/realtime/client_secrets and connect with the bai-client-secret.<key> subprotocol (see Authentication).It didn’t work?
No sound, or an audio device error
No sound, or an audio device error
sounddevice plays through your system’s default output device. Check that a working output device is selected and unmuted. The transcript print (Assistant: …) confirms the model replied even if playback failed.Connection closes with code 3000
Connection closes with code 3000
Invalid API key (or an invalid/expired ephemeral key). Check
BOSON_API_KEY is set in the shell running the script and matches a key in your workspace. See Authentication.error event with type insufficient_quota, then close code 4429
error event with type insufficient_quota, then close code 4429
A billing refusal — your key is fine, but the account has no available balance. New accounts must claim their free trial credit first; otherwise add credits in workspace billing. See Common error types.
Go deeper
Connections & sessions
Session configuration, limits, and lifecycle.
Audio & voices
Audio formats, preset voices, and custom voices.
Turn detection & interruptions
server_vad, semantic_vad, and barge-in.Tool calling
Let the model call your functions mid-conversation.
LiveKit & Pipecat
Production voice-agent frameworks with Higgs Realtime built in.
Migrate from OpenAI
The protocol is OpenAI Realtime compatible — most integrations move with config changes.