Skip to main content

WSS

wss://api.modellix.ai/api/v1/live/google/gemini-3.1-flash-live-preview

Quick Start

Install websockets>=14 and set the MODELLIX_API_KEY environment variable. This Python example sends a text question, prints the transcript, and saves the spoken reply to reply.wav.

Session Setup

Send setup as the first JSON message. The URL selects the model, so you can omit setup.model.
string[]
Set to ["AUDIO"] for a spoken reply.
string
default:"MINIMAL"
Choose MINIMAL, LOW, MEDIUM, or HIGH. The default favors low latency. Higher levels let the model spend more time reasoning before it answers.
object
default:"off"
Set to {} to receive a transcript of your audio input.
object
default:"off"
Set to {} to receive the spoken reply as text alongside the audio.
object
Set to {} to request resumption handles. To resume a session, connect to the same model from the same Modellix team and set handle to the latest saved value. An unrecognized handle closes the connection with code 1008. Reconnect without a handle to start a new session.
object[]
Declare tools your application runs with functionDeclarations. Omit Google Search. Requesting Google Search closes the connection with code 1008.

Send Input

Wait for setupComplete before sending any of these messages.
string
Send a text prompt in a realtimeInput message.
object
Send base64-encoded, 16-bit little-endian mono PCM in data. For 16 kHz input, set mimeType to audio/pcm;rate=16000.
object
Send base64-encoded JPEG or PNG frames in data with the matching mimeType. Send at most one frame per second.
object[]
Set name to the function name and response to an object containing its result. Copy the matching call’s id when provided.

Read the Reply

A server message can contain audio, transcription, and a turn marker together. Read the content before handling the turn marker.
object
The session is ready for input.
object
Decode each audio part’s base64 data and play the chunks in arrival order as mono 24 kHz, 16-bit little-endian PCM.
string
Transcribed microphone input when input transcription is enabled.
string
Transcribed model speech when output transcription is enabled.
boolean
Marks the end of this turn. Keep the socket open for another turn.
object[]
The tools for your application to run. Each call identifies the function by name and may include an id and args.
string
When sessionResumptionUpdate.resumable is true, save the latest non-empty handle for reconnection.
object
Token usage for the response, including modality breakdowns when provided.

Billing

Modellix calculates each turn’s charges from the input and output tokens the model reports. It bills thinking tokens at the output text rate. For shared billing rules, connection limits, and close codes, see the Live Overview. For more details on the upstream model and message format, see the Google AI Studio model reference and Gemini Live WebSocket reference.