## Basic model info - Model name: qwen/qwen qwen-audio-3.1-live - Model description: Qwen-Audio-3.1-Live supports real-time, two-way voice conversations in Client mode. - Endpoint name: ## Model schema The model schema is defined in the OpenAPI schema: [OpenAPI Schema](https://oapi.sunra.ai/main/qwen/qwen-audio-3.1-live/fe489a2ed3414851b0297bac69a9e3b5f2cb0c2d.json) ### Model input schema The model input schema is: ```json ``` ### Model output schema The model output schema is: ```json ``` ## Example inputs and outputs Use the following example inputs and outputs to understand the model. ### Input example ```json { } ``` ### Output example ```json { } ``` ## Model code examples ### JavaScript ```javascript import { sunra } from "@sunra/client"; const result = await sunra.subscribe("qwen/qwen-audio-3.1-live/", { input: {}, logs: true, onQueueUpdate: (update) => { console.log(`Status Update: ${update.status}, Request ID: ${update.request_id}`); }, }); console.log(result.data); console.log(result.requestId); ``` ### Python ```python import sunra_client result = sunra_client.subscribe( "qwen/qwen-audio-3.1-live/", arguments={ }, with_logs=True, on_enqueue=print, on_queue_update=print, ) print(result) ``` ### Java ```java import ai.sunra.client.*; import java.util.Map; import com.google.gson.JsonObject; var client = SunraClient.withEnvCredentials(); var response = client.subscribe( "qwen/qwen-audio-3.1-live/", SubscribeOptions.builder() .input(Map.of( )) .resultType(JsonObject.class) .onQueueUpdate(update -> System.out.printf( "\nStatus Update: %s, Request ID: %s%n", update.getStatus(), update.getRequestId() )) .logs(true) .build() ); System.out.println("Completed!"); System.out.println(response.getData()); ``` ### Kotlin ```kotlin import ai.sunra.client.kt.* import com.google.gson.JsonObject val client = createSunraClient() val response = client.subscribe( endpointId = "qwen/qwen-audio-3.1-live/", input = mapOf( ), options = ai.sunra.client.kt.SubscribeOptions(logs = true), onUpdate = { update -> println("\nStatus Update: ${update.status}, Request ID: ${update.requestId}") } ) println("Completed!") println(response.data) ``` ### Curl ```bash curl --request POST \ --url https://api.sunra.ai/v1/queue/qwen/qwen-audio-3.1-live/ \ --header "Authorization: Key $SUNRA_KEY" \ --header "Content-Type: application/json" \ --data '{}' ``` ## Model readme > Connect from a server-side WebSocket client using an ordinary Sunra API key. This endpoint supports full-duplex voice in Client mode. Your application handles delegated tasks. The gateway selects the voice model for the session. > > `wss://api-llm.sunra.ai/v1/realtime?model=qwen-audio-3.1-live` > > **Price and limits.** USD 0.000710 per connected second, including silence and idle time. The minimum charge is 3 seconds (USD 0.002130). The public gateway requires an available balance above USD 0.10. Each connection reserves up to 300 seconds (USD 0.213), limited by available credit. Unused credit is released at settlement. Five concurrent sessions are shared across the provider workspace. A handshake can return HTTP 402 for insufficient credit or 429 when all slots are occupied. > > **Try a short voice request.** Use Python 3.11 or later. Install `websockets` with `python -m pip install 'websockets>=15,<17'`. Set `SUNRA_API_KEY` in your server environment. Save a short spoken question as `question.pcm` (mono, 16 kHz, signed 16-bit little-endian PCM). For example, convert a recording with `ffmpeg -i question.wav -ar 16000 -ac 1 -f s16le question.pcm`. > > Save this as `live.py` and run `python live.py`. It streams the question, writes a new `reply.wav` and prints the billed seconds. Run from a directory where `reply.wav` does not exist. The `x-sunra-prediction-id` handshake header identifies the wallet transaction. > > ```python > import asyncio > import base64 > import json > import os > import wave > from pathlib import Path > from uuid import UUID > from websockets.asyncio.client import connect > > URL = "wss://api-llm.sunra.ai/v1/realtime?model=qwen-audio-3.1-live" > > > async def main(): > audio = Path("question.pcm").read_bytes() > if not audio or len(audio) % 2: > raise ValueError("Expected nonempty PCM16 audio") > if Path("reply.wav").exists(): > raise FileExistsError("Move reply.wav or use a new directory") > headers = {"Authorization": "Bearer " + os.environ["SUNRA_API_KEY"]} > async with connect(URL, additional_headers=headers) as ws: > ref = ws.response.headers["x-sunra-prediction-id"] > print("Session", f"rt_{UUID(ref.removeprefix('rt_'))}") > await ws.send(json.dumps({"type": "session.update", "session": { > "modalities": ["text", "audio"], "delegation": {"type": "client"}, > "turn_detection": {"type": "duplex"} > }})) > async with asyncio.timeout(10): > while json.loads(await ws.recv())["type"] != "session.updated": > pass > > async def speak(): > # Send silence after the question to allow time for a short reply. > frames = audio + bytes(32000 * 6) > for offset in range(0, len(frames), 640): > chunk = base64.b64encode(frames[offset:offset + 640]).decode() > await ws.send(json.dumps({"type": "session.input_audio.append", "audio": chunk})) > await asyncio.sleep(0.02) > await ws.send(json.dumps({"type": "session.close"})) > > async def listen(): > chunks = [] > async for message in ws: > event = json.loads(message) > if event["type"] == "session.output_audio.delta": > chunks.append(base64.b64decode(event["delta"])) > elif event["type"] == "session.closed": > print("Billed seconds", float(event["usage"]["seconds"])) > if not chunks: > raise RuntimeError("No audio reply received") > output = open("reply.wav", "xb") > try: > with output, wave.open(output, "wb") as reply: > reply.setparams((1, 2, 24000, 0, "NONE", "not compressed")) > reply.writeframes(b"".join(chunks)) > except BaseException: > Path("reply.wav").unlink(missing_ok=True) > raise > return > raise RuntimeError("Connection closed before the final usage event") > > async with asyncio.timeout(len(audio) / 32000 + 25): > await asyncio.gather(speak(), listen()) > > > asyncio.run(main()) > ```