Voice

Realtime

Realtime voice over WebSocket, OpenAI Realtime API shape. Speech in, spoken answer out, one session.

Last reviewed 2026-08-25

Connect

wss://api.mserve.ai/openai/v1/realtime?model=qwen3.8-27b

Auth is one of: the Authorization: Bearer header, the browser subprotocol openai-insecure-api-key.<key>, or an ephemeral client secret from POST /openai/v1/realtime/client_secrets. An invalid client event returns an error event and the session stays open.

from openai import OpenAI

client = OpenAI(base_url="https://api.mserve.ai/openai/v1", api_key="ms_live_your_key")

with client.realtime.connect(model="qwen3.8-27b") as conn:
    conn.session.update(session={"type": "realtime", "instructions": "Answer in one sentence.", "output_modalities": ["audio"]})
    conn.input_audio_buffer.append(audio=pcm16_base64_chunk)
    for event in conn:
        if event.type == "response.output_audio.delta":
            play(event.delta)
        elif event.type == "response.done":
            break

Session

FieldValue
audio.input.formataudio/pcm at 24 kHz, 16-bit mono. pcmu and pcma are rejected.
audio.output.formataudio/pcm at 24 kHz.
audio.input.turn_detectionserver_vad (default) or null for manual turns. threshold, prefix_padding_ms, silence_duration_ms accepted.
reasoning.effortminimal by default, which turns the model's thinking off for latency. low, medium, high enable it.
voiceAny voice id, ElevenLabs premade id, or OpenAI name.
instructionsSystem prompt for the model.

Ephemeral keys for browsers

Mint a short-lived client secret on your server and hand it to the browser. It works only for the Realtime WebSocket.

curl https://api.mserve.ai/openai/v1/realtime/client_secrets \
  -H "Authorization: Bearer $MSERVE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"session": {"type": "realtime", "model": "qwen3.8-27b"}}'
Response
{ "value": "ek_…", "expires_at": 1787700000, "session": { "type": "realtime", "model": "qwen3.8-27b", "id": "sess_…", "object": "realtime.session" } }

Billing

A turn is billed as audio minutes in, tokens for the answer, and characters spoken, at the prices for each. Audio starts as soon as the first sentence of the answer is ready.

On this page

Share feedback