Skip to content

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_KEY

Example (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 eventsDescription
session.updateUpdate session config (voice, modalities, system prompt)
input_audio_buffer.appendAppend input audio chunk (base64)
response.createAsk the model to generate a reply
Common server eventsDescription
response.text.deltaIncremental text
response.audio.deltaIncremental audio (base64)
response.doneA 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.