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

ItemValue
MethodGET (WebSocket upgrade)
Full URLwss://api.modelgo.ai/api-ws/v1/realtime?model=<logical model>
Querymodel (required) — the platform logical model name
HeaderAuthorization: Bearer <mgk_ API Key> (required; x-api-key is accepted too)
HeaderX-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:

json
{"error":{"type":"invalid_request_error","code":"unauthorized","message":"unauthorized: api_key_not_found"}}
HTTPMeaning
400The model query parameter is missing
401The API key is missing or invalid
402Insufficient balance or budget
403Not allowed to call the model, the account is suspended, or the model is not offered on this endpoint
404Unknown model, or no route for it
503Temporarily unavailable; retry later

After the handshake succeeds (HTTP 101):

  • If the gateway cannot reach the upstream, it sends one error event, then closes with code 1011; nothing is charged.
  • error events 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 error event; 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:

FieldDescription
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}
instructionsSystem persona

Voice, input transcription, and other fields are in the official client events reference.

Common events

DirectionEventPurpose
Clientsession.updateUpdate the session configuration
Clientinput_audio_buffer.appendAppend Base64 audio to the input buffer (does not trigger a response)
Clientinput_audio_buffer.commitCommit the buffer in manual mode
Clientconversation.item.createCreate a conversation item (e.g. text input, function_call_output)
Clientresponse.create / response.cancelTrigger / cancel (interrupt) a response
Serverinput_audio_buffer.speech_startedVAD detected the user starting to speak (interruption trigger)
Serverresponse.audio.deltaBase64 output audio
Serverresponse.audio_transcript.delta / response.text.deltaText of the audio / text in text-only mode
Serverresponse.doneEnd of a response; response.usage carries per-modality token usage
ServererrorError event

Audio formats

DirectionFormatEvent / field
Uplink (input)16000 Hz, 16-bit little-endian, mono PCM, Base64audio of input_audio_buffer.append
Downlink (output)24000 Hz, 16-bit little-endian, mono PCM, Base64delta of response.audio.delta

Billing and limits

  • Usage from every response.done usage on 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.

Related