Skip to main content
Version: 1.12.1

Qwen Realtime

Qwen-Omni Realtime accepts audio over an OpenAI-style WebSocket event protocol. Applications connect to the AISIX Realtime endpoint with a stable model alias, while the gateway authenticates to Alibaba Cloud Model Studio and relays the session events.

This guide configures Qwen-Omni Realtime in the Singapore region and verifies a complete audio turn. For Chat Completions, Responses, and other Qwen APIs, see Qwen (Alibaba Cloud).

Prerequisites​

Before starting, prepare the following:

  • One AISIX setup:
    • For AISIX Enterprise or AISIX Cloud, an environment with an attached gateway and permission to manage provider keys, models, and caller API keys. The Admin API path also requires a write-scoped admin token and the environment ID.
    • For AISIX OSS, a running gateway that loads a complete format-v2 resources file.
  • A Model Studio API key and workspace ID from the same region. Create the key in the international Model Studio console or the mainland China Model Studio console.
  • Access to Qwen-Omni Realtime in the selected region. The Qwen-Omni Realtime documentation lists the supported regions and workspace endpoints.
  • A short speech recording in a mono, 16 kHz, 16-bit PCM WAV file named input.wav.
  • Python 3 and pip for session verification. The Admin API path also uses curl and jq.

Use the provider ID, workspace domain, and API key from one region:

RegionProvider IDRealtime API base
Singaporealibabahttps://YOUR_WORKSPACE_ID.ap-southeast-1.maas.aliyuncs.com/api-ws/v1
Beijingalibaba-cnhttps://YOUR_WORKSPACE_ID.cn-beijing.maas.aliyuncs.com/api-ws/v1

The examples below use Singapore. Keep the workspace domain and API key in the same region. Use the matching provider ID so usage and cost attribution stay with the correct regional catalog.

Configure Qwen Realtime​

Create a dedicated regional provider key, a direct model alias, and a caller API key that can use the alias.

  1. Open Provider keys, then select New provider key.
  2. Configure the provider key:
    • Display name: qwen-realtime-prod
    • Provider: Alibaba Cloud Model Studio
    • Upstream API key: your Model Studio credential
    • API base: https://YOUR_WORKSPACE_ID.ap-southeast-1.maas.aliyuncs.com/api-ws/v1
    • Allowed environments: the environment where the alias will run
Qwen Realtime provider key with Alibaba Cloud Model Studio and the regional API base

The selected environment can reference this provider key from its models:

Production selected as an allowed environment for the Qwen Realtime provider key

The API base is the regional /api-ws/v1 root and uses https://. Do not append /realtime; AISIX adds that path and changes the scheme to wss:// when it connects upstream.

  1. Select Create provider key.
  2. In the environment, open Models. Select New model, then Direct model.
  3. Configure the alias:
    • Display name: qwen-realtime-prod
    • Upstream model id: qwen3.8-omni-flash-realtime
    • Provider key: qwen-realtime-prod
Direct Qwen Realtime model with its display name and upstream model ID

Select the dedicated provider key for this model:

Qwen Realtime provider key selected for the direct model

Realtime requires a direct model. A model group, ensemble, or semantic model is rejected before the WebSocket upgrade.

  1. Select Create model.
  2. Open API keys, then select New API key.
  3. Enter qwen-realtime-caller as the display name. Keep Selected models, then open Allowed models.
Qwen Realtime model available in the open caller API key allowed-model picker
  1. Select qwen-realtime-prod, then select Create API key. Copy the plaintext credential from the one-time view before dismissing it.

Export the copied credential for the verification client:

export AISIX_API_KEY="YOUR_CALLER_API_KEY"

Verify a Realtime Session​

Extract the raw audio frames from input.wav:

export PCM_FILE="./input.pcm"

python3 - <<'PY'
import os
import wave
from pathlib import Path

with wave.open("input.wav", "rb") as source:
if (source.getnchannels(), source.getframerate(), source.getsampwidth(), source.getcomptype()) != (1, 16000, 2, "NONE"):
raise ValueError("Expected mono 16 kHz, 16-bit PCM WAV audio.")
Path(os.environ["PCM_FILE"]).write_bytes(source.readframes(source.getnframes()))
PY

