### Initialize and start QwenPaw
Source: https://platform.qianwenai.com/docs/developer-guides/clients-and-developer-tools/qwenpaw
Run these commands in a new terminal after installation to initialize the application and start the console.
```bash
qwenpaw init --defaults
qwenpaw app
```
--------------------------------
### Quick Start Configuration
Source: https://platform.qianwenai.com/docs/developer-guides/clients-and-developer-tools/dify
Basic steps to install the TONGYI plugin, configure the API key, and perform an initial test in Dify.
```text
# 1. 安装插件
进入 Dify 插件市场 → Models → 搜索 "TONGYI" → 安装
# 2. 配置(Settings → Model Providers → TONGYI → Settings)
API Key: sk-ws-xxx
Use international endpoint: No
# 3. 测试(创建空白应用 → 聊天助手)
选择模型:qwen3.5-plus
输入消息:"写一个 Python hello world 程序"
```
--------------------------------
### Install QwenPaw via pip
Source: https://platform.qianwenai.com/docs/developer-guides/clients-and-developer-tools/qwenpaw
Install QwenPaw using pip for Python 3.10 to 3.13, then initialize and start the application.
```bash
pip install qwenpaw
qwenpaw init --defaults
qwenpaw app
```
--------------------------------
### OpenAI Client Streaming Setup
Source: https://platform.qianwenai.com/docs/api-reference/gui-plus/openai
Example of initializing an OpenAI client with a system prompt that defines the 'computer_use' tool for GUI interaction.
```APIDOC
## OpenAI Client Integration
### Description
This example demonstrates how to set up an OpenAI client to perform GUI automation tasks. It uses a system prompt to define the `computer_use` tool, which allows the model to interact with a desktop environment via mouse and keyboard actions.
### Usage
Initialize the `OpenAI` client and provide a message history containing the system prompt and user request with image context.
### Code Example
```python
import os
from openai import OpenAI
# Define system prompt with tool definitions
system_prompt = "..."
# Initialize client
client = OpenAI()
# Prepare messages
messages = [
{"role": "system", "content": system_prompt},
{"role": "user", "content": [
{"type": "image_url", "image_url": {"url": "..."}},
{"type": "text", "text": "帮我打开浏览器"}
]}
]
```
```
--------------------------------
### DashScope Java GUI Interaction Setup
Source: https://platform.qianwenai.com/docs/developer-guides/text-generation/gui-interaction
This example demonstrates how to initialize a multimodal conversation with a system prompt that defines GUI interaction tools, including mouse movements, clicks, and keyboard input.
```java
import java.util.Arrays;
import java.util.Collections;
import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversation;
import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversationParam;
import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversationResult;
import com.alibaba.dashscope.common.MultiModalMessage;
import com.alibaba.dashscope.common.Role;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.exception.UploadFileException;
public class Main {
public static void simpleMultiModalConversationCall()
throws ApiException, NoApiKeyException, UploadFileException {
String systemPrompt = "# Tools\n\n" +
"You may call one or more functions to assist with the user query.\n\n" +
"You are provided with function signatures within XML tags:\n" +
"\n" +
"{\"type\": \"function\", \"function\": {\"name\": \"computer_use\", \"description\": \"Use a mouse and keyboard to interact with a computer, and take screenshots.\\n* This is an interface to a desktop GUI. You do not have access to a terminal or applications menu. You must click on desktop icons to start applications.\\n* Some applications may take time to start or process actions, so you may need to wait and take successive screenshots to see the results of your actions. E.g. if you click on Firefox and a window doesn't open, try wait and taking another screenshot.\\n* The screen's resolution is 1000x1000.\\n* Make sure to click any buttons, links, icons, etc with the cursor tip in the center of the element. Don't click boxes on their edges unless asked.\", \"parameters\": {\"properties\": {\"action\": {\"description\": \"The action to perform. The available actions are:\\n* `key`: Performs key down presses on the arguments passed in order, then performs key releases in reverse order.\\n* `type`: Type a string of text on the keyboard.\\n* `mouse_move`: Move the cursor to a specified (x, y) pixel coordinate on the screen.\\n* `left_click`: Click the left mouse button at a specified (x, y) pixel coordinate on the screen.\\n* `left_click_drag`: Click and drag the cursor to a specified (x, y) pixel coordinate on the screen.\\n* `right_click`: Click the right mouse button at a specified (x, y) pixel coordinate on the screen.\\n* `middle_click`: Click the middle mouse button at a specified (x, y) pixel coordinate on the screen.\\n* `double_click`: Double-click the left mouse button at a specified (x, y) pixel coordinate on the screen.\\n* `triple_click`: Triple-click the left mouse button at a specified (x, y) pixel coordinate on the screen (simulated as double-click since it's the closest action).\\n* `scroll`: Performs a scroll of the mouse scroll wheel.\\n* `hscroll`: Performs a horizontal scroll (mapped to regular scroll).\\n* `wait`: Wait specified seconds for the change to happen.\\n* `terminate`: Terminate the current task and report its completion status.\\n* `answer`: Answer a question.\\n* `interact`: Resolve the blocking window by interacting with the user.\", \"enum\": [\"key\", \"type\", \"mouse_move\", \"left_click\", \"left_click_drag\", \"right_click\", \"middle_click\", \"double_click\", \"triple_click\", \"scroll\", \"hscroll\", \"wait\", \"terminate\", \"answer\", \"interact\"], \"type\": \"string\"}, \"keys\": {\"description\": \"Required only by `action=key`.\", \"type\": \"array\"}, \"text\": {\"description\": \"Required only by `action=type`, `action=answer` and `action=interact`.\", \"type\": \"string\"}, \"coordinate\": {\"description\": \"(x, y): The x (pixels from the left edge) and y (pixels from the top edge) coordinates to move the mouse to. Required only by `action=mouse_move` and `action=left_click_drag`.\", \"type\": \"array\"}, \"pixels\": {\"description\": \"The amount of scrolling to perform. Positive values scroll up, negative values scroll down. Required only by `action=scroll` and `action=hscroll`.\", \"type\": \"number\"}, \"time\": {\"description\": \"The seconds to wait. Required only by `action=wait`.\", \"type\": \"number\"}, \"status\": {\"description\": \"The status of the task. Required only by `action=terminate`.\", \"type\": \"string\", \"enum\": [\"success\", \"failure\"]}}, \"required\": [\"action\"], \"type\": \"object\"}}}\n" +
"\n\n" +
"For each function call, return a json object with function name and arguments within XML tags:\n" +
"\n" +
"{\"name\": , \"arguments\": }\n" +
"\n\n" +
"# Response format\n\n" +
"Response format for every step:\n"
```
--------------------------------
### Recognize local audio files
Source: https://platform.qianwenai.com/docs/api-reference/speech-recognition/paraformer-realtime/python-sdk
This example demonstrates how to initialize the Recognition class with a callback, start the task, and stream audio frames from a local WAV file.
```python
import os
import time
from dashscope.audio.asr import *
# 若没有将API Key配置到环境变量中,需将下面这行代码注释放开,并将apiKey替换为自己的API Key
# import dashscope
# dashscope.api_key = "apiKey"
from datetime import datetime
def get_timestamp():
now = datetime.now()
formatted_timestamp = now.strftime("[%Y-%m-%d %H:%M:%S.%f]")
return formatted_timestamp
class Callback(RecognitionCallback):
def on_complete(self) -> None:
print(get_timestamp() + ' Recognition completed')
def on_error(self, result: RecognitionResult) -> None:
print('Recognition task_id: ', result.request_id)
print('Recognition error: ', result.message)
exit(0)
def on_event(self, result: RecognitionResult) -> None:
sentence = result.get_sentence()
if 'text' in sentence:
print(get_timestamp() + ' RecognitionCallback text: ', sentence['text'])
if RecognitionResult.is_sentence_end(sentence):
print(get_timestamp() +
'RecognitionCallback sentence end, request_id:%s, usage:%s'
% (result.get_request_id(), result.get_usage(sentence)))
callback = Callback()
recognition = Recognition(model='paraformer-realtime-v2',
format='wav',
sample_rate=16000,
# "language_hints"只支持paraformer-realtime-v2模型
language_hints=['zh', 'en'],
callback=callback)
recognition.start()
try:
audio_data: bytes = None
f = open("asr_example.wav", 'rb')
if os.path.getsize("asr_example.wav"):
while True:
audio_data = f.read(3200)
if not audio_data:
break
else:
recognition.send_audio_frame(audio_data)
time.sleep(0.1)
else:
raise Exception('The supplied file was empty (zero bytes long)')
f.close()
except Exception as e:
raise e
recognition.stop()
print(
'[Metric] requestId: {}, first package delay ms: {}, last package delay ms: {}'
.format(
recognition.get_last_request_id(),
recognition.get_first_package_delay(),
recognition.get_last_package_delay(),
))
```
--------------------------------
### Start Dialog Recognition
Source: https://platform.qianwenai.com/docs/api-reference/speech-recognition/fun-asr-realtime/harmonyos-sdk
Starts the recognition process. The example shows the JSON structure for dialog_params.
```typescript
startDialog(vad_mode: Constants.VadMode, dialog_params: string): number
```
```json
{
"apikey": "st-****",
"input_context": [
{ "role": "user", "content": [{ "type": "input_text", "text": "示例上下文" }] }
]
}
```
--------------------------------
### Initialize Realtime Client
Source: https://platform.qianwenai.com/docs/developer-guides/speech/qwen-audio-realtime
Sets up the audio player and initializes the FunRealtimeClient with the required model and API credentials.
```python
async def main():
pya = pyaudio.PyAudio()
# 输出采样率 24kHz,匹配服务端音频格式
player = B64PCMPlayer(pya, sample_rate=24000)
client = FunRealtimeClient(
base_url="wss://dashscope.aliyuncs.com/api-ws/v1/realtime",
api_key=os.environ['DASHSCOPE_API_KEY'],
model="qwen-audio-3.0-realtime-plus",
voice="longanqian",
```
--------------------------------
### Prompt Parameter Example
Source: https://platform.qianwenai.com/docs/api-reference/video-generation/vidu-image-to-video/create-task
Example of the optional text prompt used to guide the video generation process.
```yaml
example: 镜头从海龟下方缓缓上移,海龟悠然游动,腹部细节清晰可见。
```
--------------------------------
### Voice Enrollment and Audio Player Setup (Java)
Source: https://platform.qianwenai.com/docs/api-reference/real-time-multimodal/voice-cloning
Demonstrates creating a custom voice by sending an audio file to the Qwen API and setting up a basic audio player structure.
```java
import com.alibaba.dashscope.audio.omni.*;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import javax.sound.sampled.*;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.ByteBuffer;
import java.nio.file.*;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Base64;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.atomic.AtomicBoolean;
public class Main {
// ===== 常量定义 =====
// 声音复刻、实时对话要使用相同的模型
private static final String TARGET_MODEL = "qwen3.5-omni-plus-realtime";
private static final String PREFERRED_NAME = "guanyu";
// 用于声音复刻的本地音频文件的相对路径
private static final String AUDIO_FILE = "voice.mp3";
private static final String AUDIO_MIME_TYPE = "audio/mpeg";
// 生成 data URI
public static String toDataUrl(String filePath) throws IOException {
byte[] bytes = Files.readAllBytes(Paths.get(filePath));
String encoded = Base64.getEncoder().encodeToString(bytes);
return "data:" + AUDIO_MIME_TYPE + ";base64," + encoded;
}
// 调用 API 创建 voice
public static String createVoice() throws Exception {
// 若没有配置环境变量,请用千问AI平台 API Key 将下行替换为:String apiKey = "sk-xxx"
String apiKey = System.getenv("DASHSCOPE_API_KEY");
String jsonPayload =
"{"
+ "\"model\": \"qwen-voice-enrollment\","
+ "\"input\": {"
+ "\"action\": \"create\","
+ "\"target_model\": \"" + TARGET_MODEL + "\","
+ "\"preferred_name\": \"" + PREFERRED_NAME + "\","
+ "\"audio\": {"
+ "\"data\": \"" + toDataUrl(AUDIO_FILE) + "\""
+ "}"
+ "}"
+ "}";
String url = "https://dashscope.aliyuncs.com/api/v1/services/audio/tts/customization";
HttpURLConnection con = (HttpURLConnection) new URL(url).openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Authorization", "Bearer " + apiKey);
con.setRequestProperty("Content-Type", "application/json");
con.setDoOutput(true);
try (OutputStream os = con.getOutputStream()) {
os.write(jsonPayload.getBytes(StandardCharsets.UTF_8));
}
int status = con.getResponseCode();
try (BufferedReader br = new BufferedReader(
new InputStreamReader(status >= 200 && status < 300 ? con.getInputStream() : con.getErrorStream(),
StandardCharsets.UTF_8))) {
StringBuilder response = new StringBuilder();
String line;
while ((line = br.readLine()) != null) {
response.append(line);
}
if (status == 200) {
JsonObject jsonObj = new Gson().fromJson(response.toString(), JsonObject.class);
return jsonObj.getAsJsonObject("output").get("voice").getAsString();
}
throw new IOException("创建语音失败: " + status + " - " + response);
}
}
// 简单的音频播放器
static class SimpleAudioPlayer {
private final SourceDataLine line;
private final Queue audioQueue = new ConcurrentLinkedQueue<>();
private final Thread playerThread;
private final AtomicBoolean shouldStop = new AtomicBoolean(false);
```
--------------------------------
### Start Qoder CLI
Source: https://platform.qianwenai.com/docs/developer-guides/clients-and-developer-tools/qoder
重启并启动 Qoder CLI 交互界面。
```bash
qodercli
```
--------------------------------
### cURL Request Example
Source: https://platform.qianwenai.com/docs/api-reference/platform-api/conversations/list-items
使用 cURL 发送 GET 请求查询会话消息列表。
```bash
curl "https://dashscope.aliyuncs.com/compatible-mode/v1/conversations/conv_xxx/items?limit=10&order=asc" \
-H "Authorization: Bearer $DASHSCOPE_API_KEY"
```
--------------------------------
### task-started Event JSON
Source: https://platform.qianwenai.com/docs/api-reference/speech-synthesis/sambert/websocket
Example of the JSON payload received when a synthesis task has successfully started.
```json
{
"header": {
"task_id": "2bf83b9a-baeb-4fda-8d9a-xxxxxxxxxxxx",
"event": "task-started",
"attributes": {}
},
"payload": {}
}
```
--------------------------------
### Initialize and Use FunASR SDK
Source: https://platform.qianwenai.com/docs/api-reference/speech-recognition/fun-asr-realtime/harmonyos-sdk
Demonstrates the core SDK workflow including callback implementation, instance initialization, parameter configuration, and starting/stopping the dialog.
```typescript
import { AsrResult, Constants, INativeNuiCallback, KwsResult, NativeNui } from 'neonui';
const callback: INativeNuiCallback = {
onNuiEventCallback: (event: Constants.NuiEvent, resultCode: number, arg2: number,
kwsResult: KwsResult, asrResult: AsrResult): void => {
if (event == Constants.NuiEvent.EVENT_ASR_PARTIAL_RESULT
|| event == Constants.NuiEvent.EVENT_SENTENCE_END) {
// 从asrResult.allResponse中解析payload.output.sentence.text。
} else if (event == Constants.NuiEvent.EVENT_TRANSCRIBER_COMPLETE) {
// 识别结束。
} else if (event == Constants.NuiEvent.EVENT_ASR_ERROR) {
// resultCode为错误码。
}
},
onNuiAudioStateChanged: (state: Constants.AudioState): void => {
// 根据STATE_OPEN、STATE_PAUSE和STATE_CLOSE控制AudioCapturer。
},
onNuiNeedAudioData: (buffer: ArrayBuffer): number => {
// 从录音队列读取数据并填入buffer,返回实际字节数。
return 0;
},
onNuiAudioRMSChanged: (val: number): number => 0,
onNuiLogTrackCallback: (level: Constants.LogLevel, log: string): void => {}
};
const nuiInstance = new NativeNui(Constants.ModeType.MODE_DIALOG);
const initParams: Record = {};
initParams['url'] = 'wss://dashscope.aliyuncs.com/api-ws/v1/inference';
initParams['device_id'] = 'my_device_id';
initParams['service_mode'] = Constants.ModeFullCloud;
initParams['audio_update_manually'] = 'false';
const initResult = nuiInstance.initialize(
callback,
JSON.stringify(initParams),
Constants.LogLevel.LOG_LEVEL_DEBUG,
false
);
if (initResult == Constants.NuiResultCode.SUCCESS) {
const nlsConfig: Record = {
'model': 'qwen-audio-3.0-asr-flash-streaming',
'sr_format': 'opus',
'sample_rate': 16000
};
const params: Record = {
'service_type': Constants.kServiceTypeSpeechTranscriber,
'nls_config': nlsConfig
};
nuiInstance.setParams(JSON.stringify(params));
const dialogParams: Record = { 'apikey': 'st-****' };
nuiInstance.startDialog(Constants.VadMode.TYPE_P2T, JSON.stringify(dialogParams));
}
// 用户结束录音时停止识别,并等待EVENT_TRANSCRIBER_COMPLETE。
function stopRecognition(): void {
nuiInstance.stopDialog();
}
// 在EVENT_TRANSCRIBER_COMPLETE的处理逻辑中调用nuiInstance.release()。
```
--------------------------------
### Streaming SSE intermediate result
Source: https://platform.qianwenai.com/docs/api-reference/speech-synthesis/cosyvoice-nrt/http-api
An example of an intermediate SSE response during a streaming request, indicating the start of a sentence.
```json
{
"request_id": "8ac1cd04-06af-9a63-b031-xxxxxxxxxxxx",
"output": {
"finish_reason": "null",
"type": "sentence-begin",
"original_text": "我家的后面有一个很大的花园。",
"sentence": {
"index": 0,
"words": []
},
"audio": {
"data": "",
"id": "audio_ee88b03d-0457-9286-8c67-xxxxxxxxxxxx",
"expires_at": 1772697707
}
},
"usage": {
"characters": 15
}
}
```
--------------------------------
### DashScope Java Generation Setup
Source: https://platform.qianwenai.com/docs/developer-guides/third-party-models/minimax-minimaxi
Java example using DashScope SDK (version 2.19.4 or higher) to handle generation results.
```java
// dashscope SDK的版本 >= 2.19.4
import com.alibaba.dashscope.aigc.generation.Generation;
import com.alibaba.dashscope.aigc.generation.GenerationParam;
import com.alibaba.dashscope.aigc.generation.GenerationResult;
import com.alibaba.dashscope.common.Message;
import com.alibaba.dashscope.common.Role;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import io.reactivex.Flowable;
import java.lang.System;
import java.util.Arrays;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Main {
private static final Logger logger = LoggerFactory.getLogger(Main.class);
private static StringBuilder reasoningContent = new StringBuilder();
private static StringBuilder finalContent = new StringBuilder();
private static boolean isFirstPrint = true;
private static void handleGenerationResult(GenerationResult message) {
String reasoning = message.getOutput().getChoices().get(0).getMessage().getReasoningContent();
String content = message.getOutput().getChoices().get(0).getMessage().getContent();
if (reasoning != null && !reasoning.isEmpty()) {
reasoningContent.append(reasoning);
if (isFirstPrint) {
System.out.println("====================思考过程====================");
isFirstPrint = false;
}
System.out.print(reasoning);
}
```
--------------------------------
### Initialize Connection Parameters
Source: https://platform.qianwenai.com/docs/api-reference/speech-recognition/fun-asr-realtime/harmonyos-sdk
Example JSON configuration for the initialize method's parameters argument.
```json
{
"url": "wss://dashscope.aliyuncs.com/api-ws/v1/inference",
"device_id": "my_device_id",
"service_mode": "1",
"audio_update_manually": "false"
}
```
--------------------------------
### Python - Synchronous Call Setup
Source: https://platform.qianwenai.com/docs/api-reference/video-generation/wan27-video-editing/create-task
Initial setup for the Python SDK, including API key configuration and reference image input methods.
```python
import os
import base64
import mimetypes
from http import HTTPStatus
# dashscope sdk >= 1.25.16
from dashscope import VideoSynthesis
import dashscope
dashscope.base_http_api_url = 'https://dashscope.aliyuncs.com/api/v1'
# 从环境变量获取 DashScope API Key
api_key = os.getenv("DASHSCOPE_API_KEY")
# ========== 参考图像输入方式(三选一)==========
# [方式一] 使用公网图片 URL
reference_image_url = "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260402/fwjpqf/wan2.7-videoedit-change-clothes.png"
# [方式二] 使用本地文件路径(file:// + 文件路径)
# reference_image_url = "file://" + "/path/to/image.png" # Linux/macOS
# reference_image_url = "file://" + "C:/path/to/image.png" # Windows
```
--------------------------------
### Analyze Video Content Output
Source: https://platform.qianwenai.com/docs/developer-guides/multimodal/vision
Example JSON output for a video analysis request identifying specific events with start and end timestamps.
```json
{"events": [{"start_time": "00:00:00", "end_time": "00:00:05", "event": "The person walks towards the table holding a cardboard box and places it on the table."}, {"start_time": "00:00:05", "end_time": "00:00:15", "event": "The person picks up a scanner and scans the label on the cardboard box."}, {"start_time": "00:00:15", "end_time": "00:00:21", "event": "The person puts the scanner back in its place and then picks up a pen to write information in a notebook."}]}
```
--------------------------------
### Java SDK: Setup and Imports
Source: https://platform.qianwenai.com/docs/developer-guides/video-generation/image-to-video-first-last
Initial setup and imports for the DashScope Java SDK. Requires SDK version 2.22.6 or higher.
```java
import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesis;
import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesisParam;
import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesisResult;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.utils.JsonUtils;
import com.alibaba.dashscope.utils.Constants;
public class Image2Video {
static {
Constants.baseHttpApiUrl = "https://dashscope.aliyuncs.com/api/v1";
}
// 如果未设置环境变量,请将下行替换为:apiKey="sk-xxx"
static String apiKey = System.getenv("DASHSCOPE_API_KEY");
```
--------------------------------
### GET /api/v1/tasks/
Source: https://platform.qianwenai.com/docs/api-reference/more/manage-asynchronous-tasks
Retrieves a paginated list of asynchronous tasks based on optional query parameters such as start time, end time, and task status.
```APIDOC
## GET /api/v1/tasks/
### Description
Retrieves a list of asynchronous tasks. Supports filtering by start time, end time, and task status.
### Method
GET
### Endpoint
https://dashscope.aliyuncs.com/api/v1/tasks/
### Parameters
#### Query Parameters
- **start_time** (Long) - Optional - Task start time (millisecond timestamp).
- **end_time** (Long) - Optional - Task end time (millisecond timestamp).
- **status** (String) - Optional - Task status (PENDING, RUNNING, SUCCEEDED, FAILED, CANCELED, UNKNOWN).
### Response
#### Success Response (200)
- **request_id** (String) - Unique identifier for the request.
- **data** (Array) - List of task results.
- **page_no** (Integer) - Current page number.
- **page_size** (Integer) - Number of items per page.
- **total_page** (Integer) - Total number of pages.
- **total** (Integer) - Total number of items.
#### Response Example
{
"request_id": "7574ee8f-xxxx-xxxx-xxxx-11c33ab46e51",
"data": [],
"page_no": 1,
"page_size": 10,
"total_page": 4,
"total": 39
}
```
--------------------------------
### Java - Video Repainting Setup
Source: https://platform.qianwenai.com/docs/api-reference/video-generation/wan-general-video-editing/create-task
This Java snippet provides the initial setup for interacting with the DashScope API, including header configuration and environment variable validation.
```java
import org.json.*;
import java.io.*;
import java.net.*;
import java.util.HashMap;
import java.util.Map;
public class VideoRepainting {
static final String BASE_URL = "https://dashscope.aliyuncs.com/api/v1";
static final String API_KEY = System.getenv("DASHSCOPE_API_KEY");
private static final Map COMMON_HEADERS = new HashMap<>();
static {
if (API_KEY == null || API_KEY.isEmpty()) {
throw new IllegalStateException("DASHSCOPE_API_KEY is not set");
}
COMMON_HEADERS.put("Authorization", "Bearer " + API_KEY);
System.setProperty("http.keepAlive", "true");
System.setProperty("http.maxConnections", "20");
}
```
--------------------------------
### Request with cache_control and additional messages
Source: https://platform.qianwenai.com/docs/developer-guides/run-and-scale/context-cache
Example of a subsequent request structure that may trigger a cache hit if the number of messages between the cache marker and the start is within the limit.
```json
[
{"role": "system", "content": "A"},
// <其他消息>
{"role": "user","content": [{"type": "text", "text": "B", "cache_control": {"type": "ephemeral"}}]}
]
```
--------------------------------
### start_audio_player
Source: https://platform.qianwenai.com/docs/api-reference/realtime-api/linux-python-sdk
Starts the audio player. This is an empty implementation on Linux; audio output must be handled via callbacks.
```python
def start_audio_player(self, config: AoqAudioPlaybackConfig) -> int
```
--------------------------------
### startAudioFile
Source: https://platform.qianwenai.com/docs/api-reference/realtime-api/windows-sdk
开始推流播放本地音频文件。fileId 需保证业务层唯一性,config 为音频文件混音配置。
```cpp
virtual int startAudioFile(const char* fileId, const AoqAudioFileMixConfig& config);
```
--------------------------------
### Translate text with cURL
Source: https://platform.qianwenai.com/docs/developer-guides/text-generation/qwen-mt
Perform a translation request using the Qwen-MT model via the DashScope API. This example includes a translation memory (tm_list) to guide the translation process.
```bash
curl -X POST https://dashscope.aliyuncs.com/api/v1/services/aigc/text-generation/generation \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"model": "qwen-mt-flash",
"input": {
"messages": [
{
"content": "El siguiente comando muestra la información de la versión de Thrift instalada.",
"role": "user"
}
]
},
"parameters": {
"translation_options": {
"source_lang": "auto",
"target_lang": "English",
"tm_list":[
{"source": "Puede utilizar uno de los siguientes métodos para consultar la versión del motor de un clúster:", "target": "You can use one of the following methods to query the engine version of a cluster:"},
{"source": "La versión de Thrift utilizada por nuestro HBase en la nube es la 0.9.0. Por lo tanto, recomendamos que la versión del cliente también sea la 0.9.0. Puede descargar Thrift 0.9.0 desde aquí. El paquete de código fuente descargado se utilizará posteriormente. Primero debe instalar el entorno de compilación de Thrift. Para la instalación desde el código fuente, puede consultar el sitio web oficial de Thrift.", "target": "The version of Thrift used by ApsaraDB for HBase is 0.9.0. Therefore, we recommend that you use Thrift 0.9.0 to create a client. Click here to download Thrift 0.9.0. The downloaded source code package will be used later. You must install the Thrift compiling environment first. For more information, see Thrift official website."},
{"source": "Puede instalar el SDK a través de PyPI. El comando de instalación es el siguiente:", "target": "You can run the following command in Python Package Index (PyPI) to install Elastic Container Instance SDK for Python:"}
]
}
}'
```
--------------------------------
### Translate with translation memory using OpenAI SDK
Source: https://platform.qianwenai.com/docs/developer-guides/text-generation/qwen-mt
Use the OpenAI-compatible SDK to perform translation while providing a list of translation memory examples to guide the model's style.
```python
import os
from openai import OpenAI
client = OpenAI(
# 若未配置环境变量,请将下行替换为您的 API Key:api_key="sk-xxx",
api_key=os.getenv("DASHSCOPE_API_KEY"),
base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
)
messages = [
{
"role": "user",
"content": "El siguiente comando muestra la información de la versión de Thrift instalada."
}
]
translation_options = {
"source_lang": "auto",
"target_lang": "English",
"tm_list": [
{
"source": "Puede utilizar uno de los siguientes métodos para consultar la versión del motor de un clúster:",
"target": "You can use one of the following methods to query the engine version of a cluster:"
},
{
"source": "La versión de Thrift utilizada por nuestro HBase en la nube es la 0.9.0. Por lo tanto, recomendamos que la versión del cliente también sea la 0.9.0. Puede descargar Thrift 0.9.0 desde aquí. El paquete de código fuente descargado se utilizará posteriormente. Primero debe instalar el entorno de compilación de Thrift. Para la instalación desde el código fuente, puede consultar el sitio web oficial de Thrift.",
"target": "The version of Thrift used by ApsaraDB for HBase is 0.9.0. Therefore, we recommend that you use Thrift 0.9.0 to create a client. Click here to download Thrift 0.9.0. The downloaded source code package will be used later. You must install the Thrift compiling environment first. For more information, see Thrift official website."
},
{
"source": "Puede instalar el SDK a través de PyPI. El comando de instalación es el siguiente:",
"target": "You can run the following command in Python Package Index (PyPI) to install Elastic Container Instance SDK for Python:"
}
]
}
completion = client.chat.completions.create(
model="qwen-mt-plus",
messages=messages,
extra_body={
"translation_options": translation_options
}
)
print(completion.choices[0].message.content)
```
--------------------------------
### initialize
Source: https://platform.qianwenai.com/docs/api-reference/speech-recognition/fun-asr-realtime/harmonyos-sdk
Initializes the SDK with connection and control parameters provided as a JSON string.
```APIDOC
## initialize
### Description
Initializes the HarmonyOS SDK for real-time speech recognition using a JSON configuration string.
### Parameters
#### Request Body (JSON String)
- **url** (string) - Required - Service address, fixed to "wss://dashscope.aliyuncs.com/api-ws/v1/inference".
- **service_mode** (string) - Required - Running mode, fixed to "1" for real-time speech recognition.
- **device_id** (string) - Required - Unique identifier for the end user.
- **apikey** (string) - Optional - API Key for authentication.
- **audio_update_manually** (string) - Optional - Whether to enable manual audio data push mode (default: "false").
- **workspace** (string) - Optional - Path for local resource files.
- **debug_path** (string) - Optional - Directory for log files.
- **save_wav** (string) - Optional - Whether to save debug audio (default: "false").
- **save_wav_by_id** (string) - Optional - Whether to name audio files by task_id (default: "false").
- **max_log_file_size** (number) - Optional - Maximum size of a single log file in bytes (default: 104857600).
- **log_track_level** (number) - Optional - Log filtering level for callbacks (default: 2).
- **enable_reconnection** (string) - Optional - Whether to enable reconnection (default: "false").
- **aec_params** (object) - Optional - Local AEC configuration.
### Request Example
{
"url": "wss://dashscope.aliyuncs.com/api-ws/v1/inference",
"device_id": "my_device_id",
"service_mode": "1",
"audio_update_manually": "false"
}
```
--------------------------------
### Go WebSocket Connection and Task Execution
Source: https://platform.qianwenai.com/docs/api-reference/speech-recognition/fun-asr-realtime/websocket-api
Example implementation for connecting to the WebSocket service, sending run-task commands, and streaming audio data in Go.
```go
package main
import (
"encoding/json"
"fmt"
"io"
"log"
"net/http"
"os"
"time"
"github.com/google/uuid"
"github.com/gorilla/websocket"
)
const (
wsURL = "wss://dashscope.aliyuncs.com/api-ws/v1/inference/" // WebSocket 服务地址
audioFile = "asr_example.wav" // 替换为您的音频文件路径
)
var dialer = websocket.DefaultDialer
func main() {
// 若未配置环境变量,请将下行替换为您的 API Key:apiKey := "sk-xxx"
apiKey := os.Getenv("DASHSCOPE_API_KEY")
// 连接 WebSocket 服务
conn, err := connectWebSocket(apiKey)
if err != nil {
log.Fatal("WebSocket 连接失败:", err)
}
defer closeConnection(conn)
// 启动 goroutine 接收结果
taskStarted := make(chan bool)
taskDone := make(chan bool)
startResultReceiver(conn, taskStarted, taskDone)
// 发送 run-task 指令
taskID, err := sendRunTaskCmd(conn)
if err != nil {
log.Fatal("发送 run-task 指令失败:", err)
}
// 等待 task-started 事件
waitForTaskStarted(taskStarted)
// 发送音频文件流进行识别
if err := sendAudioData(conn); err != nil {
log.Fatal("发送音频失败:", err)
}
```
--------------------------------
### Verify Claude Code installation
Source: https://platform.qianwenai.com/docs/developer-guides/clients-and-developer-tools/claude-code
Check the installed version of Claude Code to verify successful installation.
```bash
claude --version
```
--------------------------------
### Audio and Text Input with Python
Source: https://platform.qianwenai.com/docs/developer-guides/speech/multimodal-speech
Example of using the OpenAI Python SDK to send an audio URL and text prompt to the qwen3.5-omni-plus model with streaming enabled.
```python
import os
from openai import OpenAI
client = OpenAI(
api_key=os.getenv("DASHSCOPE_API_KEY"),
base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
)
completion = client.chat.completions.create(
model="qwen3.5-omni-plus",
messages=[
{
"role": "user",
"content": [
{
"type": "input_audio",
"input_audio": {
"data": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250211/tixcef/cherry.wav",
"format": "wav",
},
},
{"type": "text", "text": "这段音频讲了什么"},
],
},
],
modalities=["text", "audio"],
audio={"voice": "Tina", "format": "wav"},
stream=True,
stream_options={"include_usage": True},
)
for chunk in completion:
if chunk.choices:
print(chunk.choices[0].delta)
else:
print(chunk.usage)
```
--------------------------------
### Verify Kilo CLI Installation
Source: https://platform.qianwenai.com/docs/developer-guides/clients-and-developer-tools/kilo-cli
Check the installed version of the Kilo CLI to verify successful installation.
```bash
kilo --version
```
--------------------------------
### Install QwenPaw via Windows CMD script
Source: https://platform.qianwenai.com/docs/developer-guides/clients-and-developer-tools/qwenpaw
Use this command to automatically install uv, create a virtual environment, and download dependencies on Windows using CMD.
```bash
curl -fsSL https://qwenpaw.agentscope.io/install.bat -o install.bat && install.bat
```
--------------------------------
### OpenAI Node.js GUI Interaction Setup
Source: https://platform.qianwenai.com/docs/developer-guides/text-generation/gui-interaction
Configures the system prompt with computer_use tool definitions and initializes the OpenAI client to interact with the DashScope API.
```javascript
import OpenAI from "openai";
const systemPrompt = `# Tools
You may call one or more functions to assist with the user query.
You are provided with function signatures within XML tags:
{"type": "function", "function": {"name": "computer_use", "description": "Use a mouse and keyboard to interact with a computer, and take screenshots.\n* This is an interface to a desktop GUI. You do not have access to a terminal or applications menu. You must click on desktop icons to start applications.\n* Some applications may take time to start or process actions, so you may need to wait and take successive screenshots to see the results of your actions. E.g. if you click on Firefox and a window doesn't open, try wait and taking another screenshot.\n* The screen's resolution is 1000x1000.\n* Make sure to click any buttons, links, icons, etc with the cursor tip in the center of the element. Don't click boxes on their edges unless asked.", "parameters": {"properties": {"action": {"description": "The action to perform. The available actions are:\n* `key`: Performs key down presses on the arguments passed in order, then performs key releases in reverse order.\n* `type`: Type a string of text on the keyboard.\n* `mouse_move`: Move the cursor to a specified (x, y) pixel coordinate on the screen.\n* `left_click`: Click the left mouse button at a specified (x, y) pixel coordinate on the screen.\n* `left_click_drag`: Click and drag the cursor to a specified (x, y) pixel coordinate on the screen.\n* `right_click`: Click the right mouse button at a specified (x, y) pixel coordinate on the screen.\n* `middle_click`: Click the middle mouse button at a specified (x, y) pixel coordinate on the screen.\n* `double_click`: Double-click the left mouse button at a specified (x, y) pixel coordinate on the screen.\n* `triple_click`: Triple-click the left mouse button at a specified (x, y) pixel coordinate on the screen (simulated as double-click since it's the closest action).\n* `scroll`: Performs a scroll of the mouse scroll wheel.\n* `hscroll`: Performs a horizontal scroll (mapped to regular scroll).\n* `wait`: Wait specified seconds for the change to happen.\n* `terminate`: Terminate the current task and report its completion status.\n* `answer`: Answer a question.\n* `interact`: Resolve the blocking window by interacting with the user.", "enum": ["key", "type", "mouse_move", "left_click", "left_click_drag", "right_click", "middle_click", "double_click", "triple_click", "scroll", "hscroll", "wait", "terminate", "answer", "interact"], "type": "string"}, "keys": {"description": "Required only by `action=key`.", "type": "array"}, "text": {"description": "Required only by `action=type`, `action=answer` and `action=interact`.", "type": "string"}, "coordinate": {"description": "(x, y): The x (pixels from the left edge) and y (pixels from the top edge) coordinates to move the mouse to. Required only by `action=mouse_move` and `action=left_click_drag`.", "type": "array"}, "pixels": {"description": "The amount of scrolling to perform. Positive values scroll up, negative values scroll down. Required only by `action=scroll` and `action=hscroll`.", "type": "number"}, "time": {"description": "The seconds to wait. Required only by `action=wait`.", "type": "number"}, "status": {"description": "The status of the task. Required only by `action=terminate`.", "type": "string", "enum": ["success", "failure"]}}, "required": ["action"], "type": "object"}}}
For each function call, return a json object with function name and arguments within XML tags:
{"name": , "arguments": }
# Response format
Response format for every step:
1) Action: a short imperative describing what to do in the UI.
2) A single ... block containing only the JSON: {"name": , "arguments": }.
Rules:
- Output exactly in the order: Action, .
- Be brief: one for Action.
- Do not output anything else outside those two parts.
- If finishing, use action=terminate in the tool call.`;
const client = new OpenAI({
apiKey: process.env.DASHSCOPE_API_KEY,
baseURL: "https://dashscope.aliyuncs.com/compatible-mode/v1",
});
const messages = [
{
role: "system",
content: systemPrompt,
},
{
role: "user",
content: [
{
type: "image_url",
image_url: {
url: "https://img.alicdn.com/imgextra/i2/O1CN016iJ8ob1C3xP1s2M6z_!!6000000000026-2-tps-3008-1758.png",
},
},
{ type: "text", text: "帮我打开浏览器" },
],
},
];
```
--------------------------------
### Install PortAudio on macOS
Source: https://platform.qianwenai.com/docs/developer-guides/speech/realtime-translation
Use Homebrew to install the required PortAudio library and then install the PyAudio Python package.
```bash
brew install portaudio && pip install pyaudio
```
--------------------------------
### Wan26ImageParameters Size Example
Source: https://platform.qianwenai.com/docs/api-reference/image-generation/wan26-image-gen-edit/query-result
Example of the size parameter setting.
```yaml
1K
```
--------------------------------
### Main Execution Loop
Source: https://platform.qianwenai.com/docs/developer-guides/speech/qwen-audio-realtime
Initializes the audio player and client, then runs the message handling and recording loops concurrently.
```python
async def main():
pya = pyaudio.PyAudio()
# 输出采样率 24kHz,匹配服务端音频格式
player = B64PCMPlayer(pya, sample_rate=24000)
client = FunRealtimeClient(
base_url="wss://dashscope.aliyuncs.com/api-ws/v1/realtime",
api_key=os.environ['DASHSCOPE_API_KEY'],
model="qwen-audio-3.0-realtime-plus",
voice="longanqian",
turn_detection_mode=TurnDetectionMode.SERVER_VAD,
on_audio_delta_b64=player.add_data,
# 语音打断时清空播放缓冲
on_speech_started=player.cancel_playing,
)
await client.connect()
print("连接成功,开始实时对话...")
try:
# 并发运行:消息处理 + 麦克风采集
await asyncio.gather(client.handle_messages(), record_and_send(client, player, echo_suppression=False))
finally:
await client.close()
player.shutdown()
pya.terminate()
if __name__ == "__main__":
try:
asyncio.run(main())
except KeyboardInterrupt:
print("\n程序已退出。")
```