Realtime API Reference: Connections, Events & Errors
This endpoint is a long-lived WebSocket connection. The gateway relays the Qwen-Omni-Realtime protocol verbatim in both directions, with no protocol translation. The full field definitions (including tool-calling and MCP events) follow Alibaba Cloud Model Studio's official client events and server events.
Request
| Item | Value |
|---|---|
| Method | GET (WebSocket upgrade) |
| Full URL | wss://api.modelgo.ai/api-ws/v1/realtime?model=<logical model> |
| Query | model (required) — the platform logical model name |
| Header | Authorization: Bearer <mgk_ API Key> (required; x-api-key is accepted too) |
| Header | X-Request-ID (recommended) — your troubleshooting handle for the session; only A-Z a-z 0-9 - _ . :, up to 128 characters. When missing the gateway generates one and does not return it in the handshake response |
Whether a model supports this endpoint follows the protocols shown in the model marketplace.
Handshake errors
Failures before the WebSocket upgrade are returned as HTTP status codes with a body like:
{"error":{"type":"invalid_request_error","code":"unauthorized","message":"unauthorized: api_key_not_found"}}| HTTP | Meaning |
|---|---|
| 400 | The model query parameter is missing |
| 401 | The API key is missing or invalid |
| 402 | Insufficient balance or budget |
| 403 | Not allowed to call the model, the account is suspended, or the model is not offered on this endpoint |
| 404 | Unknown model, or no route for it |
| 503 | Temporarily unavailable; retry later |
After the handshake succeeds (HTTP 101):
- If the gateway cannot reach the upstream, it sends one
errorevent, then closes with code1011; nothing is charged. errorevents from the upstream during the session are relayed as-is, and the connection does not necessarily close.- When a connection reaches the 30-minute limit, the gateway closes it without an extra
errorevent; usage so far is settled as normal.
Session configuration
After connecting, the server sends session.created; the client overrides it with session.update, and the server confirms with session.updated. Common fields:
| Field | Description |
|---|---|
modalities | ["text","audio"] or ["text"] |
turn_detection | {"type":"server_vad"} / {"type":"semantic_vad"}; set null to turn off server VAD and commit / trigger responses manually |
audio.input.format | {"type":"pcm","sample_rate":16000} |
audio.output.format | {"type":"pcm","sample_rate":24000} |
instructions | System persona |
Voice, input transcription, and other fields are in the official client events reference.
Common events
| Direction | Event | Purpose |
|---|---|---|
| Client | session.update | Update the session configuration |
| Client | input_audio_buffer.append | Append Base64 audio to the input buffer (does not trigger a response) |
| Client | input_audio_buffer.commit | Commit the buffer in manual mode |
| Client | conversation.item.create | Create a conversation item (e.g. text input, function_call_output) |
| Client | response.create / response.cancel | Trigger / cancel (interrupt) a response |
| Server | input_audio_buffer.speech_started | VAD detected the user starting to speak (interruption trigger) |
| Server | response.audio.delta | Base64 output audio |
| Server | response.audio_transcript.delta / response.text.delta | Text of the audio / text in text-only mode |
| Server | response.done | End of a response; response.usage carries per-modality token usage |
| Server | error | Error event |
Audio formats
| Direction | Format | Event / field |
|---|---|---|
| Uplink (input) | 16000 Hz, 16-bit little-endian, mono PCM, Base64 | audio of input_audio_buffer.append |
| Downlink (output) | 24000 Hz, 16-bit little-endian, mono PCM, Base64 | delta of response.audio.delta |
Billing and limits
- Usage from every
response.doneusageon the connection is totaled and settled after the connection closes; see the guide. - A connection lasts at most 30 minutes (enforced by the gateway); context length, rate limits, and other specs follow the upstream's official documentation.