Install the WebSocket client and export the AISIX gateway origin:

python3 -m pip install websocket-client

# AISIX_PROXY uses http or https and has no endpoint path.
export AISIX_PROXY="YOUR_AISIX_GATEWAY_URL"

Save the following client as verify_qwen_realtime.py:

verify_qwen_realtime.py
import base64
import json
import os
from pathlib import Path
from urllib.parse import urlencode, urlsplit, urlunsplit

import websocket


def receive_until(ws, expected):
while True:
event = json.loads(ws.recv())
if event["type"] == "error":
raise RuntimeError(event.get("error"))
if event["type"] == "response.text.delta":
print(event["delta"], end="", flush=True)
if event["type"] == expected:
return event


origin = urlsplit(os.environ["AISIX_PROXY"])
scheme = "wss" if origin.scheme == "https" else "ws"
url = urlunsplit((
scheme,
origin.netloc,
"/v1/realtime",
urlencode({"model": "qwen-realtime-prod"}),
"",
))
audio = Path(os.environ["PCM_FILE"]).read_bytes()
if not audio or len(audio) % 2:
raise ValueError("Provide non-empty 16-bit PCM audio.")

ws = websocket.create_connection(
url,
header=["Authorization: Bearer " + os.environ["AISIX_API_KEY"]],
timeout=30,
)

try:
receive_until(ws, "session.created")
ws.send(json.dumps({
"type": "session.update",
"session": {
"modalities": ["text"],
"turn_detection": None,
"audio": {"input": {"format": {
"type": "pcm",
"sample_rate": 16000,
"sample_format": "s16le",
"channels": 1,
}}},
},
}))
receive_until(ws, "session.updated")

for offset in range(0, len(audio), 3200):
ws.send(json.dumps({
"type": "input_audio_buffer.append",
"audio": base64.b64encode(audio[offset:offset + 3200]).decode("ascii"),
}))
ws.send(json.dumps({"type": "input_audio_buffer.commit"}))
receive_until(ws, "input_audio_buffer.committed")
ws.send(json.dumps({"type": "response.create"}))
done = receive_until(ws, "response.done")
status = done["response"]["status"]
if status != "completed":
raise RuntimeError(f"Response ended with status {status}: {done['response']}")
print("\nResponse status: completed")
finally:
ws.close()

Run the client:

python3 verify_qwen_realtime.py

A successful run receives session.created and session.updated, prints the text response, and finishes with a completed response.done event.

AISIX authenticates the caller, replaces the alias with the upstream model ID, and authenticates to Model Studio with the provider key.

Troubleshoot the Connection​

Use the symptom that matches the connection failure, then repeat Verify a Realtime Session after applying the correction.

The WebSocket Handshake Fails​

Check the AISIX caller key and model authorization. Authentication, model access, IP restrictions, and rate limits run before the gateway accepts the upgrade.

The Session Returns an Error Event​

If the connection opens and then returns an error event, check that the DashScope API key, workspace domain, and model belong to the same region.

For gateway error behavior, see Upstream Connection Failures and Upstream Refusals After the Upgrade.

TLS Inspection Blocks the Upstream​

The public Model Studio endpoint uses a publicly trusted certificate. If your deployment reaches it through TLS inspection or a private CA, configure the gateway's deployment-wide upstream trust. The provider key's tls block does not apply to Realtime.

The Forward Proxy Cannot Connect​

For a forward proxy, the connection honors the gateway's HTTPS_PROXY, ALL_PROXY, and NO_PROXY environment variables. The proxy must support HTTP CONNECT; SOCKS proxies are not supported. See Reach the Upstream Through a Proxy.

Remove the Example Resources​

Remove the test configuration when you no longer need it.

Delete the model before its provider key. The caller key can be removed at any point:

  1. Open API keys and delete qwen-realtime-caller.
  2. Open Models and delete qwen-realtime-prod.
  3. Open Provider keys and delete qwen-realtime-prod.