请求体文本输入Pythonimport os
import dashscope
messages = [
{'role': 'system', 'content': 'You are a helpful assistant.'},
{'role': 'user', 'content': '你是谁?'}
]
response = dashscope.Generation.call(
# 若没有配置环境变量,请用百炼API Key将下行替换为:api_key="sk-xxx"
api_key=os.getenv('DASHSCOPE_API_KEY'),
model="qwen-plus", # 此处以qwen-plus为例,可按需更换模型名称。模型列表:https://help.aliyun.com/zh/model-studio/getting-started/models
messages=messages,
result_format='message'
)
print(response)Java// 建议dashscope SDK的版本 >= 2.12.0
import java.util.Arrays;
import java.lang.System;
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 com.alibaba.dashscope.utils.JsonUtils;
public class Main {
public static GenerationResult callWithMessage() throws ApiException, NoApiKeyException, InputRequiredException {
Generation gen = new Generation();
Message systemMsg = Message.builder()
.role(Role.SYSTEM.getValue())
.content("You are a helpful assistant.")
.build();
Message userMsg = Message.builder()
.role(Role.USER.getValue())
.content("你是谁?")
.build();
GenerationParam param = GenerationParam.builder()
// 若没有配置环境变量,请用百炼API Key将下行替换为:.apiKey("sk-xxx")
.apiKey(System.getenv("DASHSCOPE_API_KEY"))
// 此处以qwen-plus为例,可按需更换模型名称。模型列表:https://help.aliyun.com/zh/model-studio/getting-started/models
.model("qwen-plus")
.messages(Arrays.asList(systemMsg, userMsg))
.resultFormat(GenerationParam.ResultFormat.MESSAGE)
.build();
return gen.call(param);
}
public static void main(String[] args) {
try {
GenerationResult result = callWithMessage();
System.out.println(JsonUtils.toJson(result));
} catch (ApiException | NoApiKeyException | InputRequiredException e) {
// 使用日志框架记录异常信息
System.err.println("An error occurred while calling the generation service: " + e.getMessage());
}
System.exit(0);
}
}PHP(HTTP)
$url = "https://dashscope.aliyuncs.com/api/v1/services/aigc/text-generation/generation";
$apiKey = getenv('DASHSCOPE_API_KEY');
$data = [
// 此处以qwen-plus为例,可按需更换模型名称。模型列表:https://help.aliyun.com/zh/model-studio/getting-started/models
"model" => "qwen-plus",
"input" => [
"messages" => [
[
"role" => "system",
"content" => "You are a helpful assistant."
],
[
"role" => "user",
"content" => "你是谁?"
]
]
],
"parameters" => [
"result_format" => "message"
]
];
$jsonData = json_encode($data);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Authorization: Bearer $apiKey",
"Content-Type: application/json"
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($httpCode == 200) {
echo "Response: " . $response;
} else {
echo "Error: " . $httpCode . " - " . $response;
}
curl_close($ch);
?>Node.js(HTTP)DashScope 未提供 Node.js 环境的 SDK。如需通过 OpenAI Node.js SDK调用,请参考本文的OpenAI章节。
import fetch from 'node-fetch';
const apiKey = process.env.DASHSCOPE_API_KEY;
const data = {
model: "qwen-plus", // 此处以qwen-plus为例,可按需更换模型名称。模型列表:https://help.aliyun.com/zh/model-studio/getting-started/models
input: {
messages: [
{
role: "system",
content: "You are a helpful assistant."
},
{
role: "user",
content: "你是谁?"
}
]
},
parameters: {
result_format: "message"
}
};
fetch('https://dashscope.aliyuncs.com/api/v1/services/aigc/text-generation/generation', {
method: 'POST',
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
})
.then(response => response.json())
.then(data => {
console.log(JSON.stringify(data));
})
.catch(error => {
console.error('Error:', error);
});C#(HTTP)using System.Net.Http.Headers;
using System.Text;
class Program
{
private static readonly HttpClient httpClient = new HttpClient();
static async Task Main(string[] args)
{
// 若没有配置环境变量,请用百炼API Key将下行替换为:string? apiKey = "sk-xxx";
string? apiKey = Environment.GetEnvironmentVariable("DASHSCOPE_API_KEY");
if (string.IsNullOrEmpty(apiKey))
{
Console.WriteLine("API Key 未设置。请确保环境变量 'DASHSCOPE_API_KEY' 已设置。");
return;
}
// 设置请求 URL 和内容
string url = "https://dashscope.aliyuncs.com/api/v1/services/aigc/text-generation/generation";
// 此处以qwen-plus为例,可按需更换模型名称。模型列表:https://help.aliyun.com/zh/model-studio/getting-started/models
string jsonContent = @"{
""model"": ""qwen-plus"",
""input"": {
""messages"": [
{
""role"": ""system"",
""content"": ""You are a helpful assistant.""
},
{
""role"": ""user"",
""content"": ""你是谁?""
}
]
},
""parameters"": {
""result_format"": ""message""
}
}";
// 发送请求并获取响应
string result = await SendPostRequestAsync(url, jsonContent, apiKey);
// 输出结果
Console.WriteLine(result);
}
private static async Task
{
using (var content = new StringContent(jsonContent, Encoding.UTF8, "application/json"))
{
// 设置请求头
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
// 发送请求并获取响应
HttpResponseMessage response = await httpClient.PostAsync(url, content);
// 处理响应
if (response.IsSuccessStatusCode)
{
return await response.Content.ReadAsStringAsync();
}
else
{
return $"请求失败: {response.StatusCode}";
}
}
}
}Go(HTTP)DashScope 未提供 Go 的 SDK。如需通过 OpenAI Go SDK调用,请参考本文的OpenAI-Go章节。
package main
import (
"bytes"
"encoding/json"
"fmt"
"io"
"log"
"net/http"
"os"
)
type Message struct {
Role string `json:"role"`
Content string `json:"content"`
}
type Input struct {
Messages []Message `json:"messages"`
}
type Parameters struct {
ResultFormat string `json:"result_format"`
}
type RequestBody struct {
Model string `json:"model"`
Input Input `json:"input"`
Parameters Parameters `json:"parameters"`
}
func main() {
// 创建 HTTP 客户端
client := &http.Client{}
// 构建请求体
requestBody := RequestBody{
// 此处以qwen-plus为例,可按需更换模型名称。模型列表:https://help.aliyun.com/zh/model-studio/getting-started/models
Model: "qwen-plus",
Input: Input{
Messages: []Message{
{
Role: "system",
Content: "You are a helpful assistant.",
},
{
Role: "user",
Content: "你是谁?",
},
},
},
Parameters: Parameters{
ResultFormat: "message",
},
}
jsonData, err := json.Marshal(requestBody)
if err != nil {
log.Fatal(err)
}
// 创建 POST 请求
req, err := http.NewRequest("POST", "https://dashscope.aliyuncs.com/api/v1/services/aigc/text-generation/generation", bytes.NewBuffer(jsonData))
if err != nil {
log.Fatal(err)
}
// 设置请求头
// 若没有配置环境变量,请用百炼API Key将下行替换为:apiKey := "sk-xxx"
apiKey := os.Getenv("DASHSCOPE_API_KEY")
req.Header.Set("Authorization", "Bearer "+apiKey)
req.Header.Set("Content-Type", "application/json")
// 发送请求
resp, err := client.Do(req)
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
// 读取响应体
bodyText, err := io.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
// 打印响应内容
fmt.Printf("%s\n", bodyText)
}
curlcurl --location "https://dashscope.aliyuncs.com/api/v1/services/aigc/text-generation/generation" \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header "Content-Type: application/json" \
--data '{
"model": "qwen-plus",
"input":{
"messages":[
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "你是谁?"
}
]
},
"parameters": {
"result_format": "message"
}
}'流式输出相关文档:流式输出。文本生成模型Pythonimport os
import dashscope
messages = [
{'role':'system','content':'you are a helpful assistant'},
{'role': 'user','content': '你是谁?'}
]
responses = dashscope.Generation.call(
# 若没有配置环境变量,请用百炼API Key将下行替换为:api_key="sk-xxx"
api_key=os.getenv('DASHSCOPE_API_KEY'),
model="qwen-plus", # 此处以qwen-plus为例,可按需更换模型名称。模型列表:https://help.aliyun.com/zh/model-studio/getting-started/models
messages=messages,
result_format='message',
stream=True,
incremental_output=True
)
for response in responses:
print(response) Javaimport java.util.Arrays;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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 com.alibaba.dashscope.utils.JsonUtils;
import io.reactivex.Flowable;
import java.lang.System;
public class Main {
private static final Logger logger = LoggerFactory.getLogger(Main.class);
private static void handleGenerationResult(GenerationResult message) {
System.out.println(JsonUtils.toJson(message));
}
public static void streamCallWithMessage(Generation gen, Message userMsg)
throws NoApiKeyException, ApiException, InputRequiredException {
GenerationParam param = buildGenerationParam(userMsg);
Flowable
result.blockingForEach(message -> handleGenerationResult(message));
}
private static GenerationParam buildGenerationParam(Message userMsg) {
return GenerationParam.builder()
// 若没有配置环境变量,请用百炼API Key将下行替换为:.apiKey("sk-xxx")
.apiKey(System.getenv("DASHSCOPE_API_KEY"))
// 此处以qwen-plus为例,可按需更换模型名称。模型列表:https://help.aliyun.com/zh/model-studio/getting-started/models
.model("qwen-plus")
.messages(Arrays.asList(userMsg))
.resultFormat(GenerationParam.ResultFormat.MESSAGE)
.incrementalOutput(true)
.build();
}
public static void main(String[] args) {
try {
Generation gen = new Generation();
Message userMsg = Message.builder().role(Role.USER.getValue()).content("你是谁?").build();
streamCallWithMessage(gen, userMsg);
} catch (ApiException | NoApiKeyException | InputRequiredException e) {
logger.error("An exception occurred: {}", e.getMessage());
}
System.exit(0);
}
}
curlcurl --location "https://dashscope.aliyuncs.com/api/v1/services/aigc/text-generation/generation" \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header "Content-Type: application/json" \
--header "X-DashScope-SSE: enable" \
--data '{
"model": "qwen-plus",
"input":{
"messages":[
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "你是谁?"
}
]
},
"parameters": {
"result_format": "message",
"incremental_output":true
}
}'多模态模型Pythonimport os
from dashscope import MultiModalConversation
import dashscope
# 若使用新加坡地域的模型,请取消下列注释
# dashscope.base_http_api_url = "https://dashscope-intl.aliyuncs.com/api/v1"
messages = [
{
"role": "user",
"content": [
{"image": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241022/emyrja/dog_and_girl.jpeg"},
{"text": "图中描绘的是什么景象?"}
]
}
]
responses = MultiModalConversation.call(
# 若没有配置环境变量,请用百炼API Key将下行替换为:api_key="sk-xxx"
# 新加坡和北京地域的API Key不同。获取API Key:https://help.aliyun.com/zh/model-studio/get-api-key
api_key=os.getenv("DASHSCOPE_API_KEY"),
model='qwen3-vl-plus', # 可按需更换为其它多模态模型,并修改相应的 messages
messages=messages,
stream=True,
incremental_output=True
)
full_content = ""
print("流式输出内容为:")
for response in responses:
if response.output.choices[0].message.content:
print(response.output.choices[0].message.content[0]['text'])
full_content += response.output.choices[0].message.content[0]['text']
print(f"完整内容为:{full_content}")Javaimport 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;
import io.reactivex.Flowable;
import com.alibaba.dashscope.utils.Constants;
public class Main {
// 若使用新加坡地域的模型,请取消下列注释
// static {Constants.baseHttpApiUrl="https://dashscope-intl.aliyuncs.com/api/v1";}
public static void streamCall()
throws ApiException, NoApiKeyException, UploadFileException {
MultiModalConversation conv = new MultiModalConversation();
MultiModalMessage userMessage = MultiModalMessage.builder().role(Role.USER.getValue())
.content(Arrays.asList(Collections.singletonMap("image", "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241022/emyrja/dog_and_girl.jpeg"),
Collections.singletonMap("text", "图中描绘的是什么景象?"))).build();
MultiModalConversationParam param = MultiModalConversationParam.builder()
// 若没有配置环境变量,请用百炼API Key将下行替换为:.apiKey("sk-xxx")
// 新加坡和北京地域的API Key不同。获取API Key:https://help.aliyun.com/zh/model-studio/get-api-key
.apiKey(System.getenv("DASHSCOPE_API_KEY"))
.model("qwen3-vl-plus") // 可按需更换为其它多模态模型,并修改相应的 messages
.messages(Arrays.asList(userMessage))
.incrementalOutput(true)
.build();
Flowable
result.blockingForEach(item -> {
try {
var content = item.getOutput().getChoices().get(0).getMessage().getContent();
// 判断content是否存在且不为空
if (content != null && !content.isEmpty()) {
System.out.println(content.get(0).get("text"));
}
} catch (Exception e) {
System.out.println(e.getMessage());
}
});
}
public static void main(String[] args) {
try {
streamCall();
} catch (ApiException | NoApiKeyException | UploadFileException e) {
System.out.println(e.getMessage());
}
System.exit(0);
}
}curl# ======= 重要提示 =======
# 新加坡和北京地域的API Key不同。获取API Key:https://help.aliyun.com/zh/model-studio/get-api-key
# 以下为北京地域url,若使用新加坡地域的模型,需将url替换为:https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation
# === 执行时请删除该注释 ===
curl -X POST https://dashscope.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H 'Content-Type: application/json' \
-H 'X-DashScope-SSE: enable' \
-d '{
"model": "qwen3-vl-plus",
"input":{
"messages":[
{
"role": "user",
"content": [
{"image": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241022/emyrja/dog_and_girl.jpeg"},
{"text": "图中描绘的是什么景象?"}
]
}
]
},
"parameters": {
"incremental_output": true
}
}'图像输入关于大模型分析图像的更多用法,请参见视觉理解。Pythonimport os
import dashscope
messages = [
{
"role": "user",
"content": [
{"image": "https://dashscope.oss-cn-beijing.aliyuncs.com/images/dog_and_girl.jpeg"},
{"image": "https://dashscope.oss-cn-beijing.aliyuncs.com/images/tiger.png"},
{"image": "https://dashscope.oss-cn-beijing.aliyuncs.com/images/rabbit.png"},
{"text": "这些是什么?"}
]
}
]
response = dashscope.MultiModalConversation.call(
# 若没有配置环境变量,请用百炼API Key将下行替换为:api_key="sk-xxx"
api_key=os.getenv('DASHSCOPE_API_KEY'),
model='qwen-vl-max', # 此处以qwen-vl-max为例,可按需更换模型名称。模型列表:https://help.aliyun.com/zh/model-studio/getting-started/models
messages=messages
)
print(response)Java// Copyright (c) Alibaba, Inc. and its affiliates.
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;
import com.alibaba.dashscope.utils.JsonUtils;
public class Main {
public static void simpleMultiModalConversationCall()
throws ApiException, NoApiKeyException, UploadFileException {
MultiModalConversation conv = new MultiModalConversation();
MultiModalMessage userMessage = MultiModalMessage.builder().role(Role.USER.getValue())
.content(Arrays.asList(
Collections.singletonMap("image", "https://dashscope.oss-cn-beijing.aliyuncs.com/images/dog_and_girl.jpeg"),
Collections.singletonMap("image", "https://dashscope.oss-cn-beijing.aliyuncs.com/images/tiger.png"),
Collections.singletonMap("image", "https://dashscope.oss-cn-beijing.aliyuncs.com/images/rabbit.png"),
Collections.singletonMap("text", "这些是什么?"))).build();
MultiModalConversationParam param = MultiModalConversationParam.builder()
// 若没有配置环境变量,请用百炼API Key将下行替换为:.apiKey("sk-xxx")
.apiKey(System.getenv("DASHSCOPE_API_KEY"))
// 此处以qwen-vl-plus为例,可按需更换模型名称。模型列表:https://help.aliyun.com/zh/model-studio/getting-started/models
.model("qwen-vl-plus")
.message(userMessage)
.build();
MultiModalConversationResult result = conv.call(param);
System.out.println(JsonUtils.toJson(result));
}
public static void main(String[] args) {
try {
simpleMultiModalConversationCall();
} catch (ApiException | NoApiKeyException | UploadFileException e) {
System.out.println(e.getMessage());
}
System.exit(0);
}
}curlcurl --location 'https://dashscope.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header 'Content-Type: application/json' \
--data '{
"model": "qwen-vl-plus",
"input":{
"messages":[
{
"role": "user",
"content": [
{"image": "https://dashscope.oss-cn-beijing.aliyuncs.com/images/dog_and_girl.jpeg"},
{"image": "https://dashscope.oss-cn-beijing.aliyuncs.com/images/tiger.png"},
{"image": "https://dashscope.oss-cn-beijing.aliyuncs.com/images/rabbit.png"},
{"text": "这些是什么?"}
]
}
]
}
}'视频输入以下为传入视频帧的示例代码,关于更多用法(如传入视频文件),请参见视觉理解。Pythonfrom http import HTTPStatus
import os
# dashscope版本需要不低于1.20.10
import dashscope
messages = [{"role": "user",
"content": [
{"video":["https://img.alicdn.com/imgextra/i3/O1CN01K3SgGo1eqmlUgeE9b_!!6000000003923-0-tps-3840-2160.jpg",
"https://img.alicdn.com/imgextra/i4/O1CN01BjZvwg1Y23CF5qIRB_!!6000000003000-0-tps-3840-2160.jpg",
"https://img.alicdn.com/imgextra/i4/O1CN01Ib0clU27vTgBdbVLQ_!!6000000007859-0-tps-3840-2160.jpg",
"https://img.alicdn.com/imgextra/i1/O1CN01aygPLW1s3EXCdSN4X_!!6000000005710-0-tps-3840-2160.jpg"]},
{"text": "描述这个视频的具体过程"}]}]
response = dashscope.MultiModalConversation.call(
# 若没有配置环境变量,请用百炼API Key将下行替换为:api_key="sk-xxx"
api_key=os.getenv("DASHSCOPE_API_KEY"),
model='qwen-vl-max-latest', # 此处以qwen-vl-max-latest为例,可按需更换模型名称。模型列表:https://help.aliyun.com/zh/model-studio/getting-started/models
messages=messages
)
if response.status_code == HTTPStatus.OK:
print(response)
else:
print(response.code)
print(response.message)Java// DashScope SDK版本需要不低于2.16.7
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;
import com.alibaba.dashscope.utils.JsonUtils;
public class Main {
// 此处以qwen-vl-max-latest为例,可按需更换模型名称。模型列表:https://help.aliyun.com/zh/model-studio/getting-started/models
private static final String MODEL_NAME = "qwen-vl-max-latest";
public static void videoImageListSample() throws ApiException, NoApiKeyException, UploadFileException {
MultiModalConversation conv = new MultiModalConversation();
MultiModalMessage systemMessage = MultiModalMessage.builder()
.role(Role.SYSTEM.getValue())
.content(Arrays.asList(Collections.singletonMap("text", "You are a helpful assistant.")))
.build();
MultiModalMessage userMessage = MultiModalMessage.builder()
.role(Role.USER.getValue())
.content(Arrays.asList(Collections.singletonMap("video", Arrays.asList("https://img.alicdn.com/imgextra/i3/O1CN01K3SgGo1eqmlUgeE9b_!!6000000003923-0-tps-3840-2160.jpg",
"https://img.alicdn.com/imgextra/i4/O1CN01BjZvwg1Y23CF5qIRB_!!6000000003000-0-tps-3840-2160.jpg",
"https://img.alicdn.com/imgextra/i4/O1CN01Ib0clU27vTgBdbVLQ_!!6000000007859-0-tps-3840-2160.jpg",
"https://img.alicdn.com/imgextra/i1/O1CN01aygPLW1s3EXCdSN4X_!!6000000005710-0-tps-3840-2160.jpg")),
Collections.singletonMap("text", "描述这个视频的具体过程")))
.build();
MultiModalConversationParam param = MultiModalConversationParam.builder()
.model(MODEL_NAME).message(systemMessage)
.message(userMessage).build();
MultiModalConversationResult result = conv.call(param);
System.out.print(JsonUtils.toJson(result));
}
public static void main(String[] args) {
try {
videoImageListSample();
} catch (ApiException | NoApiKeyException | UploadFileException e) {
System.out.println(e.getMessage());
}
System.exit(0);
}
}curlcurl -X POST https://dashscope.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"model": "qwen-vl-max-latest",
"input": {
"messages": [
{
"role": "user",
"content": [
{
"video": [
"https://img.alicdn.com/imgextra/i3/O1CN01K3SgGo1eqmlUgeE9b_!!6000000003923-0-tps-3840-2160.jpg",
"https://img.alicdn.com/imgextra/i4/O1CN01BjZvwg1Y23CF5qIRB_!!6000000003000-0-tps-3840-2160.jpg",
"https://img.alicdn.com/imgextra/i4/O1CN01Ib0clU27vTgBdbVLQ_!!6000000007859-0-tps-3840-2160.jpg",
"https://img.alicdn.com/imgextra/i1/O1CN01aygPLW1s3EXCdSN4X_!!6000000005710-0-tps-3840-2160.jpg"
]
},
{
"text": "描述这个视频的具体过程"
}
]
}
]
}
}'
音频输入音频理解关于大模型分析音频的更多用法,请参见音频理解-Qwen-Audio。Pythonimport os
import dashscope
messages = [
{
"role": "user",
"content": [
{"audio": "https://dashscope.oss-cn-beijing.aliyuncs.com/audios/welcome.mp3"},
{"text": "这段音频在说什么?"}
]
}
]
response = dashscope.MultiModalConversation.call(
# 若没有配置环境变量,请用百炼API Key将下行替换为:api_key="sk-xxx"
api_key=os.getenv('DASHSCOPE_API_KEY'),
model='qwen2-audio-instruct', # 此处以qwen2-audio-instruct为例,可按需更换模型名称。模型列表:https://help.aliyun.com/zh/model-studio/getting-started/models
messages=messages
)
print(response)
Javaimport java.util.Arrays;
import java.util.Collections;
import java.lang.System;
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;
import com.alibaba.dashscope.utils.JsonUtils;
public class Main {
public static void simpleMultiModalConversationCall()
throws ApiException, NoApiKeyException, UploadFileException {
MultiModalConversation conv = new MultiModalConversation();
MultiModalMessage userMessage = MultiModalMessage.builder().role(Role.USER.getValue())
.content(Arrays.asList(Collections.singletonMap("audio", "https://dashscope.oss-cn-beijing.aliyuncs.com/audios/welcome.mp3"),
Collections.singletonMap("text", "这段音频在说什么?"))).build();
MultiModalConversationParam param = MultiModalConversationParam.builder()
// 若没有配置环境变量,请用百炼API Key将下行替换为:.apiKey("sk-xxx")
.apiKey(System.getenv("DASHSCOPE_API_KEY"))
// 此处以qwen2-audio-instruct为例,可按需更换模型名称。模型列表:https://help.aliyun.com/zh/model-studio/getting-started/models
.model("qwen2-audio-instruct")
.message(userMessage)
.build();
MultiModalConversationResult result = conv.call(param);
System.out.println(JsonUtils.toJson(result));
}
public static void main(String[] args) {
try {
simpleMultiModalConversationCall();
} catch (ApiException | NoApiKeyException | UploadFileException e) {
System.out.println(e.getMessage());
}
System.exit(0);
}
}curlcurl --location 'https://dashscope.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header 'Content-Type: application/json' \
--data '{
"model": "qwen2-audio-instruct",
"input":{
"messages":[
{
"role": "system",
"content": [
{"text": "You are a helpful assistant."}
]
},
{
"role": "user",
"content": [
{"audio": "https://dashscope.oss-cn-beijing.aliyuncs.com/audios/welcome.mp3"},
{"text": "这段音频在说什么?"}
]
}
]
}
}'联网搜索Pythonimport os
import dashscope
messages = [
{'role': 'system', 'content': 'You are a helpful assistant.'},
{'role': 'user', 'content': '杭州明天天气是什么?'}
]
response = dashscope.Generation.call(
# 若没有配置环境变量,请用百炼API Key将下行替换为:api_key="sk-xxx"
api_key=os.getenv('DASHSCOPE_API_KEY'),
model="qwen-plus", # 此处以qwen-plus为例,可按需更换模型名称。模型列表:https://help.aliyun.com/zh/model-studio/getting-started/models
messages=messages,
enable_search=True,
result_format='message'
)
print(response)
Java// 建议dashscope SDK的版本 >= 2.12.0
import java.util.Arrays;
import java.lang.System;
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 com.alibaba.dashscope.utils.JsonUtils;
public class Main {
public static GenerationResult callWithMessage() throws ApiException, NoApiKeyException, InputRequiredException {
Generation gen = new Generation();
Message systemMsg = Message.builder()
.role(Role.SYSTEM.getValue())
.content("You are a helpful assistant.")
.build();
Message userMsg = Message.builder()
.role(Role.USER.getValue())
.content("明天杭州什么天气?")
.build();
GenerationParam param = GenerationParam.builder()
// 若没有配置环境变量,请用百炼API Key将下行替换为:.apiKey("sk-xxx")
.apiKey(System.getenv("DASHSCOPE_API_KEY"))
// 此处以qwen-plus为例,可按需更换模型名称。模型列表:https://help.aliyun.com/zh/model-studio/getting-started/models
.model("qwen-plus")
.messages(Arrays.asList(systemMsg, userMsg))
.resultFormat(GenerationParam.ResultFormat.MESSAGE)
.enableSearch(true)
.build();
return gen.call(param);
}
public static void main(String[] args) {
try {
GenerationResult result = callWithMessage();
System.out.println(JsonUtils.toJson(result));
} catch (ApiException | NoApiKeyException | InputRequiredException e) {
// 使用日志框架记录异常信息
System.err.println("An error occurred while calling the generation service: " + e.getMessage());
}
System.exit(0);
}
}curlcurl -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-plus",
"input":{
"messages":[
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "明天杭州天气如何?"
}
]
},
"parameters": {
"enable_search": true,
"result_format": "message"
}
}'工具调用完整的Function Calling 流程代码请参见Function Calling。Pythonimport os
import dashscope
tools = [
{
"type": "function",
"function": {
"name": "get_current_time",
"description": "当你想知道现在的时间时非常有用。",
"parameters": {}
}
},
{
"type": "function",
"function": {
"name": "get_current_weather",
"description": "当你想查询指定城市的天气时非常有用。",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "城市或县区,比如北京市、杭州市、余杭区等。"
}
}
},
"required": [
"location"
]
}
}
]
messages = [{"role": "user", "content": "杭州天气怎么样"}]
response = dashscope.Generation.call(
# 若没有配置环境变量,请用百炼API Key将下行替换为:api_key="sk-xxx"
api_key=os.getenv('DASHSCOPE_API_KEY'),
model='qwen-plus', # 此处以qwen-plus为例,可按需更换模型名称。模型列表:https://help.aliyun.com/zh/model-studio/getting-started/models
messages=messages,
tools=tools,
result_format='message'
)
print(response)
Javaimport java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import com.alibaba.dashscope.aigc.conversation.ConversationParam.ResultFormat;
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 com.alibaba.dashscope.tools.FunctionDefinition;
import com.alibaba.dashscope.tools.ToolFunction;
import com.alibaba.dashscope.utils.JsonUtils;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.github.victools.jsonschema.generator.Option;
import com.github.victools.jsonschema.generator.OptionPreset;
import com.github.victools.jsonschema.generator.SchemaGenerator;
import com.github.victools.jsonschema.generator.SchemaGeneratorConfig;
import com.github.victools.jsonschema.generator.SchemaGeneratorConfigBuilder;
import com.github.victools.jsonschema.generator.SchemaVersion;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
public class Main {
public class GetWeatherTool {
private String location;
public GetWeatherTool(String location) {
this.location = location;
}
public String call() {
return location+"今天是晴天";
}
}
public class GetTimeTool {
public GetTimeTool() {
}
public String call() {
LocalDateTime now = LocalDateTime.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String currentTime = "当前时间:" + now.format(formatter) + "。";
return currentTime;
}
}
public static void SelectTool()
throws NoApiKeyException, ApiException, InputRequiredException {
SchemaGeneratorConfigBuilder configBuilder =
new SchemaGeneratorConfigBuilder(SchemaVersion.DRAFT_2020_12, OptionPreset.PLAIN_JSON);
SchemaGeneratorConfig config = configBuilder.with(Option.EXTRA_OPEN_API_FORMAT_VALUES)
.without(Option.FLATTENED_ENUMS_FROM_TOSTRING).build();
SchemaGenerator generator = new SchemaGenerator(config);
ObjectNode jsonSchema_weather = generator.generateSchema(GetWeatherTool.class);
ObjectNode jsonSchema_time = generator.generateSchema(GetTimeTool.class);
FunctionDefinition fdWeather = FunctionDefinition.builder().name("get_current_weather").description("获取指定地区的天气")
.parameters(JsonUtils.parseString(jsonSchema_weather.toString()).getAsJsonObject()).build();
FunctionDefinition fdTime = FunctionDefinition.builder().name("get_current_time").description("获取当前时刻的时间")
.parameters(JsonUtils.parseString(jsonSchema_time.toString()).getAsJsonObject()).build();
Message systemMsg = Message.builder().role(Role.SYSTEM.getValue())
.content("You are a helpful assistant. When asked a question, use tools wherever possible.")
.build();
Message userMsg = Message.builder().role(Role.USER.getValue()).content("杭州天气").build();
List
messages.addAll(Arrays.asList(systemMsg, userMsg));
GenerationParam param = GenerationParam.builder()
// 若没有配置环境变量,请用百炼API Key将下行替换为:.apiKey("sk-xxx")
.apiKey(System.getenv("DASHSCOPE_API_KEY"))
// 此处以qwen-plus为例,可按需更换模型名称。模型列表:https://help.aliyun.com/zh/model-studio/getting-started/models
.model("qwen-plus")
.messages(messages)
.resultFormat(ResultFormat.MESSAGE)
.tools(Arrays.asList(
ToolFunction.builder().function(fdWeather).build(),
ToolFunction.builder().function(fdTime).build()))
.build();
Generation gen = new Generation();
GenerationResult result = gen.call(param);
System.out.println(JsonUtils.toJson(result));
}
public static void main(String[] args) {
try {
SelectTool();
} catch (ApiException | NoApiKeyException | InputRequiredException e) {
System.out.println(String.format("Exception %s", e.getMessage()));
}
System.exit(0);
}
}
curlcurl --location "https://dashscope.aliyuncs.com/api/v1/services/aigc/text-generation/generation" \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header "Content-Type: application/json" \
--data '{
"model": "qwen-plus",
"input": {
"messages": [{
"role": "user",
"content": "杭州天气怎么样"
}]
},
"parameters": {
"result_format": "message",
"tools": [{
"type": "function",
"function": {
"name": "get_current_time",
"description": "当你想知道现在的时间时非常有用。",
"parameters": {}
}
},{
"type": "function",
"function": {
"name": "get_current_weather",
"description": "当你想查询指定城市的天气时非常有用。",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "城市或县区,比如北京市、杭州市、余杭区等。"
}
}
},
"required": ["location"]
}
}]
}
}'异步调用# 您的Dashscope Python SDK版本需要不低于 1.19.0。
import asyncio
import platform
import os
from dashscope.aigc.generation import AioGeneration
async def main():
response = await AioGeneration.call(
# 若没有配置环境变量,请用百炼API Key将下行替换为:api_key="sk-xxx"
api_key=os.getenv('DASHSCOPE_API_KEY'),
model="qwen-plus", # 此处以qwen-plus为例,可按需更换模型名称。模型列表:https://help.aliyun.com/zh/model-studio/getting-started/models
messages=[{"role": "user", "content": "你是谁"}],
result_format="message",
)
print(response)
if platform.system() == "Windows":
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
asyncio.run(main())文档理解Pythonimport os
import dashscope
messages = [
{'role': 'system', 'content': 'you are a helpful assisstant'},
# 请将 '{FILE_ID}'替换为您实际对话场景所使用的 fileid
{'role':'system','content':f'fileid://{FILE_ID}'},
{'role': 'user', 'content': '这篇文章讲了什么'}]
response = dashscope.Generation.call(
# 若没有配置环境变量,请用百炼API Key将下行替换为:api_key="sk-xxx"
api_key=os.getenv('DASHSCOPE_API_KEY'),
model="qwen-long",
messages=messages,
result_format='message'
)
print(response)
Javaimport java.util.Arrays;
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 com.alibaba.dashscope.utils.JsonUtils;
public class Main {
public static GenerationResult callWithFile() throws ApiException, NoApiKeyException, InputRequiredException {
Generation gen = new Generation();
Message systemMsg = Message.builder()
.role(Role.SYSTEM.getValue())
.content("you are a helpful assistant")
.build();
Message fileSystemMsg = Message.builder()
.role(Role.SYSTEM.getValue())
// 请将 '{FILE_ID}'替换为您实际对话场景所使用的 file-id
.content("fileid://{FILE_ID}")
.build();
Message userMsg = Message.builder()
.role(Role.USER.getValue())
.content("这篇文章讲了什么")
.build();
GenerationParam param = GenerationParam.builder()
// 若没有配置环境变量,请用百炼API Key将下行替换为:.apiKey("sk-xxx")
.apiKey(System.getenv("DASHSCOPE_API_KEY"))
.model("qwen-long")
.messages(Arrays.asList(systemMsg, fileSystemMsg, userMsg))
.resultFormat(GenerationParam.ResultFormat.MESSAGE)
.build();
return gen.call(param);
}
public static void main(String[] args) {
try {
GenerationResult result = callWithFile();
System.out.println(JsonUtils.toJson(result));
} catch (ApiException | NoApiKeyException | InputRequiredException e) {
System.err.println("调用 DashScope API 出错: " + e.getMessage());
e.printStackTrace();
}
}
}
curl请将 {FILE_ID}替换为您实际对话场景所使用的 file-idcurl --location "https://dashscope.aliyuncs.com/api/v1/services/aigc/text-generation/generation" \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header "Content-Type: application/json" \
--data '{
"model": "qwen-long",
"input":{
"messages":[
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "system",
"content": "fileid://{FILE_ID}"
},
{
"role": "user",
"content": "这篇文章讲了什么?"
}
]
},
"parameters": {
"result_format": "message"
}
}'
model string (必选)
模型名称。
支持的模型:Qwen 大语言模型(商业版、开源版)、Qwen-VL、Qwen-Coder、通义千问Audio、数学模型。
具体模型名称和计费,请参见文本生成-通义千问。
messages array (必选)
传递给大模型的上下文,按对话顺序排列。
通过HTTP调用时,请将messages 放入 input 对象中。消息类型
System Message object(可选)
系统消息,用于设定大模型的角色、语气、任务目标或约束条件等。一般放在messages数组的第一位。
QwQ模型不建议设置 System Message,QVQ 模型设置 System Message不会生效。属性
content string(必选)
消息内容。
role string (必选)
系统消息的角色,固定为system。
User Message object(必选)
用户消息,用于向模型传递问题、指令或上下文等。
属性
content string 或 array(必选)
消息内容。若输入只有文本,则为 string 类型;若输入包含图像等多模态数据,或启用显式缓存,则为 array 类型。
属性
text string(必选)
输入的文本。
image string(可选)
指定用于图片理解的图像文件,图像支持以下三种方式传入:
公网 URL:公网可访问的图像链接
图片的 Base64 编码,格式为 data:image/
本地文件:本地文件的绝对路径
适用模型:Qwen-VL、QVQ
示例值:{"image":"https://xxxx.jpeg"}
video array 或 string(可选)
使用Qwen-VL 模型或QVQ模型传入的视频。
若传入图像列表,则为array类型;
若传入视频文件,则为string类型。
传入本地文件请参见本地文件(Qwen-VL)或本地文件(QVQ)。
示例值:
图像列表:{"video":["https://xx1.jpg",...,"https://xxn.jpg"]}
视频文件:{"video":"https://xxx.mp4"}
fps float (可选)
每秒抽帧数。取值范围为 [0.1, 10],默认值为2.0。
功能说明
fps有两个功能:
输入视频文件时,控制抽帧频率,每 fps1秒抽取一帧。
适用于Qwen-VL 模型与QVQ模型。告知模型相邻帧之间的时间间隔,帮助其更好地理解视频的时间动态。同时适用于输入视频文件与图像列表时。该功能同时支持视频文件和图像列表输入,适用于事件时间定位或分段内容摘要等场景。
支持Qwen2.5-VL、Qwen3-VL模型与QVQ模型。较大的fps适合高速运动的场景(如体育赛事、动作电影等),较小的fps适合长视频或内容偏静态的场景。
示例值
图像列表传入:{"video":["https://xx1.jpg",...,"https://xxn.jpg"],"fps":2}
视频文件传入:{"video": "https://xx1.mp4","fps":2}
min_pixels integer (可选)
设定输入图像或视频帧的最小像素阈值。当输入图像或视频帧的像素小于min_pixels时,会将其进行放大,直到总像素高于min_pixels。
取值范围
输入图像:
Qwen3-VL:默认值和最小值均为:65536
qwen-vl-max、qwen-vl-max-latest、qwen-vl-max-0813、qwen-vl-plus、qwen-vl-plus-latest、qwen-vl-plus-0815、qwen-vl-plus-0710:默认值和最小值均为4096
其他qwen-vl-plus模型、其他qwen-vl-max模型、Qwen2.5-VL开源系列及QVQ系列模型:默认值和最小值均为3136
输入视频文件或图像列表:
Qwen3-VL(包括商业版和开源版)、qwen-vl-max、qwen-vl-max-latest、qwen-vl-max-0813、qwen-vl-plus、qwen-vl-plus-latest、qwen-vl-plus-0815、qwen-vl-plus-0710:默认值为65536,最小值为4096
其他qwen-vl-plus模型、其他qwen-vl-max模型、Qwen2.5-VL开源系列及QVQ系列模型:默认值为50176,最小值为3136
示例值
输入图像:{"type": "image_url","image_url": {"url":"https://xxxx.jpg"},"min_pixels": 65536}
输入视频文件时:{"type": "video_url","video_url": {"url":"https://xxxx.mp4"},"min_pixels": 65536}
输入图像列表时:{"type": "video","video": ["https://xx1.jpg",...,"https://xxn.jpg"],"min_pixels": 65536}
max_pixels integer (可选)
用于设定输入图像或视频帧的最大像素阈值。当输入图像或视频的像素在[min_pixels, max_pixels]区间内时,模型会按原图进行识别。当输入图像像素大于max_pixels时,会将图像进行缩小,直到总像素低于max_pixels。
取值范围
输入图像:
max_pixels 的取值与是否开启vl_high_resolution_images参数有关。
当vl_high_resolution_images为False时:
Qwen3-VL:默认值为2621440,最大值为:16777216
qwen-vl-max、qwen-vl-max-latest、qwen-vl-max-0813、qwen-vl-plus、qwen-vl-plus-latest、qwen-vl-plus-0815、qwen-vl-plus-0710:默认值为1310720,最大值为:16777216
其他qwen-vl-plus模型、其他qwen-vl-max模型、Qwen2.5-VL开源系列及QVQ系列模型:默认值为1003520 ,最大值为12845056
当vl_high_resolution_images为True时:
Qwen3-VL、qwen-vl-max、qwen-vl-max-latest、qwen-vl-max-0813、qwen-vl-plus、qwen-vl-plus-latest、qwen-vl-plus-0815、qwen-vl-plus-0710:max_pixels无效,输入图像的最大像素固定为16777216
其他qwen-vl-plus模型、其他qwen-vl-max模型、Qwen2.5-VL开源系列及QVQ系列模型:max_pixels无效,输入图像的最大像素固定为12845056
输入视频文件或图像列表:
qwen3-vl-plus系列、qwen3-vl-flash系列、qwen3-vl-235b-a22b-thinking、qwen3-vl-235b-a22b-instruct:默认值为655360,最大值为2048000
其他Qwen3-VL开源模型、qwen-vl-max、qwen-vl-max-latest、qwen-vl-max-0813、qwen-vl-plus、qwen-vl-plus-latest、qwen-vl-plus-0815、qwen-vl-plus-0710:默认值655360,最大值为786432
其他qwen-vl-plus模型、其他qwen-vl-max模型、Qwen2.5-VL开源系列及QVQ系列模型:默认值为501760,最大值为602112
示例值
输入图像:{"type": "image_url","image_url": {"url":"https://xxxx.jpg"},"max_pixels": 8388608}
输入视频文件时:{"type": "video_url","video_url": {"url":"https://xxxx.mp4"},"max_pixels": 655360}
输入图像列表时:{"type": "video","video": ["https://xx1.jpg",...,"https://xxn.jpg"],"max_pixels": 655360}
total_pixels integer (可选)
用于限制从视频中抽取的所有帧的总像素(单帧图像像素 × 总帧数)。如果视频总像素超过此限制,系统将对视频帧进行缩放,但仍会确保单帧图像的像素值在[min_pixels, max_pixels]范围内。适用于 Qwen-VL、QVQ 模型。
对于抽帧数量较多的长视频,可适当降低此值以减少Token消耗和处理时间,但这可能会导致图像细节丢失。
取值范围
qwen3-vl-plus系列、qwen3-vl-flash系列、qwen3-vl-235b-a22b-thinking、qwen3-vl-235b-a22b-instruct:默认值和最小值均为134217728,该值对应 131072 个图像 Token(每 32×32 像素对应 1 个图像 Token)。
其他Qwen3-VL开源模型、qwen-vl-max、qwen-vl-max-latest、qwen-vl-max-0813、qwen-vl-plus、qwen-vl-plus-latest、qwen-vl-plus-0815、qwen-vl-plus-0710:默认值和最小值均为67108864,该值对应 65536 个图像 Token(每 32×32 像素对应 1 个图像 Token)。
其他qwen-vl-plus模型、其他qwen-vl-max模型、Qwen2.5-VL开源系列及QVQ系列模型:默认值和最小值均为51380224,该值对应 65536 个图像 Token(每 28×28 像素对应 1 个图像 Token)。
示例值
输入视频文件时:{"type": "video_url","video_url": {"url":"https://xxxx.mp4"},"total_pixels": 134217728}
输入图像列表时:{"type": "video","video": ["https://xx1.jpg",...,"https://xxn.jpg"],"total_pixels": 134217728}
audio string
模型为音频理解时,是必选参数,如模型为qwen2-audio-instruct等。使用音频理解功能时,传入的音频文件。
示例值:{"audio":"https://xxx.mp3"}
cache_control object (可选)
仅支持显式缓存的模型支持,用于开启显式缓存。
属性
type string(必选)
固定为ephemeral。
role string (必选)
用户消息的角色,固定为user。
Assistant Message object (可选)
模型对用户消息的回复。
属性
content string (可选)
消息内容。仅当助手消息中指定tool_calls参数时非必选。
role string (必选)
固定为assistant。
partial boolean (可选)
是否开启前缀续写。相关文档:前缀续写。
支持的模型
通义千问Max 系列
qwen3-max、qwen3-max-2025-09-23、qwen3-max-preview(非思考模式)、qwen-max、qwen-max-latest、qwen-max-2024-09-19及之后的快照模型
通义千问Plus 系列(非思考模式)
qwen-plus、qwen-plus-latest、qwen-plus-2024-09-19及之后的快照模型
通义千问Flash 系列(非思考模式)
qwen-flash、qwen-flash-2025-07-28及之后的快照模型
通义千问Coder 系列
qwen3-coder-plus、qwen3-coder-flash、qwen3-coder-480b-a35b-instruct、qwen3-coder-30b-a3b-instruct、qwen-coder-plus、qwen-coder-plus-latest、qwen-coder-plus-2024-11-06、qwen-coder-turbo、qwen-coder-turbo-latest、qwen-coder-turbo-2024-09-19、qwen2.5-coder-32b-instruct、qwen2.5-coder-14b-instruct、qwen2.5-coder-7b-instruct、qwen2.5-coder-3b-instruct、qwen2.5-coder-1.5b-instruct、qwen2.5-coder-0.5b-instruct
通义千问VL 系列
qwen3-vl-plus 系列(非思考模式)
qwen3-vl-plus、qwen3-vl-plus-2025-09-23及之后的快照模型
qwen3-vl-flash 系列(非思考模式)
qwen3-vl-flash、qwen3-vl-flash-2025-10-15及之后的快照模型
qwen-vl-max 系列
qwen-vl-max、qwen-vl-max-latest、qwen-vl-max-2024-08-09及之后的快照模型
qwen-vl-plus 系列
qwen-vl-plus、qwen-vl-plus-latest、qwen-vl-plus-2024-08-09及之后的快照模型
通义千问Turbo 系列(非思考模式)
qwen-turbo、qwen-turbo-latest、qwen-turbo-2024-09-19及之后的快照模型
通义千问开源系列
Qwen3 开源模型(非思考模式)、qwen2.5-72b-instruct、qwen2.5-32b-instruct、qwen2.5-14b-instruct、qwen2.5-7b-instruct、qwen2.5-3b-instruct、qwen2.5-1.5b-instruct、qwen2.5-0.5b-instruct、Qwen3-VL开源模型(非思考模式)
通义千问Math 系列
qwen-math-plus、qwen-math-plus-latest、qwen-math-plus-0919、qwen-math-turbo、qwen-math-turbo-latest、qwen-math-turbo-0919、qwen2.5-math-72b-instruct、qwen2.5-math-7b-instruct、qwen2.5-math-1.5b-instruct
tool_calls array (可选)
发起 Function Calling 后,返回的工具与入参信息,包含一个或多个对象。由上一轮模型响应的tool_calls字段获得。
属性
id string
工具响应的ID。
type string
工具类型,当前只支持设为function。
function object
工具与入参信息。
属性
name string
工具名称。
arguments string
入参信息,为JSON格式字符串。
index integer
当前工具信息在tool_calls数组中的索引。
Tool Message object(可选)
工具的输出信息。
属性
content string (必选)
工具函数的输出内容,必须为字符串格式。
role string (必选)
固定为tool。
tool_call_id string (可选)
发起 Function Calling 后返回的 id,可以通过response.output.choices[0].message.tool_calls[$index]["id"]获取,用于标记 Tool Message 对应的工具。
temperature float (可选)
采样温度,控制模型生成文本的多样性。
temperature越高,生成的文本更多样,反之,生成的文本更确定。
取值范围: [0, 2)
temperature默认值
Qwen3(非思考模式)、Qwen3-Instruct系列、Qwen3-Coder系列、qwen-max系列、qwen-plus系列(非思考模式)、qwen-flash系列(非思考模式)、qwen-turbo系列(非思考模式)、qwen开源系列、qwen-coder系列、qwen2-audio-instruct、qwen-doc-turbo、qwen-vl-max-2025-08-13、Qwen3-VL(非思考):0.7;
QVQ系列 、qwen-vl-plus-2025-07-10、qwen-vl-plus-2025-08-15 : 0.5;
qwen-audio-turbo系列:0.00001;
qwen-vl系列、qwen2.5-omni-7b、qvq-72b-preview:0.01;
qwen-math系列:0;
Qwen3(思考模式)、Qwen3-Thinking、Qwen3-Omni-Captioner、QwQ 系列:0.6;
qwen3-max-preview(思考模式)、qwen-long系列: 1.0;
qwen-plus-character:0.92
qwen3-omni-flash系列:0.9
Qwen3-VL(思考模式):0.8
通过HTTP调用时,请将 temperature 放入 parameters 对象中。不建议修改QVQ模型的默认 temperature 值。top_p float (可选)
核采样的概率阈值,控制模型生成文本的多样性。
top_p越高,生成的文本更多样。反之,生成的文本更确定。
取值范围:(0,1.0]。
top_p默认值
Qwen3(非思考模式)、Qwen3-Instruct系列、Qwen3-Coder系列、qwen-max系列、qwen-plus系列(非思考模式)、qwen-flash系列(非思考模式)、qwen-turbo系列(非思考模式)、qwen开源系列、qwen-coder系列、qwen-long、qwen-doc-turbo、qwq-32b-preview、qwen-audio-turbo系列、qwen-vl-max-2025-08-13、Qwen3-VL(非思考模式):0.8;
qwen-vl-max-2024-11-19、qwen-vl-max-2024-10-30、qwen-vl-max-2024-08-09、qwen2-vl-72b-instruct、qwen-omni-turbo 系列:0.01;
qwen-vl-plus系列、qwen-vl-max、qwen-vl-max-latest、qwen-vl-max-2025-04-08、qwen-vl-max-2025-04-02、qwen-vl-max-2025-01-25、qwen-vl-max-2024-12-30、qvq-72b-preview、qwen2-vl-2b-instruct、qwen2-vl-7b-instruct、qwen2.5-vl-3b-instruct、qwen2.5-vl-7b-instruct、qwen2.5-vl-32b-instruct、qwen2.5-vl-72b-instruct:0.001;
QVQ系列、qwen-vl-plus-2025-07-10、qwen-vl-plus-2025-08-15 、qwen2-audio-instruct:0.5;
qwen3-max-preview(思考模式)、qwen-math系列、Qwen3-Omni-Flash系列:1.0;
Qwen3(思考模式)、Qwen3-VL(思考模式)、Qwen3-Thinking、QwQ 系列、Qwen3-Omni-Captioner、qwen-plus-character:0.95
Java SDK中为topP。通过HTTP调用时,请将 top_p 放入 parameters 对象中。不建议修改QVQ模型的默认 top_p 值。top_k integer (可选)
生成过程中采样候选集的大小。例如,取值为50时,仅将单次生成中得分最高的50个Token组成随机采样的候选集。取值越大,生成的随机性越高;取值越小,生成的确定性越高。取值为None或当top_k大于100时,表示不启用top_k策略,此时仅有top_p策略生效。
取值需要大于或等于0。
top_k默认值
QVQ系列、qwen-vl-plus-2025-07-10、qwen-vl-plus-2025-08-15:10;
QwQ 系列:40;
qwen-math 系列、其余qwen-vl-plus系列、qwen-vl-max-2025-08-13之前的模型、qwen-audio-turbo系列、qwen2.5-omni-7b、qvq-72b-preview:1;
Qwen3-Omni-Flash系列:50
其余模型均为20;
Java SDK中为topK。通过HTTP调用时,请将 top_k 放入 parameters 对象中。不建议修改QVQ模型的默认 top_k 值。enable_thinking boolean (可选)
使用混合思考模型时,是否开启思考模式,适用于 Qwen3 、Qwen3-VL模型。相关文档:深度思考
可选值:
true:开启
开启后,思考内容将通过reasoning_content字段返回。false:不开启
不同模型的默认值:支持的模型
Java SDK 为enableThinking;通过HTTP调用时,请将 enable_thinking 放入 parameters 对象中。thinking_budget integer (可选)
思考过程的最大长度。适用于Qwen3-VL、Qwen3 的商业版与开源版模型。相关文档:限制思考长度。
默认值为模型最大思维链长度,请参见:模型列表
Java SDK 为 thinkingBudget。通过HTTP调用时,请将 thinking_budget 放入 parameters 对象中。默认值为模型最大思维链长度。enable_code_interpreter boolean (可选)默认值为 false
是否开启代码解释器功能。仅适用于思考模式下的 qwen3-max-preview。相关文档:代码解释器
可选值:
true:开启
false:不开启
不支持 Java SDK。通过HTTP调用时,请将 enable_code_interpreter 放入 parameters 对象中。repetition_penalty float (可选)
模型生成时连续序列中的重复度。提高repetition_penalty时可以降低模型生成的重复度,1.0表示不做惩罚。没有严格的取值范围,只要大于0即可。
repetition_penalty默认值
qwen-max、qwen-max-latest、qwen-max-2024-09-19、qwen-math系列、qwen-vl-max系列、qvq-72b-preview、qwen2-vl-72b-instruct、qwen-vl-plus-2025-01-02、qwen-vl-plus-2025-05-07、qwen-vl-plus-2025-07-10、qwen-vl-plus-2025-08-15、qwen-vl-plus-latest、qwen2.5-vl-3b-instruct、qwen2.5-vl-7b-instruct、qwen2.5-vl-32b-instruct、qwen2.5-vl-72b-instruct、qwen-audio-turbo-latest、qwen-audio-turbo-2024-12-04、QVQ系列、QwQ系列、qwq-32b-preview、Qwen3-VL: 1.0;
qwen-coder系列、qwen2.5-1.5b-instruct、qwen2.5-0.5b-instruct、qwen2-1.5b-instruct、qwen2-0.5b-instruct、qwen2-vl-2b-instruct、qwen2-vl-7b-instruct、qwen-vl-plus-2024-08-09、qwen-vl-plus-2023-12-01、qwen2.5-omni-7b、qwen2-audio-instruct:1.1;
qwen-vl-plus、qwen-vl-plus-2025-01-25:1.2;
其余模型为1.05。
Java SDK中为repetitionPenalty。通过HTTP调用时,请将 repetition_penalty 放入 parameters 对象中。使用qwen-vl-plus_2025-01-25模型进行文字提取时,建议设置repetition_penalty为1.0。不建议修改QVQ模型的默认 repetition_penalty 值。presence_penalty float (可选)
控制模型生成文本时的内容重复度。
取值范围:[-2.0, 2.0]。正值降低重复度,负值增加重复度。
在创意写作或头脑风暴等需要多样性、趣味性或创造力的场景中,建议调高该值;在技术文档或正式文本等强调一致性与术语准确性的场景中,建议调低该值。
presence_penalty默认值
qwen3-max-preview(思考模式)、Qwen3(非思考模式)、Qwen3-Instruct系列、qwen3-0.6b/1.7b/4b(思考模式)、QVQ系列、qwen-max、qwen-max-latest、qwen-max-latest、qwen-max-2024-09-19、qwen2.5-vl系列、qwen-vl-max系列、qwen-vl-plus、qwen2-vl-72b-instruct、qwen-vl-plus-2025-01-02、Qwen3-VL(非思考):1.5;
qwen-vl-plus-latest、qwen-vl-plus-2025-08-15、qwen-vl-plus-2025-07-10:1.2
qwen-vl-plus-2025-01-25:1.0;
qwen3-8b/14b/32b/30b-a3b/235b-a22b(思考模式)、qwen-plus/qwen-plus-latest/2025-04-28(思考模式)、qwen-turbo/qwen-turbo/2025-04-28(思考模式):0.5;
其余均为0.0。
原理介绍
如果参数值是正数,模型将对目前文本中已存在的Token施加一个惩罚值(惩罚值与文本出现的次数无关),减少这些Token重复出现的几率,从而减少内容重复度,增加用词多样性。
示例
提示词:把这句话翻译成中文“This movie is good. The plot is good, the acting is good, the music is good, and overall, the whole movie is just good. It is really good, in fact. The plot is so good, and the acting is so good, and the music is so good.”
参数值为2.0:这部电影很好。剧情很棒,演技棒,音乐也非常好听,总的来说,整部电影都好得不得了。实际上它真的很优秀。剧情非常精彩,演技出色,音乐也是那么的动听。
参数值为0.0:这部电影很好。剧情好,演技好,音乐也好,总的来说,整部电影都很好。事实上,它真的很棒。剧情非常好,演技也非常出色,音乐也同样优秀。
参数值为-2.0:这部电影很好。情节很好,演技很好,音乐也很好,总的来说,整部电影都很好。实际上,它真的很棒。情节非常好,演技也非常好,音乐也非常好。
使用qwen-vl-plus-2025-01-25模型进行文字提取时,建议设置presence_penalty为1.5。不建议修改QVQ模型的默认presence_penalty值。Java SDK不支持设置该参数。通过HTTP调用时,请将 presence_penalty 放入 parameters 对象中。vl_high_resolution_images boolean (可选)默认值为false
是否将输入图像的像素上限提升至 16384 Token 对应的像素值。相关文档:处理高分辨率图像。
vl_high_resolution_images:true,使用固定分辨率策略,忽略 max_pixels 设置,超过此分辨率时会将图像总像素缩小至此上限内。
点击查看各模型像素上限
vl_high_resolution_images为True时,不同模型像素上限不同:
Qwen3-VL系列、qwen-vl-max、qwen-vl-max-latest、qwen-vl-max-0813、qwen-vl-plus、qwen-vl-plus-latest、qwen-vl-plus-0815、qwen-vl-plus-0710模型:16777216(每Token对应32*32像素,即16384*32*32)
QVQ系列、其他Qwen2.5-VL系列模型:12845056(每Token对应28*28像素,即 16384*28*28)
vl_high_resolution_images为false,像素上限由 max_pixels 决定,输入图像的像素超过max_pixels会将图像缩小至max_pixels内。各模型的默认像素上限即max_pixels的默认值。
Java SDK 为 vlHighResolutionImages(需要的最低版本为2.20.8)。通过HTTP调用时,请将 vl_high_resolution_images 放入 parameters 对象中。vl_enable_image_hw_output boolean (可选)默认值为 false
是否返回图像缩放后的尺寸。模型会对输入的图像进行缩放处理,配置为 True 时会返回图像缩放后的高度和宽度,开启流式输出时,该信息在最后一个数据块(chunk)中返回。支持Qwen-VL模型。
Java SDK中为 vlEnableImageHwOutput,Java SDK最低版本为2.20.8。通过HTTP调用时,请将 vl_enable_image_hw_output 放入 parameters 对象中。max_tokens integer (可选)
用于限制模型输出的最大 Token 数。若生成内容超过此值,生成将提前停止,且返回的finish_reason为length。
默认值与最大值均为模型的最大输出长度,请参见文本生成-通义千问。
适用于需控制输出长度的场景,如生成摘要、关键词,或用于降低成本、缩短响应时间。
触发 max_tokens 时,响应的 finish_reason 字段为 length。
max_tokens不限制思考模型思维链的长度。Java SDK中为maxTokens(模型为通义千问VL/Audio时,Java SDK中为maxLength,在 2.18.4 版本之后支持也设置为 maxTokens)。通过HTTP调用时,请将 max_tokens 放入 parameters 对象中。seed integer (可选)
随机数种子。用于确保在相同输入和参数下生成结果可复现。若调用时传入相同的 seed 且其他参数不变,模型将尽可能返回相同结果。
取值范围:[0,231−1]。
seed默认值
qwen-vl-plus-2025-01-02、qwen-vl-max、qwen-vl-max-latest、qwen-vl-max-2025-04-08、qwen-vl-max-2025-04-02、qwen-vl-max-2024-12-30、qvq-72b-preview、qvq-max系列:3407;
qwen-vl-max-2025-01-25、qwen-vl-max-2024-11-19、qwen-vl-max-2024-10-30、qwen-vl-max-2024-08-09、qwen-vl-max-2024-02-01、qwen2-vl-72b-instruct、qwen2-vl-2b-instruct、qwen-vl-plus、qwen-vl-plus-latest、qwen-vl-plus-2025-05-07、qwen-vl-plus-2025-01-25、qwen-vl-plus-2024-08-09、qwen-vl-plus-2023-12-01:无默认值;
其余模型均为1234。
通过HTTP调用时,请将 seed 放入 parameters 对象中。stream boolean (可选) 默认值为false
是否流式输出回复。参数值:
false:模型生成完所有内容后一次性返回结果。
true:边生成边输出,即每生成一部分内容就立即输出一个片段(chunk)。
该参数仅支持Python SDK。通过Java SDK实现流式输出请通过streamCall接口调用;通过HTTP实现流式输出请在Header中指定X-DashScope-SSE为enable。Qwen3商业版(思考模式)、Qwen3开源版、QwQ、QVQ只支持流式输出。 incremental_output boolean (可选)默认为false(Qwen3-Max、Qwen3-VL、Qwen3 开源版、QwQ 、QVQ模型默认值为 true)
在流式输出模式下是否开启增量输出。推荐您优先设置为true。
参数值:
false:每次输出为当前已经生成的整个序列,最后一次输出为生成的完整结果。
I
I like
I like apple
I like apple.true(推荐):增量输出,即后续输出内容不包含已输出的内容。您需要实时地逐个读取这些片段以获得完整的结果。
I
like
apple
.Java SDK中为incrementalOutput。通过HTTP调用时,请将 incremental_output 放入 parameters 对象中。QwQ 模型与思考模式下的 Qwen3 模型只支持设置为 true。由于 Qwen3 商业版模型默认值为false,您需要在思考模式下手动设置为 true。Qwen3 开源版模型不支持设置为 false。response_format object (可选) 默认值为{"type": "text"}
返回内容的格式。可选值:
{"type": "text"}:输出文字回复;
{"type": "json_object"}:输出标准格式的JSON字符串。
{"type": "json_schema","json_schema": {...} }:输出指定格式的JSON字符串。
相关文档:结构化输出。支持的模型参见支持的模型。若指定为{"type": "json_object"},需在提示词中明确指示模型输出JSON,如:“请按照json格式输出”,否则会报错。Java SDK中为responseFormat。通过HTTP调用时,请将 response_format 放入 parameters 对象中。属性
type string (必选)
返回内容的格式。可选值:
text:输出文字回复;
json_object:输出标准格式的JSON字符串;
json_schema:输出指定格式的JSON字符串。
json_schema object
当 type 为 json_schema 时,该字段为必选,用于定义结构化输出的配置。
属性
name string (必选)
Schema 的唯一标识名称。仅支持字母(不区分大小写)、数字、下划线和短横线,最长 64 个字符。
description string (可选)
描述 Schema 的用途,帮助模型理解输出的语义上下文。
schema object (可选)
符合 JSON Schema 标准的对象,定义模型输出的数据结构。
构建JSON Schema 方法参加:JSON Schemastrict boolean (可选)默认值为false
控制是否强制模型严格遵守 Schema 的所有约束。
true(推荐)
模型严格遵循字段类型、必填项、格式等所有约束,确保输出 100% 合规。
false(不推荐)
模型仅大致遵循 Schema,可能生成不符合规范的输出,导致验证失败。
result_format string (可选) 默认为text(Qwen3-Max、Qwen3-VL、QwQ 模型、Qwen3 开源模型(除了qwen3-next-80b-a3b-instruct)与 Qwen-Long 模型默认值为 message)
返回数据的格式。推荐您优先设置为message,可以更方便地进行多轮对话。
平台后续将统一调整默认值为message。Java SDK中为resultFormat。通过HTTP调用时,请将 result_format 放入 parameters 对象中。模型为通义千问VL/QVQ/Audio时,设置text不生效。Qwen3-Max、Qwen3-VL、思考模式下的 Qwen3 模型只能设置为message,由于 Qwen3 商业版模型默认值为text,您需要将其设置为message。如果您使用 Java SDK 调用Qwen3 开源模型,并且传入了 text,依然会以 message格式进行返回。logprobs boolean (可选)默认值为 false
是否返回输出 Token 的对数概率,可选值:
true
返回
false
不返回
支持以下模型:
qwen-plus系列的快照模型(不包含主线模型)
qwen-turbo 系列的快照模型(不包含主线模型)
Qwen3 开源模型
通过HTTP调用时,请将 logprobs 放入 parameters 对象中。top_logprobs integer (可选)默认值为0
指定在每一步生成时,返回模型最大概率的候选 Token 个数。
取值范围:[0,5]
仅当 logprobs 为 true 时生效。
Java SDK中为topLogprobs。通过HTTP调用时,请将 top_logprobs 放入 parameters 对象中。n integer (可选) 默认值为1
生成响应的个数,取值范围是1-4。对于需要生成多个响应的场景(如创意写作、广告文案等),可以设置较大的 n 值。
当前仅支持 qwen-plus、 Qwen3(非思考模式)、qwen-plus-character 模型,且在传入 tools 参数时固定为1。设置较大的 n 值不会增加输入 Token 消耗,会增加输出 Token 的消耗。通过HTTP调用时,请将 n 放入 parameters 对象中。stop string 或 array (可选)
用于指定停止词。当模型生成的文本中出现stop 指定的字符串或token_id时,生成将立即终止。
可传入敏感词以控制模型的输出。
stop为数组时,不可将token_id和字符串同时作为元素输入,比如不可以指定为["你好",104307]。通过HTTP调用时,请将 stop 放入 parameters 对象中。tools array (可选)
包含一个或多个工具对象的数组,供模型在 Function Calling 中调用。相关文档:Function Calling
使用 tools 时,必须将result_format设为message。
发起 Function Calling,或提交工具执行结果时,都必须设置tools参数。
属性
type string (必选)
工具类型,当前仅支持function。
function object (必选)
属性
name string (必选)
工具函数的名称,必须是字母、数字,可以包含下划线和短划线,最大长度为64。
description string (必选)
工具函数的描述,供模型选择何时以及如何调用工具函数。
parameters object (可选)默认值为 {}
工具的参数描述,需要是一个合法的JSON Schema。JSON Schema的描述可以见链接。若parameters参数为空,表示该工具没有入参(如时间查询工具)。
为提高工具调用的准确性,建议传入 parameters。通过HTTP调用时,请将 tools 放入 parameters 对象中。暂时不支持qwen-vl与qwen-audio系列模型。tool_choice string 或 object (可选)默认值为 auto
工具选择策略。若需对某类问题强制指定工具调用方式(例如始终使用某工具或禁用所有工具),可设置此参数。
auto
大模型自主选择工具策略;
none
若在特定请求中希望临时禁用工具调用,可设定tool_choice参数为none;
{"type": "function", "function": {"name": "the_function_to_call"}}
若希望强制调用某个工具,可设定tool_choice参数为{"type": "function", "function": {"name": "the_function_to_call"}},其中the_function_to_call是指定的工具函数名称。
思考模式的模型不支持强制调用某个工具。Java SDK中为toolChoice。通过HTTP调用时,请将 tool_choice 放入 parameters 对象中。parallel_tool_calls boolean (可选)默认值为 false
是否开启并行工具调用。
可选值:
true:开启
false:不开启。
并行工具调用详情请参见:并行工具调用。
Java SDK中为parallelToolCalls。通过HTTP调用时,请将 parallel_tool_calls 放入 parameters 对象中。enable_search boolean (可选) 默认值为false
模型在生成文本时是否使用互联网搜索结果进行参考。取值如下:
true:启用互联网搜索,模型会将搜索结果作为文本生成过程中的参考信息,但模型会基于其内部逻辑判断是否使用互联网搜索结果。
若开启后未联网搜索,可优化提示词,或设置search_options中的forced_search参数开启强制搜索。false:关闭互联网搜索。
计费信息请参见计费说明。
Java SDK中为enableSearch。通过HTTP调用时,请将 enable_search 放入 parameters 对象中。启用互联网搜索功能可能会增加 Token 的消耗。search_options object (可选)
联网搜索的策略。仅当enable_search为true时生效。详情参见联网搜索。
通过HTTP调用时,请将 search_options 放入 parameters 对象中。Java SDK中为searchOptions。属性
enable_source boolean(可选)默认值为false
在返回结果中是否展示搜索到的信息。参数值:
true:展示;
false:不展示。
enable_citation boolean(可选)默认值为false
是否开启[1]或[ref_1]样式的角标标注功能。在enable_source为true时生效。参数值:
true:开启;
false:不开启。
citation_format string(可选)默认值为"[
角标样式。在enable_citation为true时生效。参数值:
[
[ref_
forced_search boolean(可选)默认值为false
是否强制开启搜索。参数值:
true:强制开启;
false:不强制开启。
search_strategy string(可选)默认值为turbo
搜索互联网信息的策略。
可选值:
turbo (默认): 兼顾响应速度与搜索效果,适用于大多数场景。
max: 采用更全面的搜索策略,可调用多源搜索引擎,以获取更详尽的搜索结果,但响应时间可能更长。
agent:可多次调用联网搜索工具与大模型,实现多轮信息检索与内容整合。
agent策略仅适用于 qwen3-max 与 qwen3-max-2025-09-23。启用该策略时,仅支持返回搜索来源(enable_source: true),其他联网搜索功能不可用。enable_search_extension boolean(可选)默认值为false
是否开启特定领域增强。参数值:
true
开启。
false(默认值)
不开启。
prepend_search_result boolean(可选)默认值为false
在流式输出且enable_source为true时,可通过prepend_search_result配置第一个返回的数据包是否只包含搜索来源信息。可选值:
true
只包含搜索来源信息。
false(默认值)
包含搜索来源信息与大模型回复信息。
暂不支持 DashScope Java SDK。X-DashScope-DataInspection string (可选)
在通义千问 API 的内容安全能力基础上,是否进一步识别输入输出内容的违规信息。取值如下:
'{"input":"cip","output":"cip"}':进一步识别;
不设置该参数:不进一步识别。
通过 HTTP 调用时请放入请求头:-H "X-DashScope-DataInspection: {\"input\": \"cip\", \"output\": \"cip\"}";
通过 Python SDK 调用时请通过headers配置:headers={'X-DashScope-DataInspection': '{"input":"cip","output":"cip"}'}。
详细使用方法请参见内容审核。
不支持通过 Java SDK 设置。不适用于Qwen-Audio 系列模型。