Realtime
The realtime endpoint uses WebSocket for low-latency, bidirectional voice / text interaction — ideal for live voice chat and simultaneous interpretation.
Connect
GET wss://ai.youqi.tech/v1/realtime?model=<model>Connect via WebSocket and pass authentication in the handshake header:
http
Authorization: Bearer sk-YOUR_API_KEYExample (Node.js)
javascript
import WebSocket from "ws";
const ws = new WebSocket(
"wss://ai.youqi.tech/v1/realtime?model=gpt-4o-realtime-preview",
{
headers: { Authorization: "Bearer sk-YOUR_API_KEY" },
},
);
ws.on("open", () => {
ws.send(
JSON.stringify({
type: "response.create",
response: { modalities: ["text", "audio"], instructions: "Hello" },
}),
);
});
ws.on("message", (data) => {
console.log(JSON.parse(data.toString()));
});Event model
The realtime endpoint is event-driven: the client sends events (e.g. session.update, input_audio_buffer.append, response.create) and the server pushes events (e.g. response.audio.delta, response.text.delta, response.done).
| Common client events | Description |
|---|---|
session.update | Update session config (voice, modalities, system prompt) |
input_audio_buffer.append | Append input audio chunk (base64) |
response.create | Ask the model to generate a reply |
| Common server events | Description |
|---|---|
response.text.delta | Incremental text |
response.audio.delta | Incremental audio (base64) |
response.done | A reply is complete |
WARNING
The realtime endpoint is a long-lived, event-driven connection that differs significantly from regular REST endpoints. Available models and the exact event set depend on the selected model.