Skip to content

Realtime

The Realtime API uses a WebSocket connection for low-latency bidirectional communication, including realtime conversations, audio input and output, and transcription.

WebSocket URL

text
wss://api.nexusmodels.cn/v1/realtime?model=YOUR_REALTIME_MODEL

Replace YOUR_REALTIME_MODEL with an available realtime model name.

Authentication

Include the virtual API key during the WebSocket handshake:

http
Authorization: Bearer YOUR_NEXUSMODELS_API_KEY

Connect with wscat

Install wscat:

bash
npm install -g wscat

Connect:

bash
wscat \
  -c 'wss://api.nexusmodels.cn/v1/realtime?model=YOUR_REALTIME_MODEL' \
  -H 'Authorization: Bearer YOUR_NEXUSMODELS_API_KEY'

After connecting, send a session configuration event:

json
{
  "type": "session.update",
  "session": {
    "modalities": [
      "text",
      "audio"
    ],
    "instructions": "Answer in English.",
    "voice": "alloy"
  }
}

Send a text message:

json
{
  "type": "conversation.item.create",
  "item": {
    "type": "message",
    "role": "user",
    "content": [
      {
        "type": "input_text",
        "text": "Please introduce NexusModels."
      }
    ]
  }
}

Request a model response:

json
{
  "type": "response.create"
}

Common events

EventDirectionDescription
session.updateClient → ServerUpdate session configuration
conversation.item.createClient → ServerAdd a user message
input_audio_buffer.appendClient → ServerAppend Base64-encoded audio
response.createClient → ServerRequest a model response
response.text.deltaServer → ClientIncremental text output
response.audio.deltaServer → ClientIncremental audio output
response.doneServer → ClientResponse completed
errorServer → ClientError event