Skip to Content
ModelSell Docs
Audio & MoreElevenLabs Audio Integration

Eleven Realtime

Open an OpenAI-compatible WebSocket session with ElevenLabs speech-to-speech voice agents through ModelSell.

Eleven Realtime handles both sides of a voice conversation. Use eleven_realtime_v1_mini for lower latency and cost, or eleven_realtime_v1_max for more complex turns and tool use. Both use the OpenAI Realtime event format. For transcription-only sessions, use Speech to Text. Eleven Realtime models · OpenAI Realtime compatibility

Access and authentication

Your ModelSell API key and supplier group must allow the selected model. The upstream ElevenLabs channel key must have the ElevenAgents Write permission, identified as convai_write. ModelSell requests a model-scoped, short-lived ElevenLabs client secret on the server and uses it to open the upstream socket. Authenticate to the gateway with your ModelSell key. Create realtime client secret · ElevenLabs API key permissions

ModelSell WebSocket routeModel selectorAuthentication
GET /elevenlabs/v1/convai/realtimeQuery parameter model. Omission selects eleven_realtime_v1_mini.Authorization: Bearer $MODELSELL_API_KEY or xi-api-key: $MODELSELL_API_KEY
GET /v1/realtimeQuery parameter model. Supply the ModelSell model ID.Authorization: Bearer $MODELSELL_API_KEY

Set MODELSELL_WS_URL and MODELSELL_API_KEY as described in the ElevenLabs integration overview. A successful WebSocket upgrade is followed by session.created when the upstream session is ready. If an error arrives first, check the ModelSell key's group access, the channel's convai_write permission, and the upstream model and region settings. Regional availability

Request a spoken response

Run python -m pip install websocket-client. This example opens a session, sends a text turn, and saves the streamed audio as a mono 24 kHz PCM WAV. Use it from a trusted server or local development environment that can hold the ModelSell API key. ElevenLabs audio streaming format

import base64
import json
import os
import wave
from urllib.parse import urlencode

from websocket import create_connection

model = "eleven_realtime_v1_mini"
base = os.environ["MODELSELL_WS_URL"].rstrip("/")
query = urlencode({"model": model})
ws = create_connection(
    f"{base}/elevenlabs/v1/convai/realtime?{query}",
    header=[f"Authorization: Bearer {os.environ['MODELSELL_API_KEY']}"],
    subprotocols=["realtime"],
    timeout=45,
)

def send(event):
    ws.send(json.dumps(event))

def receive():
    event = json.loads(ws.recv())
    if event.get("type") == "error":
        raise RuntimeError(event.get("error", {}).get("code") or "Realtime request failed")
    return event

def await_event(event_type):
    while True:
        event = receive()
        if event.get("type") == event_type:
            return event

try:
    await_event("session.created")
    send({
        "type": "session.update",
        "session": {
            "type": "realtime",
            "instructions": "Answer in one short spoken sentence.",
            "output_modalities": ["audio"],
            "audio": {"output": {"voice": "brian", "format": {"type": "audio/pcm"}}},
        },
    })
    await_event("session.updated")
    send({
        "type": "conversation.item.create",
        "item": {
            "type": "message",
            "role": "user",
            "content": [{"type": "input_text", "text": "Say hello to our listeners."}],
        },
    })
    send({"type": "response.create"})

    with wave.open("reply.wav", "wb") as output:
        output.setparams((1, 2, 24000, 0, "NONE", "not compressed"))
        frames = 0
        while True:
            event = receive()
            kind = event.get("type")
            if kind in {"response.output_audio.delta", "response.audio.delta"}:
                audio = base64.b64decode(event["delta"])
                output.writeframesraw(audio)
                frames += len(audio) // 2
            elif kind == "response.done":
                if event["response"].get("status") != "completed" or frames == 0:
                    raise RuntimeError("No complete audio response")
                print(event["response"]["id"])
                break
finally:
    ws.close()

Streaming events and session options

Event or fieldUse
session.updateSet session instructions, available audio settings, voice, and supported turn detection. Continue after session.updated.
input_audio_buffer.appendSend microphone audio chunks encoded as Base64. The input encoding must match the negotiated format.
input_audio_buffer.commitSubmit buffered audio when using client-controlled turns. With server turn detection, follow the provider's turn events.
response.createRequest a response after supplying a turn when automatic response creation is disabled.
response.output_audio.deltaDecode the delta field and play or save bytes incrementally.
response.doneCheck the final response status and inspect the usage when present.

Reconnect to select a different model. Use client-executed function tools for tool calls. Keep provider-hosted tools, callbacks, stored prompt references, and saved conversation IDs in the ElevenAgents workspace. Eleven Realtime compatibility · Realtime session configuration

Usage

ModelSell meters the session from session.created and adds input, output, and cached token usage reported in completed response events. Close the connection after the final response.done to finish the session. Actual charges depend on the model and your ModelSell group. ModelSell prices · Eleven Realtime pricing model

On this page