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_MODELReplace 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_KEYConnect with wscat
Install wscat:
bash
npm install -g wscatConnect:
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
| Event | Direction | Description |
|---|---|---|
session.update | Client → Server | Update session configuration |
conversation.item.create | Client → Server | Add a user message |
input_audio_buffer.append | Client → Server | Append Base64-encoded audio |
response.create | Client → Server | Request a model response |
response.text.delta | Server → Client | Incremental text output |
response.audio.delta | Server → Client | Incremental audio output |
response.done | Server → Client | Response completed |
error | Server → Client | Error event |