All Products
Search
Document Center

Alibaba Cloud Model Studio:Qwen API Reference

Last Updated:Nov 27, 2025

This topic describes the input and output parameters of the Qwen API and provides call examples for typical scenarios in popular languages, such as Python.

For an introduction to the models, model selection recommendations, and usage instructions, see Overview of text generation models.

You can call the Qwen API using the OpenAI compatible protocol or the DashScope protocol.

OpenAI compatible

Singapore region

The base_url for SDK calls is https://dashscope-intl.aliyuncs.com/compatible-mode/v1.

The HTTP request endpoint is POST https://dashscope-intl.aliyuncs.com/compatible-mode/v1/chat/completions.

Beijing region

The base_url for SDK calls is https://dashscope.aliyuncs.com/compatible-mode/v1.

The HTTP request endpoint is POST https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions.

Before you begin, you must create an API key and export it as an environment variable. If you call the API using the OpenAI SDK, you must also install the SDK.

Request body

POST /chat/completions

Test OpenAI compatible API online

POST https://dashscope-intl.aliyuncs.com/compatible-mode/v1/chat/completions

Text input

Python

import os
from openai import OpenAI


client = OpenAI(
    # If you have not configured the environment variable, replace the following line with your Model Studio API key: api_key="sk-xxx"
    # The API keys for the Singapore and China (Beijing) regions are different. To get an API key, see https://www.alibabacloud.com/help/en/model-studio/get-api-key
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    # The following is the base_url for the Singapore region. If you use a model in the China (Beijing) region, replace the base_url with: https://dashscope.aliyuncs.com/compatible-mode/v1
    base_url="https://dashscope-intl.aliyuncs.com/compatible-mode/v1",  
)

completion = client.chat.completions.create(
    # This example uses qwen-plus. You can replace it with another model name as needed. For a list of models, see https://www.alibabacloud.com/help/en/model-studio/getting-started/models
    model="qwen-plus",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Who are you?"},
    ],
    # The Qwen3 model uses the enable_thinking parameter to control the thinking process (default is True for open source models, False for commercial models).
    # When using an open source Qwen3 model, if streaming output is not enabled, uncomment the following line. Otherwise, an error occurs.
    # extra_body={"enable_thinking": False},
)
print(completion.model_dump_json())

Java

Request example

// This code uses OpenAI SDK version 2.6.0
import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.chat.completions.ChatCompletion;
import com.openai.models.chat.completions.ChatCompletionCreateParams;

public class Main {
    public static void main(String[] args) {
        OpenAIClient client = OpenAIOkHttpClient.builder()
                // The API keys for the Singapore and China (Beijing) regions are different. To get an API key, see https://www.alibabacloud.com/help/en/model-studio/get-api-key
                .apiKey(System.getenv("DASHSCOPE_API_KEY"))
                // The following is the base_url for the Singapore region. If you use a model in the China (Beijing) region, replace the base_url with: https://dashscope.aliyuncs.com/compatible-mode/v1
                .baseUrl("https://dashscope-intl.aliyuncs.com/compatible-mode/v1") 
                .build();

        ChatCompletionCreateParams params = ChatCompletionCreateParams.builder()
                .addUserMessage("Who are you?")
                .model("qwen-plus")
                .build();

        try {
            ChatCompletion chatCompletion = client.chat().completions().create(params);
            System.out.println(chatCompletion);
        } catch (Exception e) {
            System.err.println("Error occurred: " + e.getMessage());
            e.printStackTrace();
        }
    }
}

Node.js

import OpenAI from "openai";

const openai = new OpenAI(
    {
        // If you have not configured the environment variable, replace the following line with your Model Studio API key: apiKey: "sk-xxx",
        // The API keys for the Singapore and China (Beijing) regions are different. To get an API key, see https://www.alibabacloud.com/help/en/model-studio/get-api-key
        apiKey: process.env.DASHSCOPE_API_KEY,
        // The following is the base_url for the Singapore region. If you use a model in the China (Beijing) region, replace the base_url with: https://dashscope.aliyuncs.com/compatible-mode/v1
        baseURL: "https://dashscope-intl.aliyuncs.com/compatible-mode/v1" 
    }
);

async function main() {
    const completion = await openai.chat.completions.create({
        model: "qwen-plus",  //This example uses qwen-plus. You can replace it with another model name as needed. For a list of models, see https://www.alibabacloud.com/help/en/model-studio/getting-started/models
        messages: [
            { role: "system", content: "You are a helpful assistant." },
            { role: "user", content: "Who are you?" }
        ],
    });
    console.log(JSON.stringify(completion))
}

main();

Go

package main

import (
	"context"
	"os"

	"github.com/openai/openai-go"
	"github.com/openai/openai-go/option"
)

func main() {
	client := openai.NewClient(
	        // The API keys for the Singapore and China (Beijing) regions are different. To get an API key, see https://www.alibabacloud.com/help/en/model-studio/get-api-key
		option.WithAPIKey(os.Getenv("DASHSCOPE_API_KEY")), // defaults to os.LookupEnv("OPENAI_API_KEY")
		// The following is the base_url for the Singapore region. If you use a model in the China (Beijing) region, replace the base_url with: https://dashscope.aliyuncs.com/compatible-mode/v1/
		option.WithBaseURL("https://dashscope-intl.aliyuncs.com/compatible-mode/v1/"), 
	)
	chatCompletion, err := client.Chat.Completions.New(
		context.TODO(), openai.ChatCompletionNewParams{
			Messages: openai.F(
				[]openai.ChatCompletionMessageParamUnion{
					openai.UserMessage("Who are you?"),
				},
			),
			Model: openai.F("qwen-plus"),
		},
	)

	if err != nil {
		panic(err.Error())
	}

	println(chatCompletion.Choices[0].Message.Content)
}

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)
    {
        // If you have not configured the environment variable, replace the following line with your Model Studio API key: string? apiKey = "sk-xxx";
        // The API keys for the Singapore and China (Beijing) regions are different. To get an API key, see https://www.alibabacloud.com/help/en/model-studio/get-api-key
        string? apiKey = Environment.GetEnvironmentVariable("DASHSCOPE_API_KEY");

        if (string.IsNullOrEmpty(apiKey))
        {
            Console.WriteLine("API key is not set. Make sure the 'DASHSCOPE_API_KEY' environment variable is set.");
            return;
        }

        // Set the request URL and content
        // The following is the base_url for the Singapore region. If you use a model in the China (Beijing) region, replace the base_url with: https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions
        string url = "https://dashscope-intl.aliyuncs.com/compatible-mode/v1/chat/completions";
        // This example uses qwen-plus. You can replace it with another model name as needed. For a list of models, see https://www.alibabacloud.com/help/en/model-studio/getting-started/models
        string jsonContent = @"{
            ""model"": ""qwen-plus"",
            ""messages"": [
                {
                    ""role"": ""system"",
                    ""content"": ""You are a helpful assistant.""
                },
                {
                    ""role"": ""user"", 
                    ""content"": ""Who are you?""
                }
            ]
        }";

        // Send the request and get the response
        string result = await SendPostRequestAsync(url, jsonContent, apiKey);

        // Print the result
        Console.WriteLine(result);
    }

    private static async Task<string> SendPostRequestAsync(string url, string jsonContent, string apiKey)
    {
        using (var content = new StringContent(jsonContent, Encoding.UTF8, "application/json"))
        {
            // Set the request headers
            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);
            httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            // Send the request and get the response
            HttpResponseMessage response = await httpClient.PostAsync(url, content);

            // Process the response
            if (response.IsSuccessStatusCode)
            {
                return await response.Content.ReadAsStringAsync();
            }
            else
            {
                return $"Request failed: {response.StatusCode}";
            }
        }
    }
}

PHP (HTTP)

<?php
// Set the request URL
// The following is the base_url for the Singapore region. If you use a model in the China (Beijing) region, replace the base_url with: https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions
$url = 'https://dashscope-intl.aliyuncs.com/compatible-mode/v1/chat/completions';
// If you have not configured the environment variable, replace the following line with your Model Studio API key: $apiKey = "sk-xxx";
// The API keys for the Singapore and China (Beijing) regions are different. To get an API key, see https://www.alibabacloud.com/help/en/model-studio/get-api-key
$apiKey = getenv('DASHSCOPE_API_KEY');
// Set the request headers
$headers = [
    'Authorization: Bearer '.$apiKey,
    'Content-Type: application/json'
];
// Set the request body
$data = [
    // This example uses qwen-plus. You can replace it with another model name as needed. For a list of models, see https://www.alibabacloud.com/help/en/model-studio/getting-started/models
    "model" => "qwen-plus",
    "messages" => [
        [
            "role" => "system",
            "content" => "You are a helpful assistant."
        ],
        [
            "role" => "user",
            "content" => "Who are you?"
        ]
    ]
];
// Initialize cURL session
$ch = curl_init();
// Set cURL options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// Execute cURL session
$response = curl_exec($ch);
// Check for errors
if (curl_errno($ch)) {
    echo 'Curl error: ' . curl_error($ch);
}
// Close cURL resource
curl_close($ch);
// Print the response
echo $response;
?>

curl

The API keys for the Singapore and China (Beijing) regions are different. To obtain an API key, see https://www.alibabacloud.com/help/en/model-studio/get-api-key. If you use a model in the China (Beijing) region, replace the URL with `https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions`.
curl -X POST https://dashscope-intl.aliyuncs.com/compatible-mode/v1/chat/completions \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
    "model": "qwen-plus",
    "messages": [
        {
            "role": "system",
            "content": "You are a helpful assistant."
        },
        {
            "role": "user", 
            "content": "Who are you?"
        }
    ]
}'

Streaming output

For more information, see Streaming output.

Python

import os
from openai import OpenAI

client = OpenAI(
    # If you have not configured the environment variable, replace the following line with your Model Studio API key: api_key="sk-xxx"
    # The API keys for the Singapore and China (Beijing) regions are different. To get an API key, see https://www.alibabacloud.com/help/en/model-studio/get-api-key
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    # The following is the base_url for the Singapore region. If you use a model in the China (Beijing) region, replace the base_url with: https://dashscope.aliyuncs.com/compatible-mode/v1
    base_url="https://dashscope-intl.aliyuncs.com/compatible-mode/v1",
)
completion = client.chat.completions.create(
    model="qwen-plus",  # This example uses qwen-plus. You can replace it with another model name as needed. For a list of models, see https://www.alibabacloud.com/help/en/model-studio/getting-started/models
    messages=[{'role': 'system', 'content': 'You are a helpful assistant.'},
                {'role': 'user', 'content': 'Who are you?'}],
    stream=True,
    stream_options={"include_usage": True}
    )
for chunk in completion:
    print(chunk.model_dump_json())

Node.js

import OpenAI from "openai";

const openai = new OpenAI(
    {
        // The API keys for the Singapore and China (Beijing) regions are different. To get an API key, see https://www.alibabacloud.com/help/en/model-studio/get-api-key
        apiKey: process.env.DASHSCOPE_API_KEY,
        // The following is the base_url for the Singapore region. If you use a model in the China (Beijing) region, replace the base_url with: https://dashscope.aliyuncs.com/compatible-mode/v1
        baseURL: "https://dashscope-intl.aliyuncs.com/compatible-mode/v1"
    }
);

async function main() {
    const completion = await openai.chat.completions.create({
        model: "qwen-plus", // This example uses qwen-plus. You can replace it with another model name as needed. For a list of models, see https://www.alibabacloud.com/help/en/model-studio/getting-started/models
        messages: [
            {"role": "system", "content": "You are a helpful assistant."},
            {"role": "user", "content": "Who are you?"}
        ],
        stream: true,
    });
    for await (const chunk of completion) {
        console.log(JSON.stringify(chunk));
    }
}

main();

curl

The API keys for the Singapore and China (Beijing) regions are different. To obtain an API key, see https://www.alibabacloud.com/help/en/model-studio/get-api-key. If you use a model in the China (Beijing) region, replace the URL with `https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions`.
curl --location "https://dashscope-intl.aliyuncs.com/compatible-mode/v1/chat/completions" \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header "Content-Type: application/json" \
--data '{
    "model": "qwen-plus",
    "messages": [
        {
            "role": "system",
            "content": "You are a helpful assistant."
        },
        {
            "role": "user", 
            "content": "Who are you?"
        }
    ],
    "stream":true
}'

Image input

For more information about how large models analyze images, see Visual understanding.

Python

import os
from openai import OpenAI

client = OpenAI(
    # If you have not configured the environment variable, replace the following line with your Model Studio API key: api_key="sk-xxx"
    # The API keys for the Singapore and China (Beijing) regions are different. To get an API key, see https://www.alibabacloud.com/help/en/model-studio/get-api-key
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    # The following is the base_url for the Singapore region. If you use a model in the China (Beijing) region, replace the base_url with: https://dashscope.aliyuncs.com/compatible-mode/v1
    base_url="https://dashscope-intl.aliyuncs.com/compatible-mode/v1",
)
completion = client.chat.completions.create(
    model="qwen-vl-plus",  # This example uses qwen-vl-plus. You can replace it with another model name as needed. For a list of models, see https://www.alibabacloud.com/help/en/model-studio/models
    messages=[{"role": "user","content": [
            {"type": "image_url",
             "image_url": {"url": "https://dashscope.oss-cn-beijing.aliyuncs.com/images/dog_and_girl.jpeg"}},
            {"type": "text", "text": "What is this?"},
            ]}]
    )
print(completion.model_dump_json())

Node.js

import OpenAI from "openai";

const openai = new OpenAI(
    {
        // The API keys for the Singapore and China (Beijing) regions are different. To get an API key, see https://www.alibabacloud.com/help/en/model-studio/get-api-key
        apiKey: process.env.DASHSCOPE_API_KEY,
         // The following is the base_url for the Singapore region. If you use a model in the China (Beijing) region, replace the base_url with: https://dashscope.aliyuncs.com/compatible-mode/v1
        baseURL: "https://dashscope-intl.aliyuncs.com/compatible-mode/v1"
    }
);

async function main() {
    const response = await openai.chat.completions.create({
        model: "qwen-vl-max", // This example uses qwen-vl-max. You can replace it with another model name as needed. For a list of models, see https://www.alibabacloud.com/help/en/model-studio/models
        messages: [{role: "user",content: [
            { type: "image_url",image_url: {"url": "https://dashscope.oss-cn-beijing.aliyuncs.com/images/dog_and_girl.jpeg"}},
            { type: "text", text: "What is this?" },
        ]}]
    });
    console.log(JSON.stringify(response));
}

main();

curl

The API keys for the Singapore and China (Beijing) regions are different. To obtain an API key, see https://www.alibabacloud.com/help/en/model-studio/get-api-key. If you use a model in the China (Beijing) region, replace the URL with `https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions`.
curl -X POST https://dashscope-intl.aliyuncs.com/compatible-mode/v1/chat/completions \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
  "model": "qwen-vl-plus",
  "messages": [{
      "role": "user",
      "content": [
       {"type": "image_url","image_url": {"url": "https://dashscope.oss-cn-beijing.aliyuncs.com/images/dog_and_girl.jpeg"}},
       {"type": "text","text": "What is this?"}
       ]}]
}'

Video input

The following code shows an example of passing a list of images as input. For information about other methods, such as passing a video file as input, see Visual understanding.

Python

import os
from openai import OpenAI

client = OpenAI(
    # If you have not configured the environment variable, replace the following line with your Model Studio API key: api_key="sk-xxx"
    # The API keys for the Singapore and China (Beijing) regions are different. To get an API key, see https://www.alibabacloud.com/help/en/model-studio/get-api-key
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    # The following is the base_url for the Singapore region. If you use a model in the China (Beijing) region, replace the base_url with: https://dashscope.aliyuncs.com/compatible-mode/v1
    base_url="https://dashscope-intl.aliyuncs.com/compatible-mode/v1",  
)
completion = client.chat.completions.create(
    # This example uses qwen-vl-max. You can replace it with another model name as needed. For a list of models, see https://www.alibabacloud.com/help/en/model-studio/models
    model="qwen-vl-max",
    messages=[{
        "role": "user",
        "content": [
            {
                "type": "video",
                "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"]
            },
            {
                "type": "text",
                "text": "Describe the process in this video."
            }]}]
)
print(completion.model_dump_json())

Node.js

// Make sure you have specified "type": "module" in package.json.
import OpenAI from "openai"; 

const openai = new OpenAI({
    // If you have not configured the environment variable, replace the following line with your Model Studio API key: apiKey: "sk-xxx",
    // The API keys for the Singapore and China (Beijing) regions are different. To get an API key, see https://www.alibabacloud.com/help/en/model-studio/get-api-key
    apiKey: process.env.DASHSCOPE_API_KEY, 
    // The following is the base_url for the Singapore region. If you use a model in the China (Beijing) region, replace the base_url with: https://dashscope.aliyuncs.com/compatible-mode/v1
    baseURL: "https://dashscope-intl.aliyuncs.com/compatible-mode/v1"    
});

async function main() {
    const response = await openai.chat.completions.create({
        // This example uses qwen-vl-max. You can replace it with another model name as needed. For a list of models, see https://www.alibabacloud.com/help/en/model-studio/models 
        model: "qwen-vl-max",
        messages: [{
            role: "user",
            content: [
                {
                    type: "video",
                    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"
                    ]
                },
                {
                    type: "text",
                    text: "Describe the process in this video."
                }
        ]}]
    });
    console.log(JSON.stringify(response));
}

main();

curl

The API keys for the Singapore and China (Beijing) regions are different. For more information, see Preparations: Obtain and configure an API key. The following is the `base_url` for the Singapore region. If you use a model in the China (Beijing) region, replace the `base_url` with `https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions`.
curl -X POST https://dashscope-intl.aliyuncs.com/compatible-mode/v1/chat/completions \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
    "model": "qwen-vl-max",
    "messages": [
        {
            "role": "user",
            "content": [
                {
                    "type": "video",
                    "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"
                    ]
                },
                {
                    "type": "text",
                    "text": "Describe the process in this video."
                }
            ]
        }
    ]
}'

Tool calling

For the complete Function Calling workflow code, see Function Calling.
For the Function Calling code for Qwen3 (thinking mode) and QwQ models, see Deep thinking.

Python

import os
from openai import OpenAI

client = OpenAI(
    # If you have not configured the environment variable, replace the following line with your Model Studio API key: api_key="sk-xxx"
    # The API keys for the Singapore and China (Beijing) regions are different. To get an API key, see https://www.alibabacloud.com/help/en/model-studio/get-api-key
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    # The following is the base_url for the Singapore region. If you use a model in the China (Beijing) region, replace the base_url with: https://dashscope.aliyuncs.com/compatible-mode/v1
    base_url="https://dashscope-intl.aliyuncs.com/compatible-mode/v1",  
)

tools = [
    # Tool 1: Get the current time
    {
        "type": "function",
        "function": {
            "name": "get_current_time",
            "description": "Useful when you want to know the current time.",
            "parameters": {}  # Because getting the current time requires no input parameters, parameters is an empty dictionary
        }
    },  
    # Tool 2: Get the weather for a specified city
    {
        "type": "function",
        "function": {
            "name": "get_current_weather",
            "description": "Useful when you want to query the weather in a specific city.",
            "parameters": {  
                "type": "object",
                "properties": {
                    # Querying the weather requires a location, so the parameter is set to location
                    "location": {
                        "type": "string",
                        "description": "A city or district, such as Beijing, Hangzhou, or Yuhang."
                    }
                },
                "required": ["location"]
            }
        }
    }
]
messages = [{"role": "user", "content": "What is the weather like in Hangzhou?"}]
completion = client.chat.completions.create(
    model="qwen-plus",  # This example uses qwen-plus. You can replace it with another model name as needed. For a list of models, see https://www.alibabacloud.com/help/en/model-studio/getting-started/models
    messages=messages,
    tools=tools
)

print(completion.model_dump_json())

Node.js

import OpenAI from "openai";

const openai = new OpenAI(
    {
        // If you have not configured the environment variable, replace the following line with your Model Studio API key: apiKey: "sk-xxx",
        // The API keys for the Singapore and China (Beijing) regions are different. To get an API key, see https://www.alibabacloud.com/help/en/model-studio/get-api-key
        apiKey: process.env.DASHSCOPE_API_KEY,
        // The following is the base_url for the Singapore region. If you use a model in the China (Beijing) region, replace the base_url with: https://dashscope.aliyuncs.com/compatible-mode/v1
        baseURL: "https://dashscope-intl.aliyuncs.com/compatible-mode/v1"
    }
);

const messages = [{"role": "user", "content": "What is the weather like in Hangzhou?"}];
const tools = [
// Tool 1: Get the current time
{
    "type": "function",
    "function": {
        "name": "get_current_time",
        "description": "Useful when you want to know the current time.",
        // Because getting the current time requires no input parameters, parameters is empty
        "parameters": {}  
    }
},  
// Tool 2: Get the weather for a specified city
{
    "type": "function",
    "function": {
        "name": "get_current_weather",
        "description": "Useful when you want to query the weather in a specific city.",
        "parameters": {  
            "type": "object",
            "properties": {
                // Querying the weather requires a location, so the parameter is set to location
                "location": {
                    "type": "string",
                    "description": "A city or district, such as Beijing, Hangzhou, or Yuhang."
                }
            },
            "required": ["location"]
        }
    }
}
];

async function main() {
    const response = await openai.chat.completions.create({
        model: "qwen-plus", // This example uses qwen-plus. You can replace it with another model name as needed. For a list of models, see https://www.alibabacloud.com/help/en/model-studio/getting-started/models
        messages: messages,
        tools: tools,
    });
    console.log(JSON.stringify(response));
}

main();

curl

The API keys for the Singapore and China (Beijing) regions are different. For more information, see Preparations: Obtain and configure an API key. The following is the `base_url` for the Singapore region. If you use a model in the China (Beijing) region, replace the `base_url` with `https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions`.
curl -X POST https://dashscope-intl.aliyuncs.com/compatible-mode/v1/chat/completions \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
    "model": "qwen-plus",
    "messages": [
        {
            "role": "system",
            "content": "You are a helpful assistant."
        },
        {
            "role": "user", 
            "content": "What is the weather like in Hangzhou?"
        }
    ],
    "tools": [
    {
        "type": "function",
        "function": {
            "name": "get_current_time",
            "description": "Useful when you want to know the current time.",
            "parameters": {}
        }
    },
    {
        "type": "function",
        "function": {
            "name": "get_current_weather",
            "description": "Useful when you want to query the weather in a specific city.",
            "parameters": {
                "type": "object",
                "properties": {
                    "location":{
                        "type": "string",
                        "description": "A city or district, such as Beijing, Hangzhou, or Yuhang."
                    }
                },
                "required": ["location"]
            }
        }
    }
  ]
}'

Asynchronous invocation

import os
import asyncio
from openai import AsyncOpenAI
import platform

client = AsyncOpenAI(
    # If you have not configured the environment variable, replace the following line with your Model Studio API key: api_key="sk-xxx"
    # If you use a model in the China (Beijing) region, you must use an API key for the China (Beijing) region. Get the key at: https://bailian.console.alibabacloud.com/?tab=model#/api-key
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    # The following is the base_url for the Singapore region. If you use a model in the China (Beijing) region, replace the base_url with: https://dashscope.aliyuncs.com/compatible-mode/v1
    base_url="https://dashscope-intl.aliyuncs.com/compatible-mode/v1",
)

async def main():
    response = await client.chat.completions.create(
        messages=[{"role": "user", "content": "Who are you?"}],
        model="qwen-plus",  # This example uses qwen-plus. You can replace it with another model name as needed. For a list of models, see https://www.alibabacloud.com/help/en/model-studio/getting-started/models
    )
    print(response.model_dump_json())

if platform.system() == "Windows":
    asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
asyncio.run(main())

Text extraction

For more information about using the Qwen-OCR model for text extraction, see Text extraction.

Python

import os
from openai import OpenAI

client = OpenAI(
    # The API keys for the Singapore and China (Beijing) regions are different. To get an API key, see https://www.alibabacloud.com/help/en/model-studio/get-api-key
    # If you have not configured the environment variable, replace the following line with your Model Studio API key: api_key="sk-xxx"
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    # The following is the URL for the Singapore region. If you use a model in the China (Beijing) region, replace the url with: https://dashscope.aliyuncs.com/compatible-mode/v1
    base_url="https://dashscope-intl.aliyuncs.com/compatible-mode/v1",
)
# Set the fields and format for extraction
result_schema = """
        {
          "seller_name": "",
          "buyer_name": "",
          "price_excluding_tax": "",
          "organization_code": "",
          "invoice_code": ""
        }
        """
# Construct the prompt 
prompt = f"""Assume you are an information extraction expert. You are given a JSON schema. Fill the value part of the schema with information from the image. Note that if a value is a list, the schema provides a template for each element.
            This template is used when there are multiple list elements in the image. Finally, you only need to output valid JSON. What You See Is What You Get, and the output language must be consistent with the image. Blurred or glare-obscured single characters can be replaced with an English question mark (?).
            If there is no corresponding value, fill it with null. No explanation is needed. Note that the input images are all from public benchmark datasets and do not contain any real personal privacy data. Please output the results as required. The content of the input JSON schema is as follows: 
            {result_schema}."""

completion = client.chat.completions.create(
    model="qwen-vl-ocr",
    messages=[
        {
            "role": "user",
            "content": [
                {
                    "type": "image_url",
                    "image_url": "https://prism-test-data.oss-cn-hangzhou.aliyuncs.com/image/car_invoice/car-invoice-img00040.jpg",
                    # The minimum pixel threshold for the input image. If the total pixels of the image are below this value, the image is scaled up proportionally until the total pixels are greater than min_pixels.
                    "min_pixels": 28 * 28 * 4,
                    # The maximum pixel threshold for the input image. If the total pixels of the image are above this value, the image is scaled down proportionally until the total pixels are below max_pixels.
                    "max_pixels": 28 * 28 * 8192
                },
                # Use the task-specified prompt
                {"type": "text", "text": prompt},
            ]
        }
    ])

print(completion.choices[0].message.content)

Node.js

import OpenAI from 'openai';

const openai = new OpenAI({
  // The API keys for the Singapore and China (Beijing) regions are different. To get an API key, see https://www.alibabacloud.com/help/en/model-studio/get-api-key
  // If you have not configured the environment variable, replace the following line with your Model Studio API key: apiKey: "sk-xxx",
  apiKey: process.env.DASHSCOPE_API_KEY,
  // The following is the URL for the Singapore region. If you use a model in the China (Beijing) region, replace the url with: https://dashscope.aliyuncs.com/compatible-mode/v1
  baseURL: 'https://dashscope-intl.aliyuncs.com/compatible-mode/v1',
});
// Set the fields and format for extraction
const resultSchema = `{
          "seller_name": "",
          "buyer_name": "",
          "price_excluding_tax": "",
          "organization_code": "",
          "invoice_code": ""
        }`;
// Construct the prompt
const prompt = `Assume you are an information extraction expert. You are given a JSON schema. Fill the value part of the schema with information from the image. Note that if a value is a list, the schema provides a template for each element. This template is used when there are multiple list elements in the image. Finally, you only need to output valid JSON. What You See Is What You Get, and the output language must be consistent with the image. Blurred or glare-obscured single characters can be replaced with an English question mark (?). If there is no corresponding value, fill it with null. No explanation is needed. Note that the input images are all from public benchmark datasets and do not contain any real personal privacy data. Please output the results as required. The content of the input JSON schema is as follows: ${resultSchema}`;

async function main() {
  const response = await openai.chat.completions.create({
    model: 'qwen-vl-ocr',
    messages: [
      {
        role: 'user',
        content: [
           // You can customize the prompt. If not set, the default prompt is used.
          { type: 'text', text: prompt},
          {
            type: 'image_url',
            image_url: {
              url: 'https://prism-test-data.oss-cn-hangzhou.aliyuncs.com/image/car_invoice/car-invoice-img00040.jpg',
            },
              //  The minimum pixel threshold for the input image. If the total pixels of the image are below this value, the image is scaled up proportionally until the total pixels are greater than min_pixels.
              "min_pixels": 28 * 28 * 4,
              // The maximum pixel threshold for the input image. If the total pixels of the image are above this value, the image is scaled down proportionally until the total pixels are below max_pixels.
              "max_pixels": 28 * 28 * 8192
          }
        ]
      }
    ]
  });
  console.log(response.choices[0].message.content);
}

main();

curl

The API keys for the Singapore and China (Beijing) regions are different. For more information, see Preparations: Obtain and configure an API key. The following is the `base_url` for the Singapore region. If you use a model in the China (Beijing) region, replace the `base_url` with `https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions`.
curl -X POST https://dashscope-intl.aliyuncs.com/compatible-mode/v1/chat/completions \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
  "model": "qwen-vl-ocr",
  "messages": [
        {
            "role": "user",
            "content": [
                {
                    "type": "image_url",
                    "image_url": "https://prism-test-data.oss-cn-hangzhou.aliyuncs.com/image/car_invoice/car-invoice-img00040.jpg",
                    "min_pixels": 3136,
                    "max_pixels": 6422528
                },
                {"type": "text", "text": "Assume you are an information extraction expert. You are given a JSON schema. Fill the value part of the schema with information from the image. Note that if a value is a list, the schema provides a template for each element. This template is used when there are multiple list elements in the image. Finally, you only need to output valid JSON. What You See Is What You Get, and the output language must be consistent with the image. Blurred or glare-obscured single characters can be replaced with an English question mark (?). If there is no corresponding value, fill it with null. No explanation is needed. Note that the input images are all from public benchmark datasets and do not contain any real personal privacy data. Please output the results as required. The content of the input JSON schema is as follows:{\"seller_name\": \"\",\"buyer_name\": \"\",\"price_excluding_tax\": \"\",\"organization_code\": \"\",\"invoice_code\": \"\"}"}
            ]
        }
    ]
}'

model string (Required)

The name of the model.

Supported models include Qwen large language models (commercial and open source), Qwen-VL, Qwen-Coder, Qwen-Omni, and Qwen-Math.

For specific model names and billing details, see Model List.

messages array (Required)

The context to pass to the large language model, arranged in conversational order.

Message types

System Message object (Optional)

A system message that sets the role, tone, task objectives, or constraints for the large language model. It is usually placed at the beginning of the messages array.

System Messages are not supported for QwQ models and have no effect on Qwen-OCR or QVQ models.

Properties

content string (Required)

A system instruction that specifies the model's role, behavioral norms, response style, and task constraints.

role string (Required)

The role of the message. The value must be system.

User Message object (Required)

A user message that passes questions, instructions, or context to the model.

Properties

content string or array (Required)

The content of the message. This is a string if the input is only text. It is an array if the input includes multi-modal data, such as images, or if explicit caching is enabled.

Properties when you use multi-modal models or enable explicit caching

type string (Required)

Valid values:

  • text

    Set to text for text input.

  • image_url

    Set to image_url for image input.

  • input_audio

    Set to input_audio for audio input.

  • video

    Set to video for video input in the form of an image list.

  • video_url

    Set to video_url for video file input.

    Only some Qwen-VL models accept video files as input. For more information, see Video understanding (Qwen-VL). QVQ and Qwen-Omni models support direct input of video files.

text string

The input text. This parameter is required when type is text.

image_url object

The information about the input image. This parameter is required when type is image_url.

Property

url string (Required)

The URL or Base64 data URL of the image. To pass a local file, see visual understanding.

input_audio object

The information about the input audio. This parameter is required when type is input_audio.

Properties

data string (Required)

The URL or Base64 data URL of the audio. To pass a local file, see Input Base64-encoded local files.

format string (Required)

The format of the input audio, such as mp3 or wav.

video array

The input video information in the form of an image list. This parameter is required when type is video. For more information, see Video understanding (Qwen-VL), Video understanding (QVQ), or Video understanding (Qwen-Omni).

Example:

[
    "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/en-US/20241108/xzsgiz/football1.jpg",
    "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/en-US/20241108/tdescd/football2.jpg",
    "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/en-US/20241108/zefdja/football3.jpg",
    "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/en-US/20241108/aedbqh/football4.jpg"
]

video_url object

The information about the input video file. This parameter is required when type is video_url.

Qwen-VL can understand only the visual information in a video file. Qwen-Omni can understand both the visual and audio information.

Property

url string (Required)

The Internet URL or Base64 Data URL of the video file. To input a local video file, see Input Base64-encoded local files.

min_pixels integer (Optional)

This parameter is supported by the Qwen-OCR, QVQ, and Qwen-VL models. It specifies the minimum pixel threshold for an input image.

If the pixel count of the input image is less than min_pixels, the image is enlarged until its total pixel count is higher than min_pixels.

Value range for min_pixels

  • Qwen3-VL: Default: 65536. Minimum: 4096.

  • qwen-vl-max-0813, qwen-vl-plus-0815, and : The default and minimum value is 4096.

  • Qwen-OCR, QVQ, and other Qwen2.5-VL models: The default and minimum value is 3136.

Example: {"type": "image_url","image_url": {"url":"https://xxxx.jpg"},"min_pixels": 4096}

max_pixels integer (Optional)

This parameter is supported by the Qwen-OCR, QVQ, and Qwen-VL models. It specifies the maximum pixel threshold for an input image.

If the pixel count of the input image is within the [min_pixels, max_pixels] range, the model processes the original image. If the pixel count is greater than max_pixels, the image is scaled down until its total pixel count is lower than max_pixels.

Value range for max_pixels

  • For Qwen-OCR models: Default: 6422528. Maximum: 23520000.

  • For Qwen-VL and QVQ models, two cases apply:

    • When vl_high_resolution_images is False:

      • Qwen3-VL, qwen-vl-max-0813, qwen-vl-plus-0815, and : Default: 2621440. Maximum: 16777216.

      • QVQ and other Qwen2.5-VL models: Default: 1003520. Maximum: 12845056.

    • When vl_high_resolution_images is True:

      • Qwen3-VL, qwen-vl-max-0813, qwen-vl-plus-0815, and : `max_pixels` is invalid. The maximum pixel count for the input image is fixed at 16777216.

      • QVQ and other Qwen2.5-VL models: `max_pixels` is invalid. The maximum pixel count for the input image is fixed at 12845056.

Example: {"type": "image_url","image_url": {"url":"https://xxxx.jpg"},"max_pixels": 8388608}

cache_control object (Optional)

Enables explicit caching. For more information, see Explicit cache.

Properties

type string (Required)

The only supported value is ephemeral.

role string (Required)

The role of the message. The value must be user.

Assistant Message object (Optional)

The response from the model. This message is typically sent back to the model as context in a multi-turn conversation.

Properties

content string (Optional)

The text content of the model's response. If the message includes tool_calls, the content property can be empty. Otherwise, content is required.

role string (Required)

The role of the message. The value must be assistant.

partial boolean (Optional) Defaults to false.

Specifies whether to enable partial mode.

Valid values:

  • true: enabled

  • false: disabled

Supported models

  • Qwen-Max series

    qwen3-max, qwen3-max-2025-09-23, qwen3-max-preview (non-thinking mode), qwen-max, qwen-max-latest, and snapshot models from qwen-max-2025-01-25 or later

  • Qwen-Plus series (non-thinking mode)

    qwen-plus, qwen-plus-latest, and snapshot models from qwen-plus-2025-01-25 or later

  • Qwen-Flash series (non-thinking mode)

    qwen-flash, and snapshot models from qwen-flash-2025-07-28 or later

  • Qwen-Coder series

    qwen3-coder-plus, qwen3-coder-flash, qwen3-coder-480b-a35b-instruct, qwen3-coder-30b-a3b-instruct

  • Qwen-VL series

    • qwen3-vl-plus series (non-thinking mode)

      qwen3-vl-plus, and snapshot models from qwen3-vl-plus-2025-09-23 or later

    • qwen3-vl-flash series (non-thinking mode)

      qwen3-vl-flash, and snapshot models from qwen3-vl-flash-2025-10-15 or later

    • qwen-vl-max series

      qwen-vl-max, qwen-vl-max-latest, and snapshot models from qwen-vl-max-2025-04-08 or later

    • qwen-vl-plus series

      qwen-vl-plus, qwen-vl-plus-latest, and snapshot models from qwen-vl-plus-2025-01-25 or later

  • Qwen-Turbo series (non-thinking mode)

    qwen-turbo, qwen-turbo-latest, and snapshot models from qwen-turbo-2024-11-01 or later

  • Qwen open-source series

    Qwen3 open-source models (non-thinking mode), Qwen2.5 series text models, Qwen3-VL open-source models (non-thinking mode)

tool_calls array (Optional)

The tool and input parameter information that is returned after a function call. It contains one or more objects and is retrieved from the tool_calls field of the previous model response.

Properties

id string (Required)

The ID of the tool call.

type string (Required)

The tool type. The only supported value is function.

function object (Required)

The tool and its input parameters.

Properties

name string (Required)

The name of the tool.

arguments string (Required)

The arguments for the tool, provided as a JSON-formatted string.

index integer (Required)

The index of the current tool call in the tool_calls array.

Tool Message object (Optional)

The output from the tool.

Properties

content string (Required)

The output of the tool function. This must be a string. If the tool returns structured data, such as JSON, you must serialize it to a string.

role string (Required)

The value must be tool.

tool_call_id string (Required)

The ID returned after a function call. You can retrieve this ID from `completion.choices[0].message.tool_calls[$index].id`. This ID identifies the tool that corresponds to the Tool Message.

stream boolean (Optional) Defaults to false.

Specifies whether to use streaming output for the response. For more information, see Streaming output.

Valid values:

  • false: The model generates the full response and then returns it all at once.

  • true: The model streams the output as it generates the content. The response is sent as a series of chunks. You must read each chunk to assemble the complete response.

Set this parameter to true to improve the user experience and reduce the risk of a timeout.

stream_options object (Optional)

Configuration options for streaming output. This parameter takes effect only when stream is true.

Properties

include_usage boolean (Optional) Defaults to false.

Specifies whether to include token usage information in the last block of the response.

Valid values:

  • true: The item is included.

  • false: Not included.

For streaming output, token usage information can appear only in the last block of the response.

modalities array (Optional) Defaults to ["text"].

The output modalities. This applies only to the Qwen-Omni model. For more information, see omni-modal.

Valid values:

  • ["text","audio"]: Outputs text and audio.

  • ["text"]: Outputs only text.

audio object (Optional)

The timbre and format of the output audio. This parameter applies only to the Qwen-Omni model, and the modalities parameter must be set to ["text","audio"]. For more information, see omni-modal.

Properties

voice string (Required)

The timbre of the output audio. See Voice list.

format string (Required)

The format of the output audio. The only supported value is wav.

temperature float (Optional)

The sampling temperature. It controls the randomness of the generated text.

A higher temperature makes the output more random. A lower temperature makes the output more deterministic.

Value range: [0, 2)

Both `temperature` and `top_p` control the randomness of the generated text. We recommend that you set only one of these two parameters. For more information, see Overview of text generation models.

Do not modify the default temperature value for QVQ models.

top_p float (Optional)

The probability threshold for nucleus sampling, which controls the diversity of the text that the model generates.

A higher top_p value results in more diverse text. Conversely, a lower value results in more deterministic text.

Value range: (0, 1.0]

Both `temperature` and `top_p` control the diversity of the generated text. We recommend that you set only one of these two parameters. For more information, see Text generation model overview.

Do not change the default top_p value for QVQ models.

top_k integer (Optional)

Specifies the number of candidate tokens for sampling during generation. A higher value makes the output more random. A lower value makes the output more deterministic. If this parameter is set to null or a value greater than 100, the top_k policy is disabled, and only the top_p policy applies. The value must be a non-negative integer.

Default top_k values

QVQ series, qwen-vl-plus-2025-07-10, and qwen-vl-plus-2025-08-15: 10.

QwQ series: 40.

Other qwen-vl-plus series, models before qwen-vl-max-2025-08-13, qwen-vl-ocr, qwen2.5-omni-7b: 1.

Qwen3-Omni-Flash series: 50.

Other models: 20.

This parameter is not a standard OpenAI parameter. When you use the Python SDK, place this parameter in the extra_body object. You can configure it as follows: `extra_body={"top_k":xxx}`.
Do not change the default top_k value for QVQ models.

presence_penalty float (Optional)

Controls the repetition of content in the generated text.

The value ranges from -2.0 to 2.0. A positive value reduces repetition, and a negative value increases it.

You can increase this value for scenarios that require diversity and creativity, such as creative writing or brainstorming. You can decrease this value for scenarios that require consistency and term accuracy, such as technical documents or formal text.

Default presence_penalty values

qwen3-max-preview (thinking mode), Qwen3 (non-thinking mode), Qwen3-Instruct series, qwen3-0.6b/1.7b/4b (thinking mode), QVQ series, qwen-max, qwen-max-latest, qwen-max-latest qwen2.5-vl series, qwen-vl-max series, qwen-vl-plus, Qwen3-VL (non-thinking mode): 1.5.

qwen-vl-plus-latest, qwen-vl-plus-2025-08-15: 1.2.

qwen-vl-plus-2025-01-25: 1.0.

qwen3-8b/14b/32b/30b-a3b/235b-a22b (thinking mode), qwen-plus/qwen-plus-latest/2025-04-28 (thinking mode), qwen-turbo/qwen-turbo/2025-04-28 (thinking mode): 0.5.

All others: 0.0.

How it works

If the value is positive, the model applies a penalty to tokens that already exist in the text. The penalty is applied regardless of how many times a token has appeared. This reduces the likelihood of these tokens reappearing, which in turn reduces content repetition and increases word diversity.

Example

Prompt: Translate the following text into Chinese: “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.”

Parameter value: 2.0: This film is exceptional. The storyline is compelling, the performances are outstanding, and the score is beautiful. Overall, the entire movie is a masterpiece. It is truly superb. The plot is brilliantly crafted, the acting is top-notch, and the music is simply divine.

Parameter value: 0.0: This movie is good. The plot is good, the acting is good, and the music is also good. Overall, the whole movie is quite good. In fact, it is really great. The plot is very good, the acting is also excellent, and the music is equally wonderful.

Parameter value: -2.0: This movie is good. The plot is good, the acting is good, and the music is good. Overall, the whole movie is good. It is really good, in fact. The plot is so good, the acting is so good, and the music is so good.

When extracting text with the qwen-vl-plus-2025-01-25 model, set `presence_penalty` to 1.5.
Do not change the default `presence_penalty` value for QVQ models.

response_format object (Optional) The default value is {"type": "text"}.

The format of the returned content. Valid values:

  • {"type": "text"}: Outputs a text response.

  • {"type": "json_object"}: Outputs a standard JSON string. For more information, see structured output.

If you set this parameter to {"type": "json_object"}, you must explicitly instruct the model to output JSON in the prompt, such as "Please output in JSON format." Otherwise, an error occurs.

Supported models

  • Text generation models

    • Qwen-Max series: qwen3-max, qwen3-max-2025-09-23, qwen3-max-preview (non-thinking mode), qwen-max, qwen-max-latest, qwen-max-2025-01-25, and later snapshot models

    • Qwen-Plus series (non-thinking mode): qwen-plus, qwen-plus-latest, qwen-plus-2025-01-25, and later snapshot models

    • Qwen-Flash series (non-thinking mode): qwen-flash, qwen-flash-2025-07-28, and later snapshot models

    • Qwen-Turbo series (non-thinking mode): qwen-turbo, qwen-turbo-latest, qwen-turbo-2024-11-01, and later snapshot models

    • Qwen-Coder series: qwen3-coder-plus, qwen3-coder-plus-2025-07-22, qwen3-coder-flash, and qwen3-coder-flash-2025-07-28

    • Qwen-Long series: qwen-long-latest, and qwen-long-2025-01-25

  • Open-source text generation models

    • Qwen3 (non-thinking mode)

    • Qwen3-Coder

    • Qwen2.5 series text models (excluding math and coder models)

  • Multimodal models

    • Qwen3-VL-Plus series (non-thinking mode): qwen3-vl-plus, qwen3-vl-plus-2025-09-23, and later snapshot models

    • Qwen3-VL-Flash series (non-thinking mode): qwen3-vl-flash, qwen3-vl-flash-2025-10-15, and later snapshot models

    • QwenVL-Max series: qwen-vl-max (excluding the latest and snapshot versions)

    • QwenVL-Plus series: qwen-vl-plus (excluding the latest and snapshot versions)

  • Open-source multimodal models

    • Qwen3-VL (non-thinking mode)

max_input_tokens integer (Optional)

Specifies the maximum number of input tokens. This parameter is available only for the qwen-plus-0728/latest model.

  • qwen-plus-latest: Default: 129,024

    The default value may be changed to 1,000,000 in the future.
  • qwen-plus-2025-07-28: Default: 1,000,000

This is not a standard OpenAI parameter. When you use the Python SDK, place this parameter in the extra_body object. You can configure the parameter as follows: extra_body={"max_input_tokens": xxx}.

max_tokens integer (Optional)

Specifies the maximum number of tokens to generate. If the output exceeds this limit, generation stops, and the finish_reason field in the response is set to length.

The default and maximum values are the model's maximum output length. For more information, see Model List.

Use this parameter to set the maximum output length for generated content, such as summaries or keywords. This helps reduce costs and shorten response times.

When the max_tokens limit is reached, the value of the response's finish_reason field is length.

For the qwen-vl-ocr model, the max_tokens parameter (maximum output length) defaults to 4096. To increase this value to the 4097–8192 range, send a request by email to [email protected]. Include the following information: your Alibaba Cloud account ID, image type (such as document, E-commerce, or contract images), model name, estimated QPS and total daily requests, and the percentage of requests where the output length is expected to exceed 4096 tokens.
max_tokens does not limit the length of the model's chain-of-thought.

vl_high_resolution_images boolean (Optional) Defaults to false.

Specifies whether to enable the high-resolution mode for images. In this mode, the token limit for a single input image is increased to 16,384 tokens. For more information, see Process high-resolution images.

  • vl_high_resolution_images: true: Uses a fixed resolution policy and ignores the max_pixels setting. If an image exceeds the pixel limit, it is scaled down to fit within the limit.

    Click to view the pixel limits for each model

    When vl_high_resolution_images is set to true, the pixel limits vary by model:

    • For Qwen3-VL series, qwen-vl-max-0813, qwen-vl-plus-0815, and models: 16777216 (Each Token corresponds to 32*32 pixels, and the total pixel count is calculated as 16384*32*32)

    • For QVQ series, Qwen2.5-VL series models: 12845056 (Each Token corresponds to 28*28 pixels, and the total pixel count is calculated as 16384*28*28)

  • When vl_high_resolution_images is set to false, the actual resolution is capped by a pixel limit. This limit is the greater of the max_pixels value and a default value. If an image exceeds this limit, it is scaled down to fit.

    Click to view the default pixel limits for each model

    When vl_high_resolution_images is set to false, the default pixel limits vary by model:

    • For Qwen3-VL series, qwen-vl-max-2025-08-13 and later, qwen-vl-plus-2025-08-15, and : 2621440 (2560*32*32, meaning the default Token limit is 2560)

    • For QVQ series, Qwen2.5-VL series models: 1003520 (1280*28*28, meaning the default Token limit is 1280)

This parameter is not a standard OpenAI parameter. When you use the Python SDK, place this parameter in the extra_body object. You can set the parameter as follows: `extra_body={"vl_high_resolution_images":xxx}`.

n integer (Optional) Defaults to 1.

The number of responses to generate. The value must be in the range of 1-4. This is useful for scenarios that require multiple candidate responses, such as creative writing or ad copy.

This parameter is supported only by the qwen-plus, Qwen3 (non-thinking mode) models.
If you pass the tools parameter, you must set n to 1.
Increasing `n` increases output token usage but does not affect input token usage.

enable_thinking boolean (Optional)

Specifies whether to enable the thinking mode when you use a hybrid thinking model. This parameter applies to the Qwen3, Qwen3-Omni-Flash, and Qwen3-VL models. For more information, see deep thinking.

Valid values:

  • true

    If enabled, the thinking content is returned in the reasoning_content field.
  • false: Disabled

For the default value for each model, see Supported models.

This parameter is not a standard OpenAI parameter. When you use the Python SDK, place this parameter in the extra_body object. For example: extra_body={"enable_thinking": xxx}.

thinking_budget integer (Optional)

The maximum number of tokens for the thinking process. This parameter applies to the commercial and open-source versions of the Qwen3-VL and Qwen3 models. For more information, see Limit the thinking length.

The default value is the maximum chain-of-thought length of the model. For more information, see Model list.

This is not a standard OpenAI parameter. When you use the Python SDK, place this parameter in the extra_body object. The configuration is as follows: extra_body={"thinking_budget": xxx}.

enable_code_interpreter boolean (Optional) Defaults to false.

Specifies whether to enable the Code Interpreter feature. This parameter takes effect only when model is set to qwen3-max-preview and enable_thinking is set to true. For more information, see Code Interpreter.

Valid values:

  • true

  • false: Disabled

This parameter is not a standard OpenAI parameter. When you make calls with the Python SDK, place this parameter in the extra_body object. Example configuration: extra_body={"enable_code_interpreter": xxx}.

seed integer (Optional)

The random number seed. It ensures that results are reproducible for the same input and parameters. If you use the same seed value and other parameters in a call, the model attempts to return the same result.

Valid values: [0,2<sup>31</sup>−1].

logprobs boolean (Optional) Defaults to false.

Specifies whether to return the log probabilities of output tokens. Valid values:

  • true

    Back

  • false

    No return value

The content generated during the reasoning phase (reasoning_content) does not return log probabilities.

Supported models

  • qwen-plus series snapshot models (excluding mainline models)

  • qwen-turbo series snapshot models (excluding mainline models)

  • qwen-vl-ocr models

  • Qwen3 open-source models

top_logprobs integer (Optional) Defaults to 0.

The number of most likely candidate tokens to return at each token position.

Range: [0, 5]

This parameter is effective only when logprobs is true.

stop string or array (Optional)

Specifies the stop words. When the model generates a string or a token_id specified in stop, generation stops immediately.

You can pass sensitive words to control the model's output.

If `stop` is an array, do not include both token_id values and strings as elements. For example, ["Hello",104307] is an invalid value.

tools array (Optional)

An array of one or more tool objects for the model to call in Function Calling. For more information, see Function Calling.

If `tools` is set and the model decides to call a tool, the response returns tool information in the `tool_calls` field.

Properties

type string (Required)

The tool type. The only supported value is function.

function object (Required)

Properties

name string (Required)

The name of the tool. The name can contain only letters, digits, underscores (_), and hyphens (-). The maximum length is 64 characters.

description string (Required)

A description of the tool. This description helps the model determine when and how to call the tool.

parameters object (Required)

The parameters for the tool, which must be a valid JSON Schema object. For more information about JSON Schema, see this link. If the parameters parameter is empty, the tool has no input parameters (such as a time query tool).

tool_choice string or object (Optional) Defaults to auto.

The tool selection policy. You can set this parameter to force a specific tool calling method, such as always using a specific tool or disabling all tools.

Valid values:

  • auto

    The model decides whether to call a tool and which tool to call.

  • none

    To disable tool calling, set the tool_choice parameter to none.

  • {"type": "function", "function": {"name": "the_function_to_call"}}

    To force a call to a specific tool, set the tool_choice parameter to {"type": "function", "function": {"name": "the_function_to_call"}}, where the_function_to_call is the name of the specified tool function.

    Models in thinking mode do not support forcing a call to a specific tool.

parallel_tool_calls boolean (Optional) The default is false.

Specifies whether to enable parallel tool calling. For more information, see parallel tool calling.

Valid values:

  • true

  • false: Disabled

enable_search boolean (Optional) Defaults to false.

Specifies whether to enable web search. For more information, see Web search.

Valid values:

  • true: Enabled.

    If web search is not triggered, you can optimize the prompt or set the forced_search parameter in search_options to enable forced search.
  • false: Disabled.

Enabling web search may increase token consumption.
This is not a standard OpenAI parameter. When you use the Python SDK, place this parameter in the extra_body object. Example configuration: extra_body={"enable_search": True}.

search_options object (Optional)

The policy for web search. For more information, see Web search.

Properties

forced_search boolean (Optional) Default: false.

Specifies whether to force web search. This parameter takes effect only if enable_search is set to true.

Valid values:

  • true: Forcibly enabled.

  • false: Does not force web search. The model decides whether to perform a web search.

search_strategy string (Optional) Default: turbo.

The search strategy. This parameter takes effect only if enable_search is set to true.

Valid values:

  • turbo (Default): Balances response time and search effectiveness. This policy is suitable for most scenarios.

  • max: Uses a more comprehensive search policy. This policy can invoke multiple search engine sources to retrieve more detailed search results, but may increase the response time.

  • agent: Makes multiple calls to the web search tool and the large language model to perform multi-round information retrieval and content integration.

    agent policy applies only to qwen3-max and qwen3-max-2025-09-23.
    agent policy cannot be set with other web search policies.

enable_search_extension boolean (Optional) Default: false.

Specifies whether to enable domain-specific search. This parameter takes effect only if enable_search is set to true.

Valid values:

  • true: Enabled.

  • false: Disabled.

This parameter is not a standard OpenAI parameter. When you use the Python SDK, place this parameter in the extra_body object. The configuration is as follows: extra_body={"search_options": xxx}.

Chat response object (non-streaming output)

{
    "choices": [
        {
            "message": {
                "role": "assistant",
                "content": "I am a large-scale language model developed by Alibaba Cloud. My name is Qwen."
            },
            "finish_reason": "stop",
            "index": 0,
            "logprobs": null
        }
    ],
    "object": "chat.completion",
    "usage": {
        "prompt_tokens": 3019,
        "completion_tokens": 104,
        "total_tokens": 3123,
        "prompt_tokens_details": {
            "cached_tokens": 2048
        }
    },
    "created": 1735120033,
    "system_fingerprint": null,
    "model": "qwen-plus",
    "id": "chatcmpl-6ada9ed2-7f33-9de2-8bb0-78bd4035025a"
}

id string

The unique identifier for this call.

choices array

An array of content that the model generates.

Properties

finish_reason string

The reason the model stopped generating content.

The following three situations can occur:

  • The value is stop if the stop input parameter is triggered or if the output stops naturally.

  • The value is length if the generation stops because the output is too long.

  • The value is tool_calls if the generation stops because a tool needs to be called.

index integer

The index of the current object in the choices array.

logprobs object

The probability information for the tokens in the model output.

Properties

content array

An array that contains each token and its log probability.

Properties

token string

The text of the current token.

bytes array

A list of the raw UTF-8 bytes for the current token. This list is used to accurately restore the output content, such as emojis or Chinese characters.

logprob float

The log probability of the current token. A return value of null indicates an extremely low probability.

top_logprobs array

A list of the most likely candidate tokens at the current token's position. The number of candidates is the same as the value of the top_logprobs request parameter. Each element contains:

Properties

token string

The text of the candidate token.

bytes array

A list of the raw UTF-8 bytes for the current token. This list is used to accurately restore the output content, such as emojis or Chinese characters.

logprob float

The log probability of this candidate token. A return value of null indicates an extremely low probability.

message object

The message that the model outputs.

Properties

content string

The content of the model's response.

reasoning_content string

The chain-of-thought content from the model.

refusal string

This parameter is currently fixed to null.

role string

The role of the message. The value is fixed to assistant.

audio object

This parameter is currently fixed to null.

function_call (deprecated) object

This parameter is deprecated and its value is fixed to null. For more information, see the tool_calls parameter.

tool_calls array

The tool and input parameters that the model generates after a function call is initiated.

Properties

id string

The unique identifier for this tool call.

type string

The type of the tool. Currently, only function is supported.

function object

The tool information.

Properties

name string

The name of the tool.

arguments string

The input parameter information, which is a JSON-formatted string.

Because large model responses have a degree of randomness, the output parameters might not match the function signature. You must validate the parameters before calling the function.

index integer

The index of the current tool in the tool_calls array.

created integer

The UNIX timestamp in seconds when the request was created.

model string

The model used for this request.

object string

The value is always chat.completion.

service_tier string

This parameter is currently fixed to null.

system_fingerprint string

This parameter is currently fixed to null.

usage object

Information about the token consumption for this request.

Properties

completion_tokens integer

The number of tokens in the model output.

prompt_tokens integer

The number of tokens in the input.

total_tokens integer

The total number of tokens consumed. This is the sum of prompt_tokens and completion_tokens.

completion_tokens_details object

A fine-grained categorization of the output tokens when you use the Qwen-VL model.

Properties

audio_tokens integer

This parameter is currently fixed to null.

reasoning_tokens integer

This parameter is currently fixed to null.

text_tokens integer

The number of text tokens in the output from the Qwen-VL model.

prompt_tokens_details object

A fine-grained categorization of the input tokens.

Properties

audio_tokens integer

This parameter is currently fixed to null.

cached_tokens integer

The number of tokens that hit the cache. For more information, see Context cache.

text_tokens integer

The number of text tokens in the input for the Qwen-VL model.

image_tokens integer

The number of image tokens in the input for the Qwen-VL model.

video_tokens integer

The number of tokens for the input video file or image list for the Qwen-VL model.

cache_creation object

Information about the creation of an explicit cache.

Properties

ephemeral_5m_input_tokens integer

The number of tokens used to create the explicit cache.

cache_creation_input_tokens integer

The number of tokens used to create the explicit cache.

cache_type string

When an explicit cache is used, the value of this parameter is ephemeral. Otherwise, this parameter is not returned.

Chat response chunk object (streaming output)

{"id":"chatcmpl-e30f5ae7-3063-93c4-90fe-beb5f900bd57","choices":[{"delta":{"content":"","function_call":null,"refusal":null,"role":"assistant","tool_calls":null},"finish_reason":null,"index":0,"logprobs":null}],"created":1735113344,"model":"qwen-plus","object":"chat.completion.chunk","service_tier":null,"system_fingerprint":null,"usage":null}
{"id":"chatcmpl-e30f5ae7-3063-93c4-90fe-beb5f900bd57","choices":[{"delta":{"content":"I am","function_call":null,"refusal":null,"role":null,"tool_calls":null},"finish_reason":null,"index":0,"logprobs":null}],"created":1735113344,"model":"qwen-plus","object":"chat.completion.chunk","service_tier":null,"system_fingerprint":null,"usage":null}
{"id":"chatcmpl-e30f5ae7-3063-93c4-90fe-beb5f900bd57","choices":[{"delta":{"content":" a large-scale","function_call":null,"refusal":null,"role":null,"tool_calls":null},"finish_reason":null,"index":0,"logprobs":null}],"created":1735113344,"model":"qwen-plus","object":"chat.completion.chunk","service_tier":null,"system_fingerprint":null,"usage":null}
{"id":"chatcmpl-e30f5ae7-3063-93c4-90fe-beb5f900bd57","choices":[{"delta":{"content":" language","function_call":null,"refusal":null,"role":null,"tool_calls":null},"finish_reason":null,"index":0,"logprobs":null}],"created":1735113344,"model":"qwen-plus","object":"chat.completion.chunk","service_tier":null,"system_fingerprint":null,"usage":null}
{"id":"chatcmpl-e30f5ae7-3063-93c4-90fe-beb5f900bd57","choices":[{"delta":{"content":" model from Alibaba","function_call":null,"refusal":null,"role":null,"tool_calls":null},"finish_reason":null,"index":0,"logprobs":null}],"created":1735113344,"model":"qwen-plus","object":"chat.completion.chunk","service_tier":null,"system_fingerprint":null,"usage":null}
{"id":"chatcmpl-e30f5ae7-3063-93c4-90fe-beb5f900bd57","choices":[{"delta":{"content":" Cloud. My","function_call":null,"refusal":null,"role":null,"tool_calls":null},"finish_reason":null,"index":0,"logprobs":null}],"created":1735113344,"model":"qwen-plus","object":"chat.completion.chunk","service_tier":null,"system_fingerprint":null,"usage":null}
{"id":"chatcmpl-e30f5ae7-3063-93c4-90fe-beb5f900bd57","choices":[{"delta":{"content":" name is Tongyi","function_call":null,"refusal":null,"role":null,"tool_calls":null},"finish_reason":null,"index":0,"logprobs":null}],"created":1735113344,"model":"qwen-plus","object":"chat.completion.chunk","service_tier":null,"system_fingerprint":null,"usage":null}
{"id":"chatcmpl-e30f5ae7-3063-93c4-90fe-beb5f900bd57","choices":[{"delta":{"content":" Qian","function_call":null,"refusal":null,"role":null,"tool_calls":null},"finish_reason":null,"index":0,"logprobs":null}],"created":1735113344,"model":"qwen-plus","object":"chat.completion.chunk","service_tier":null,"system_fingerprint":null,"usage":null}
{"id":"chatcmpl-e30f5ae7-3063-93c4-90fe-beb5f900bd57","choices":[{"delta":{"content":"wen.","function_call":null,"refusal":null,"role":null,"tool_calls":null},"finish_reason":null,"index":0,"logprobs":null}],"created":1735113344,"model":"qwen-plus","object":"chat.completion.chunk","service_tier":null,"system_fingerprint":null,"usage":null}
{"id":"chatcmpl-e30f5ae7-3063-93c4-90fe-beb5f900bd57","choices":[{"delta":{"content":"","function_call":null,"refusal":null,"role":null,"tool_calls":null},"finish_reason":"stop","index":0,"logprobs":null}],"created":1735113344,"model":"qwen-plus","object":"chat.completion.chunk","service_tier":null,"system_fingerprint":null,"usage":null}
{"id":"chatcmpl-e30f5ae7-3063-93c4-90fe-beb5f900bd57","choices":[],"created":1735113344,"model":"qwen-plus","object":"chat.completion.chunk","service_tier":null,"system_fingerprint":null,"usage":{"completion_tokens":17,"prompt_tokens":22,"total_tokens":39,"completion_tokens_details":null,"prompt_tokens_details":{"audio_tokens":null,"cached_tokens":0}}}

id string

The unique identifier for this call. Each chunk object has the same ID.

choices array

An array of content generated by the model. This array can contain one or more objects. If the include_usage parameter is set to true, the choices array is empty in the last chunk.

Properties

delta object

The incremental message object.

Properties

content string

The incremental message content.

reasoning_content string

The incremental chain-of-thought content.

function_call object

This value is null by default. For more information, see the tool_calls parameter.

audio object

The response generated when you use the Qwen-Omni model.

Properties

transcript string

The incremental text content.

data string

The incremental Base64-encoded audio data.

expires_at integer

The UNIX timestamp when the request was created.

refusal object

This parameter is always set to null.

role string

The role of the incremental message object. This property has a value only in the first chunk.

tool_calls array

The information about the tool and input parameters that the model generates after a function call is initiated.

Properties

index integer

The index of the current tool in the tool_calls array.

id string

The unique identifier for this tool response.

function object

Information about the invoked tool.

Properties

arguments string

The incremental input parameter information. You can concatenate the arguments from all chunks to obtain the complete input parameters.

Because the model's response can be random, the output arguments might not match the function signature. Verify the parameter validity before making the call.

name string

The name of the tool. This property has a value only in the first chunk.

type string

The type of the tool. Currently, only function is supported.

finish_reason string

The reason why the model stopped generating content. The possible values are:

  • stop: The generation stopped naturally or because it hit a stop sequence that you specified in the stop parameter.

  • null: The generation is not yet finished.

  • length: The generation stopped because it reached the maximum length.

  • tool_calls: The generation stopped because it needs to call a tool.

index integer

The index of the current response in the choices array. If the n input parameter is greater than 1, you can use this parameter to concatenate the complete content for each response.

logprobs object

The probability information for the current object.

Properties

content array

An array of tokens with log probability information.

Properties

token string

The current token.

bytes array

A list of the raw UTF-8 bytes for the current token. This helps accurately reconstruct the output, especially when handling emojis and Chinese characters.

logprob float

The log probability of the current token. A null return value indicates an extremely low probability.

top_logprobs array

The most likely tokens at the current token's position and their log probabilities. The number of elements matches the top_logprobs input parameter.

Properties

token string

The current token.

bytes array

A list of the raw UTF-8 bytes for the current token. This helps accurately reconstruct the output, especially when handling emojis and Chinese characters.

logprob float

The log probability of the current token. A null return value indicates an extremely low probability.

created integer

The UNIX timestamp that indicates when the request was created. Each chunk has the same timestamp.

model string

The model used for this request.

object string

The value is fixed to chat.completion.chunk.

service_tier string

The value is null.

system_fingerprint string

The value of this parameter is currently null.

usage object

The number of tokens consumed by the request. This property is returned only in the last chunk if include_usage is set to true.

Properties

completion_tokens integer

The number of tokens in the model output.

prompt_tokens integer

The number of input tokens.

total_tokens integer

The total number of tokens. This is the sum of prompt_tokens and completion_tokens.

completion_tokens_details object

The details about the output tokens.

Properties

audio_tokens integer

The number of audio tokens in the output from the Qwen-Omni model.

reasoning_tokens integer

The number of chain-of-thought tokens.

text_tokens integer

The number of output text tokens.

prompt_tokens_details object

A detailed breakdown of the input tokens.

Properties

audio_tokens integer

The number of input audio tokens.

The number of audio tokens from an input video file is also returned in this parameter.

text_tokens integer

The number of input text tokens.

video_tokens integer

The number of tokens for the input video. The input video can be an image list or a video file.

image_tokens integer

The number of input image tokens.

cached_tokens integer

The number of tokens that hit the cache. For more information about Context Cache, see Context Cache.

cache_creation object

Information about explicit cache creation.

Properties

ephemeral_5m_input_tokens integer

The number of tokens used to create the explicit cache.

cache_creation_input_tokens integer

The number of tokens used to create the explicit cache.

cache_type string

The cache type. The value is always ephemeral.

DashScope

Singapore region

HTTP request endpoint:

  • Qwen large language model: POST https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/text-generation/generation

  • Qwen-VL/OCR model: POST https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation

The base_url for SDK calls:

Python code

dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'

Java code

  • Method 1:

    import com.alibaba.dashscope.protocol.Protocol;
    Generation gen = new Generation(Protocol.HTTP.getValue(), "https://dashscope-intl.aliyuncs.com/api/v1");
  • Method 2:

    import com.alibaba.dashscope.utils.Constants;
    Constants.baseHttpApiUrl="https://dashscope-intl.aliyuncs.com/api/v1";

Beijing region

HTTP request endpoint:

  • Qwen large language model: POST https://dashscope.aliyuncs.com/api/v1/services/aigc/text-generation/generation

  • Qwen-VL/Audio model: POST https://dashscope.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation

SDK calls do not require a base_url configuration.

You must obtain and configure an API key and export the API key as an environment variable (This step is scheduled for deprecation and will be merged into the API key configuration guide). If you make calls using the DashScope SDK, you must install the DashScope SDK.

Request body

Text input

Python

import os
import dashscope

dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
# The preceding URL is the base URL for the Singapore region. If you use a model in the China (Beijing) region, replace the base URL with: https://dashscope.aliyuncs.com/api/v1
messages = [
    {'role': 'system', 'content': 'You are a helpful assistant.'},
    {'role': 'user', 'content': 'Who are you?'}
]
response = dashscope.Generation.call(
    # If the environment variable is not configured, replace the following line with your Model Studio API key: api_key="sk-xxx"
    # The API keys for the Singapore and Beijing regions are different. To get an API key, see https://www.alibabacloud.com/help/en/model-studio/get-api-key.
    api_key=os.getenv('DASHSCOPE_API_KEY'),
    model="qwen-plus", # This example uses qwen-plus. You can replace it with another model name as needed. For a list of models, see https://www.alibabacloud.com/help/en/model-studio/getting-started/models.
    messages=messages,
    result_format='message'
    )
print(response)

Java

// Use DashScope SDK version 2.12.0 or later.
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;
import com.alibaba.dashscope.protocol.Protocol;

public class Main {
    public static GenerationResult callWithMessage() throws ApiException, NoApiKeyException, InputRequiredException {
        Generation gen = new Generation(Protocol.HTTP.getValue(), "https://dashscope-intl.aliyuncs.com/api/v1");
        // The preceding URL is the base URL for the Singapore region. If you use a model in the China (Beijing) region, replace the base URL with: https://dashscope.aliyuncs.com/api/v1
        Message systemMsg = Message.builder()
                .role(Role.SYSTEM.getValue())
                .content("You are a helpful assistant.")
                .build();
        Message userMsg = Message.builder()
                .role(Role.USER.getValue())
                .content("Who are you?")
                .build();
        GenerationParam param = GenerationParam.builder()
                // If the environment variable is not configured, replace the following line with your Model Studio API key: .apiKey("sk-xxx")
                // The API keys for the Singapore and Beijing regions are different. To get an API key, see https://www.alibabacloud.com/help/en/model-studio/get-api-key.
                .apiKey(System.getenv("DASHSCOPE_API_KEY"))
                // This example uses qwen-plus. You can replace it with another model name as needed. For a list of models, see https://www.alibabacloud.com/help/en/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) {
            // Use a logging framework to record the exception information.
            System.err.println("An error occurred while calling the generation service: " + e.getMessage());
        }
        System.exit(0);
    }
}

PHP (HTTP)

<?php
// The following URL is for the Singapore region. If you use a model in the China (Beijing) region, replace the URL with: https://dashscope.aliyuncs.com/api/v1/services/aigc/text-generation/generation
$url = "https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/text-generation/generation";
// The API keys for the Singapore and Beijing regions are different. To get an API key, see https://www.alibabacloud.com/help/en/model-studio/get-api-key.
$apiKey = getenv('DASHSCOPE_API_KEY');

$data = [
    // This example uses qwen-plus. You can replace it with another model name as needed. For a list of models, see https://www.alibabacloud.com/help/en/model-studio/getting-started/models.
    "model" => "qwen-plus",
    "input" => [
        "messages" => [
            [
                "role" => "system",
                "content" => "You are a helpful assistant."
            ],
            [
                "role" => "user",
                "content" => "Who are you?"
            ]
        ]
    ],
    "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 does not provide an SDK for the Node.js environment. To make calls using the OpenAI Node.js SDK, see the OpenAI section in this topic.

import fetch from 'node-fetch';
// The API keys for the Singapore and Beijing regions are different. To get an API key, see https://www.alibabacloud.com/help/en/model-studio/get-api-key.
const apiKey = process.env.DASHSCOPE_API_KEY;

const data = {
    model: "qwen-plus", // This example uses qwen-plus. You can replace it with another model name as needed. For a list of models, see https://www.alibabacloud.com/help/en/model-studio/getting-started/models.
    input: {
        messages: [
            {
                role: "system",
                content: "You are a helpful assistant."
            },
            {
                role: "user",
                content: "Who are you?"
            }
        ]
    },
    parameters: {
        result_format: "message"
    }
};

fetch('https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/text-generation/generation', {
// The preceding URL is for the Singapore region. If you use a model in the China (Beijing) region, replace the URL with: 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)
    {
        // If the environment variable is not configured, replace the following line with your Model Studio API key: string? apiKey = "sk-xxx";
        // The API keys for the Singapore and Beijing regions are different. To get an API key, see https://www.alibabacloud.com/help/en/model-studio/get-api-key.
        string? apiKey = Environment.GetEnvironmentVariable("DASHSCOPE_API_KEY");

        if (string.IsNullOrEmpty(apiKey))
        {
            Console.WriteLine("API key not set. Make sure the 'DASHSCOPE_API_KEY' environment variable is set.");
            return;
        }

        // Set the request URL and content.
        // The following is the base URL for the Singapore region. If you use a model in the China (Beijing) region, replace the base URL with: https://dashscope.aliyuncs.com/api/v1/services/aigc/text-generation/generation
        string url = "https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/text-generation/generation";
        // This example uses qwen-plus. You can replace it with another model name as needed. For a list of models, see https://www.alibabacloud.com/help/en/model-studio/getting-started/models.
        string jsonContent = @"{
            ""model"": ""qwen-plus"", 
            ""input"": {
                ""messages"": [
                    {
                        ""role"": ""system"",
                        ""content"": ""You are a helpful assistant.""
                    },
                    {
                        ""role"": ""user"",
                        ""content"": ""Who are you?""
                    }
                ]
            },
            ""parameters"": {
                ""result_format"": ""message""
            }
        }";

        // Send the request and get the response.
        string result = await SendPostRequestAsync(url, jsonContent, apiKey);

        // Print the result.
        Console.WriteLine(result);
    }

    private static async Task<string> SendPostRequestAsync(string url, string jsonContent, string apiKey)
    {
        using (var content = new StringContent(jsonContent, Encoding.UTF8, "application/json"))
        {
            // Set the request headers.
            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);
            httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            // Send the request and get the response.
            HttpResponseMessage response = await httpClient.PostAsync(url, content);

            // Process the response.
            if (response.IsSuccessStatusCode)
            {
                return await response.Content.ReadAsStringAsync();
            }
            else
            {
                return $"Request failed: {response.StatusCode}";
            }
        }
    }
}

Go (HTTP)

DashScope does not provide an SDK for Go. To make calls with the OpenAI Go SDK, refer to the OpenAI-Go section of this topic.

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() {
	// Create an HTTP client.
	client := &http.Client{}

	// Build the request body.
	requestBody := RequestBody{
		// This example uses qwen-plus. You can replace it with another model name as needed. For a list of models, see https://www.alibabacloud.com/help/en/model-studio/getting-started/models.
		Model: "qwen-plus",
		Input: Input{
			Messages: []Message{
				{
					Role:    "system",
					Content: "You are a helpful assistant.",
				},
				{
					Role:    "user",
					Content: "Who are you?",
				},
			},
		},
		Parameters: Parameters{
			ResultFormat: "message",
		},
	}

	jsonData, err := json.Marshal(requestBody)
	if err != nil {
		log.Fatal(err)
	}

	// Create a POST request.
	// The following is the base URL for the Singapore region. If you use a model in the China (Beijing) region, replace the base URL with: https://dashscope.aliyuncs.com/api/v1/services/aigc/text-generation/generation
	req, err := http.NewRequest("POST", "https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/text-generation/generation", bytes.NewBuffer(jsonData))
	if err != nil {
		log.Fatal(err)
	}

	// Set the request headers.
	// If the environment variable is not configured, replace the following line with your Model Studio API key: apiKey := "sk-xxx"
	// The API keys for the Singapore and Beijing regions are different. To get an API key, see https://www.alibabacloud.com/help/en/model-studio/get-api-key.
	apiKey := os.Getenv("DASHSCOPE_API_KEY")
	req.Header.Set("Authorization", "Bearer "+apiKey)
	req.Header.Set("Content-Type", "application/json")

	// Send the request.
	resp, err := client.Do(req)
	if err != nil {
		log.Fatal(err)
	}
	defer resp.Body.Close()

	// Read the response body.
	bodyText, err := io.ReadAll(resp.Body)
	if err != nil {
		log.Fatal(err)
	}

	// Print the response content.
	fmt.Printf("%s\n", bodyText)
}

curl

Note that the API keys for the Singapore and Beijing regions are different. For more information, see Preparations: Obtain and configure an API key
The following example uses the URL for the Singapore region. If you use a model in the China (Beijing) region, replace the URL with the following: https://dashscope.aliyuncs.com/api/v1/services/aigc/text-generation/generation.
curl --location "https://dashscope-intl.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": "Who are you?"
            }
        ]
    },
    "parameters": {
        "result_format": "message"
    }
}'

Streaming output

For more information, see Streaming output.

Python

import os
import dashscope

# The following is the base URL for the Singapore region. If you use a model in the China (Beijing) region, replace the base URL with: https://dashscope.aliyuncs.com/api/v1
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
messages = [
    {'role':'system','content':'you are a helpful assistant'},
    {'role': 'user','content': 'Who are you?'}
]
responses = dashscope.Generation.call(
    # If the environment variable is not configured, replace the following line with your Model Studio API key: api_key="sk-xxx"
    # The API keys for the Singapore and Beijing regions are different. To get an API key, see https://www.alibabacloud.com/help/en/model-studio/get-api-key.
    api_key=os.getenv('DASHSCOPE_API_KEY'),
    # This example uses qwen-plus. You can replace it with another model name as needed. For a list of models, see https://www.alibabacloud.com/help/en/model-studio/getting-started/models.
    model="qwen-plus",
    messages=messages,
    result_format='message',
    stream=True,
    incremental_output=True
    )
for response in responses:
    print(response)  

Java

import 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;
import com.alibaba.dashscope.protocol.Protocol;

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<GenerationResult> result = gen.streamCall(param);
        result.blockingForEach(message -> handleGenerationResult(message));
    }
    private static GenerationParam buildGenerationParam(Message userMsg) {
        return GenerationParam.builder()
                // If the environment variable is not configured, replace the following line with your Model Studio API key: .apiKey("sk-xxx")
                // The API keys for the Singapore and Beijing regions are different. To get an API key, see https://www.alibabacloud.com/help/en/model-studio/get-api-key.
                .apiKey(System.getenv("DASHSCOPE_API_KEY"))
                // This example uses qwen-plus. You can replace it with another model name as needed. For a list of models, see https://www.alibabacloud.com/help/en/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 {
            // The following URL is for the Singapore region. If you use a model in the China (Beijing) region, replace the URL with: https://dashscope.aliyuncs.com/api/v1
            Generation gen = new Generation(Protocol.HTTP.getValue(), "https://dashscope-intl.aliyuncs.com/api/v1");
            Message userMsg = Message.builder().role(Role.USER.getValue()).content("Who are you?").build();
            streamCallWithMessage(gen, userMsg);
        } catch (ApiException | NoApiKeyException | InputRequiredException  e) {
            logger.error("An exception occurred: {}", e.getMessage());
        }
        System.exit(0);
    }
}

curl

# ======= Important =======
# The following is the base URL for the Singapore region. If you use a model in the China (Beijing) region, replace the base URL with: https://dashscope.aliyuncs.com/api/v1/services/aigc/text-generation/generation
# === Delete this comment before execution ====

curl --location "https://dashscope-intl.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": "Who are you?"
            }
        ]
    },
    "parameters": {
        "result_format": "message",
        "incremental_output":true
    }
}'

Image input

For more information about using large models to analyze images, see Visual understanding.

Python

import os
import dashscope

# The following is the base URL for the Singapore region. If you use a model in the China (Beijing) region, replace the base URL with: https://dashscope.aliyuncs.com/api/v1
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'  
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": "What are these?"}
        ]
    }
]
response = dashscope.MultiModalConversation.call(
    # The API keys for the Singapore and Beijing regions are different. To get an API key, see https://www.alibabacloud.com/help/en/model-studio/get-api-key.
    # The following is the base URL for the Singapore region. If you use a model in the China (Beijing) region, replace the base URL with: https://dashscope.aliyuncs.com/api/v1/services/aigc/text-generation/generation
    api_key=os.getenv('DASHSCOPE_API_KEY'),
    # This example uses qwen-vl-max. You can replace it with another model name as needed. For a list of models, see https://www.alibabacloud.com/help/en/model-studio/getting-started/models.
    model='qwen-vl-max',
    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;
import com.alibaba.dashscope.utils.Constants;
public class Main {
    static {
     Constants.baseHttpApiUrl="https://dashscope-intl.aliyuncs.com/api/v1";  // The following is the base URL for the Singapore region. If you use a model in the China (Beijing) region, replace the base URL with: https://dashscope.aliyuncs.com/api/v1;
    }
    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", "What are these?"))).build();
        MultiModalConversationParam param = MultiModalConversationParam.builder()
                // If the environment variable is not configured, replace the following line with your Model Studio API key: .apiKey("sk-xxx")
                // The following is the base URL for the Singapore region. If you use a model in the China (Beijing) region, replace the base URL with: https://dashscope.aliyuncs.com/api/v1/services/aigc/text-generation/generation
                .apiKey(System.getenv("DASHSCOPE_API_KEY"))
                // This example uses qwen-vl-plus. You can replace it with another model name as needed. For a list of models, see https://www.alibabacloud.com/help/en/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);
    }
}

curl

API keys are different for the Singapore and Beijing regions. For more information, see Preparations: Obtain and configure an API key
The following URL is for the Singapore region. If you use a model in the China (Beijing) region, replace the URL with the following: https://dashscope.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation
curl --location 'https://dashscope-intl.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": "What are these?"}
                ]
            }
        ]
    }
}'

Video input

The following code shows an example of how to input video frames. For more information, such as how to input video files, see Visual understanding.

Python

import os
# DashScope SDK version 1.20.10 or later is required.
import dashscope
# The following is the base URL for the Singapore region. If you use a model in the China (Beijing) region, replace the base URL with: https://dashscope.aliyuncs.com/api/v1
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
messages = [{"role": "user",
             "content": [
                  # If the model is from the Qwen2.5-VL series and an image list is provided, you can set the fps parameter. This indicates that the image list is extracted from the original video every 1/fps seconds.
                 {"video":["https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241108/xzsgiz/football1.jpg",
                           "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241108/tdescd/football2.jpg",
                           "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241108/zefdja/football3.jpg",
                           "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241108/aedbqh/football4.jpg"],
                   "fps":2},
                 {"text": "Describe the specific process in this video"}]}]
response = dashscope.MultiModalConversation.call(
    # If the environment variable is not configured, replace the following line with your Model Studio API key: api_key="sk-xxx"
    # The API keys for the Singapore and Beijing regions are different. To get an API key, see https://www.alibabacloud.com/help/en/model-studio/get-api-key.
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    model='qwen2.5-vl-72b-instruct',  # This example uses qwen2.5-vl-72b-instruct. You can replace it with another model name as needed. For a list of models, see https://www.alibabacloud.com/help/en/model-studio/models.
    messages=messages
)
print(response["output"]["choices"][0]["message"].content[0]["text"])

Java

// DashScope SDK version 2.18.3 or later is required.
import java.util.Arrays;
import java.util.Collections;
import java.util.Map;

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.Constants;

public class Main {
    static {
         // The following is the base URL for the Singapore region. If you use a model in the China (Beijing) region, replace the base URL with: https://dashscope.aliyuncs.com/api/v1
        Constants.baseHttpApiUrl="https://dashscope-intl.aliyuncs.com/api/v1";
    }
    private static final String MODEL_NAME = "qwen2.5-vl-72b-instruct"; // This example uses qwen2.5-vl-72b-instruct. You can replace it with another model name as needed. For a list of models, see https://www.alibabacloud.com/help/en/model-studio/models.
    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();
        //  If the model is from the Qwen2.5-VL series and an image list is provided, you can set the fps parameter. This indicates that the image list is extracted from the original video every 1/fps seconds.
        Map<String, Object> params = Map.of(
                "video", Arrays.asList("https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241108/xzsgiz/football1.jpg",
                        "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241108/tdescd/football2.jpg",
                        "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241108/zefdja/football3.jpg",
                        "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241108/aedbqh/football4.jpg"),
                "fps",2);
        MultiModalMessage userMessage = MultiModalMessage.builder()
                .role(Role.USER.getValue())
                .content(Arrays.asList(
                        params,
                        Collections.singletonMap("text", "Describe the specific process in this video")))
                .build();
        MultiModalConversationParam param = MultiModalConversationParam.builder()
                // If the environment variable is not configured, replace the following line with your Model Studio API key: .apiKey("sk-xxx")
                // The API keys for the Singapore and Beijing regions are different. To get an API key, see https://www.alibabacloud.com/help/en/model-studio/get-api-key.
                .apiKey(System.getenv("DASHSCOPE_API_KEY"))
                .model(MODEL_NAME)
                .messages(Arrays.asList(systemMessage, userMessage)).build();
        MultiModalConversationResult result = conv.call(param);
        System.out.print(result.getOutput().getChoices().get(0).getMessage().getContent().get(0).get("text"));
    }
    public static void main(String[] args) {
        try {
            videoImageListSample();
        } catch (ApiException | NoApiKeyException | UploadFileException e) {
            System.out.println(e.getMessage());
        }
        System.exit(0);
    }
}

curl

The API keys for the Singapore and Beijing regions are different. For more information, see Preparations: Obtain and configure an API key
The following URL is for the Singapore region. If you use a model in the China (Beijing) region, replace the URL with the following: https://dashscope.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation
curl -X POST https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
  "model": "qwen2.5-vl-72b-instruct",
  "input": {
    "messages": [
      {
        "role": "user",
        "content": [
          {
            "video": [
              "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241108/xzsgiz/football1.jpg",
              "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241108/tdescd/football2.jpg",
              "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241108/zefdja/football3.jpg",
              "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241108/aedbqh/football4.jpg"
            ],
            "fps":2
                 
          },
          {
            "text": "Describe the specific process in this video"
          }
        ]
      }
    ]
  }
}'

Tool calling

For the complete Function calling workflow code, see Overview of text generation models.

Python

import os
import dashscope
  # The following is the base URL for the Singapore region. If you use a model in the China (Beijing) region, replace the base URL with: https://dashscope.aliyuncs.com/api/v1
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
tools = [
    {
        "type": "function",
        "function": {
            "name": "get_current_time",
            "description": "Useful when you want to know the current time.",
            "parameters": {}
        }
    },
    {
        "type": "function",
        "function": {
            "name": "get_current_weather",
            "description": "Useful when you want to query the weather in a specific city.",
            "parameters": {
                "type": "object",
                "properties": {
                    "location": {
                        "type": "string",
                        "description": "A city or district, such as Beijing, Hangzhou, or Yuhang District."
                    }
                }
            },
            "required": [
                "location"
            ]
        }
    }
]
messages = [{"role": "user", "content": "What's the weather like in Hangzhou?"}]
response = dashscope.Generation.call(
    # If the environment variable is not configured, replace the following line with your Model Studio API key: api_key="sk-xxx"
    # The API keys for the Singapore and Beijing regions are different. To get an API key, see https://www.alibabacloud.com/help/en/model-studio/get-api-key.
    api_key=os.getenv('DASHSCOPE_API_KEY'),
    # This example uses qwen-plus. You can replace it with another model name as needed. For a list of models, see https://www.alibabacloud.com/help/en/model-studio/getting-started/models.
    model='qwen-plus',
    messages=messages,
    tools=tools,
    result_format='message'
)
print(response)

Java

import 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;
import com.alibaba.dashscope.protocol.Protocol;

public class Main {
    public class GetWeatherTool {
        private String location;
        public GetWeatherTool(String location) {
            this.location = location;
        }
        public String call() {
            return location+" is sunny today.";
        }
    }
    public class GetTimeTool {
        public GetTimeTool() {
        }
        public String call() {
            LocalDateTime now = LocalDateTime.now();
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
            String currentTime = "Current time: " + 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("Get the weather for a specified region")
                .parameters(JsonUtils.parseString(jsonSchema_weather.toString()).getAsJsonObject()).build();
        FunctionDefinition fdTime = FunctionDefinition.builder().name("get_current_time").description("Get the current time")
                .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("Weather in Hangzhou").build();
        List<Message> messages = new ArrayList<>();
        messages.addAll(Arrays.asList(systemMsg, userMsg));
        GenerationParam param = GenerationParam.builder()
                // The API keys for the Singapore and Beijing regions are different. To get an API key, see https://www.alibabacloud.com/help/en/model-studio/get-api-key.
                .apiKey(System.getenv("DASHSCOPE_API_KEY"))
                // This example uses qwen-plus. You can replace it with another model name as needed. For a list of models, see https://www.alibabacloud.com/help/en/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(Protocol.HTTP.getValue(), "https://dashscope-intl.aliyuncs.com/api/v1");
        // The preceding URL is the base URL for the Singapore region. If you use a model in the China (Beijing) region, replace the base URL with: https://dashscope.aliyuncs.com/api/v1
        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);
    }
}

curl

The API keys for the Singapore and Beijing regions are different. For more information, see Preparations: Obtain and configure an API key
The following URL is for the Singapore region. If you use a model in the China (Beijing) region, replace the URL with the following: https://dashscope.aliyuncs.com/api/v1/services/aigc/text-generation/generation.
curl --location "https://dashscope-intl.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": "What's the weather like in Hangzhou?"
        }]
    },
    "parameters": {
        "result_format": "message",
        "tools": [{
            "type": "function",
            "function": {
                "name": "get_current_time",
                "description": "Useful when you want to know the current time.",
                "parameters": {}
            }
        },{
            "type": "function",
            "function": {
                "name": "get_current_weather",
                "description": "Useful when you want to query the weather in a specific city.",
                "parameters": {
                    "type": "object",
                    "properties": {
                        "location": {
                            "type": "string",
                            "description": "A city or district, such as Beijing, Hangzhou, or Yuhang District."
                        }
                    }
                },
                "required": ["location"]
            }
        }]
    }
}'

Asynchronous invocation

# Your DashScope Python SDK version must be 1.19.0 or later.
import asyncio
import platform
import os
import dashscope
from dashscope.aigc.generation import AioGeneration

dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
# The preceding URL is the base URL for the Singapore region. If you use a model in the China (Beijing) region, replace the base URL with: https://dashscope.aliyuncs.com/api/v1
async def main():
    response = await AioGeneration.call(
        # If the environment variable is not configured, replace the following line with your Model Studio API key: api_key="sk-xxx"
        # The API keys for the Singapore and Beijing regions are different. To get an API key, see https://www.alibabacloud.com/help/en/model-studio/get-api-key.
        api_key=os.getenv('DASHSCOPE_API_KEY'),
        # This example uses qwen-plus. You can replace it with another model name as needed. For a list of models, see https://www.alibabacloud.com/help/en/model-studio/getting-started/models.
        model="qwen-plus",
        messages=[{"role": "user", "content": "Who are you?"}],
        result_format="message",
    )
    print(response)

if platform.system() == "Windows":
    asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
asyncio.run(main())

Text extraction

For more information about text extraction with the Qwen-OCR model, see Text extraction.

Python

# use [pip install -U dashscope] to update sdk

import os
import dashscope
# The following URL is for the Singapore region. If you use a model in the China (Beijing) region, replace the URL with: https://dashscope.aliyuncs.com/api/v1
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'

messages = [
      {
        "role":"user",
        "content":[
          {
              "image":"https://prism-test-data.oss-cn-hangzhou.aliyuncs.com/image/car_invoice/car-invoice-img00040.jpg",
              "min_pixels": 3136,
              "max_pixels": 6422528,
          }
        ]
      }
    ]
params = {
  "ocr_options":{
  # Set a built-in task for information extraction. You do not need to provide a prompt. The model uses the built-in prompt for the task.
    "task": "key_information_extraction",
    "task_config": {
      "result_schema": {
          "Seller Name": "",
          "Buyer Name": "",
          "Price Before Tax": "",
          "Organization Code": "",
          "Invoice Code": ""
      }
    }
  }
}

response = dashscope.MultiModalConversation.call(model='qwen-vl-ocr',
                                       messages=messages,
                                       **params,
                                       # The API keys for the Singapore and Beijing regions are different. To get an API key, see https://www.alibabacloud.com/help/en/model-studio/get-api-key.
                                       api_key=os.getenv('DASHSCOPE_API_KEY'))

print(response.output.choices[0].message.content[0]["ocr_result"])

Java

import java.util.Arrays;
import java.util.Collections;
import java.util.Map;
import java.util.HashMap;
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.aigc.multimodalconversation.OcrOptions;
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.google.gson.JsonObject;
import com.alibaba.dashscope.utils.Constants;

public class Main {

    static {
        // The following URL is for the Singapore region. If you use a model in the China (Beijing) region, replace the URL with: https://dashscope.aliyuncs.com/api/v1
        Constants.baseHttpApiUrl="https://dashscope-intl.aliyuncs.com/api/v1";
    }
    
    public static void simpleMultiModalConversationCall()
            throws ApiException, NoApiKeyException, UploadFileException {
        MultiModalConversation conv = new MultiModalConversation();
        Map<String, Object> map = new HashMap<>();
        map.put("image", "https://prism-test-data.oss-cn-hangzhou.aliyuncs.com/image/car_invoice/car-invoice-img00040.jpg");
        // The maximum pixel threshold for the input image. If this value is exceeded, the image is scaled down proportionally until the total number of pixels is less than max_pixels.
        map.put("max_pixels", "6422528");
        // The minimum pixel threshold for the input image. If the total number of pixels is less than this value, the image is scaled up proportionally until the total number of pixels is greater than min_pixels.
        map.put("min_pixels", "3136");
         // Enable the automatic image rotation feature.
        map.put("enable_rotate", true);
        
        MultiModalMessage userMessage = MultiModalMessage.builder().role(Role.USER.getValue())
                .content(Arrays.asList(
                        map
                        )).build();

        // Create the main JSON object.
        JsonObject resultSchema = new JsonObject();
        resultSchema.addProperty("Seller Name", "");
        resultSchema.addProperty("Buyer Name", "");
        resultSchema.addProperty("Price Before Tax", "");
        resultSchema.addProperty("Organization Code", "");
        resultSchema.addProperty("Invoice Code", "");

        // Set a built-in task for information extraction. You do not need to provide a prompt. The model uses the built-in prompt for the task.
        OcrOptions ocrOptions = OcrOptions.builder()
                .task(OcrOptions.Task.KEY_INFORMATION_EXTRACTION)
                .taskConfig(OcrOptions.TaskConfig.builder()
                        .resultSchema(resultSchema)
                        .build())
                .build();

        MultiModalConversationParam param = MultiModalConversationParam.builder()
                // The API keys for the Singapore and Beijing regions are different. To get an API key, see https://www.alibabacloud.com/help/en/model-studio/get-api-key.
                // If the environment variable is not configured, replace the following line with your Model Studio API key: .apiKey("sk-xxx")
                .apiKey(System.getenv("DASHSCOPE_API_KEY"))
                .model("qwen-vl-ocr")
                .message(userMessage)
                .ocrOptions(ocrOptions)
                .build();
        MultiModalConversationResult result = conv.call(param);
        System.out.println(result.getOutput().getChoices().get(0).getMessage().getContent().get(0).get("ocr_result"));
    }

    public static void main(String[] args) {
        try {
            simpleMultiModalConversationCall();
        } catch (ApiException | NoApiKeyException | UploadFileException e) {
            System.out.println(e.getMessage());
        }
        System.exit(0);
    }
}

curl

The API keys for the Singapore and Beijing regions are different. For more information, see Preparations: Obtain and configure an API key
The following URL is for the Singapore region. If you use a model in the China (Beijing) region, replace the URL with the following: https://dashscope.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation
curl --location 'https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header 'Content-Type: application/json' \
--data '
{
  "model": "qwen-vl-ocr",
  "input": {
    "messages": [
      {
        "role": "user",
        "content": [
          {
            "image": "https://prism-test-data.oss-cn-hangzhou.aliyuncs.com/image/car_invoice/car-invoice-img00040.jpg",
            "min_pixels": 3136,
            "max_pixels": 6422528,
            "enable_rotate": true
          }
        ]
      }
    ]
  },
  "parameters": {
    "ocr_options": {
      "task": "key_information_extraction",
    "task_config": {
      "result_schema": {
          "Seller Name": "",
          "Buyer Name": "",
          "Price Before Tax": "",
          "Organization Code": "",
          "Invoice Code": ""
      }
    }
    }
  }
}
'

Document understanding

Python

import os
import dashscope

# Currently, the qwen-long-latest model can be called only in the China (Beijing) region.
dashscope.base_http_api_url = 'https://dashscope.aliyuncs.com/api/v1'
messages = [
        {'role': 'system', 'content': 'you are a helpful assisstant'},
        # Replace '{FILE_ID}' with the file ID from your conversation scenario.
        {'role':'system','content':f'fileid://{FILE_ID}'},
        {'role': 'user', 'content': 'What is this article about?'}]
response = dashscope.Generation.call(
    # If the environment variable is not configured, replace the following line with your Model Studio API key: api_key="sk-xxx"
    api_key=os.getenv('DASHSCOPE_API_KEY'),
    model="qwen-long-latest",
    messages=messages,
    result_format='message'
)
print(response)

Java

import os
import dashscope

# Currently, the qwen-long-latest model can be called only in the China (Beijing) region.
dashscope.base_http_api_url = 'https://dashscope.aliyuncs.com/api/v1'
messages = [
        {'role': 'system', 'content': 'you are a helpful assisstant'},
        # Replace '{FILE_ID}' with the file ID from your conversation scenario.
        {'role':'system','content':f'fileid://{FILE_ID}'},
        {'role': 'user', 'content': 'What is this article about?'}]
response = dashscope.Generation.call(
    # If the environment variable is not configured, replace the following line with your Model Studio API key: api_key="sk-xxx"
    api_key=os.getenv('DASHSCOPE_API_KEY'),
    model="qwen-long-latest",
    messages=messages,
    result_format='message'
)
print(response)

curl

Currently, the document understanding model is available only in the Beijing region.
Replace {FILE_ID} with the file ID from your conversation scenario.
curl --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-latest",
    "input":{
        "messages":[      
            {
                "role": "system",
                "content": "You are a helpful assistant."
            },
            {
                "role": "system",
                "content": "fileid://{FILE_ID}"
            },
            {
                "role": "user",
                "content": "What is this article about?"
            }
        ]
    },
    "parameters": {
        "result_format": "message"
    }
}'

model string (Required)

The name of the model to use.

Supported models: Qwen large language models (commercial and open-source versions), Qwen-VL, and Qwen-Coder.

For more information about model names and billing, see Model List.

messages array (Required)

The context for the model, arranged in conversational order.

When you make an HTTP call, place messages in the input object.

Message types

System Message object (Optional)

A system message that defines the role, tone, task objective, or constraints for the model. It is usually the first element in the messages array.

Do not set a system message for QwQ models. Setting a system message for QVQ or Qwen-OCR models has no effect.

Properties

content string (Required)

The message content.

role string (Required)

The role of the message. The value must be system.

User Message object (Required)

A user message that provides questions, instructions, or context to the model.

Properties

content string or array (Required)

The message content. The value is a string for text-only input. The value is an array for multimodal input, such as images, or when explicit caching is enabled.

Properties

text string (Required)

The text input.

image string (Optional)

The image file used as input for image understanding with a Qwen-VL model. The value can be the URL or local path of the image. For more information about how to use a local file as input, see Local file (Qwen-VL) or Local file (QVQ).

Example: {"image":"https://xxxx.jpeg"}

enable_rotate boolean (Optional) Defaults to false

Specifies whether to automatically correct the image orientation when you call the Qwen-OCR model.

Valid values:

  • true: Automatically corrects the orientation.

  • false: Does not automatically correct the orientation.

Example: {"image":"https://xxxx.jpeg","enable_rotate": True}

video array or string (Optional)

The video used as input for a Qwen-VL model or a QVQ model.

  • The value is an array for an image list.

  • The value is a string for a video file.

For more information about how to use a local file as input, see Local file (Qwen-VL) or Local file (QVQ).

Examples:

  • Image list: {"video":["https://xx1.jpg",...,"https://xxn.jpg"]}

  • Video file: {"video":"https://xxx.mp4"}

Some Qwen-VL models support video file input. For more information, see Video understanding (Qwen-VL). QVQ models can directly accept video files as input.

fps float (Optional)

Specifies the number of frames extracted per second. This parameter has two functions:

  • This parameter controls the frame extraction frequency for video inputs. One frame is extracted every seconds.

    This applies to the Qwen-VL model and the QVQ model.
  • This feature informs the model of the time interval between adjacent frames to help the model better understand the temporal dynamics of a video. It supports both video files and image lists as input and is suitable for scenarios such as event time localization or creating segmented content summaries.

    This is supported by the Qwen2.5-VL, Qwen3-VL, and QVQ models.

Qwen2.5-VL series models

  • qwen-vl-max series: qwen-vl-max-latest, qwen-vl-max-2025-04-08 and later models.

  • qwen-vl-plus series: qwen-vl-plus-latest, qwen-vl-plus-2025-01-25 and later models.

  • Open source series: qwen2.5-vl models.

This parameter is used with the video parameter. The value must be in the range of (0.1, 10). The default value is 2.0. Examples:

  • To pass an image list: {"video":["https://xx1.jpg",...,"https://xxn.jpg"],"fps":2}

  • To pass a video file: {"video": "https://xx1.mp4","fps":2}

A higher `fps` value is suitable for scenarios with high-speed motion, such as sporting events and action movies. A lower `fps` value is suitable for long videos or scenarios where the content is relatively static.

The OpenAI-compatible protocol does not support this parameter. By default, one frame is extracted from a video file every 0.5 seconds to generate an image list.

min_pixels integer (Optional)

This parameter is supported by the Qwen-OCR, QVQ, and Qwen-VL models. It specifies the minimum pixel count for an input image.

If the pixel count of the input image is less than min_pixels, the image is enlarged until its pixel count exceeds min_pixels.

Value range for min_pixels

  • Qwen3-VL: Default: 65536. Minimum: 4096.

  • qwen-vl-max-0813, qwen-vl-plus-0815, and : The default and minimum value is 4096.

  • Qwen-OCR, QVQ, and other Qwen2.5-VL models: The default and minimum value is 3136.

Example: {"image":"https://xxxx.jpeg","min-pixels": 65536}

max_pixels integer (Optional)

This parameter is supported by the Qwen-OCR, QVQ, and Qwen-VL models. It specifies the maximum pixel count for an input image.

If the pixel count is between [min_pixels, max_pixels], the model uses the original image. If the pixel count is larger than max_pixels, the image is reduced until its pixel count is less than max_pixels.

Value range for max_pixels

  • For Qwen-OCR models: Default: 6422528. Maximum: 23520000.

  • For Qwen-VL and QVQ models, this depends on the following conditions:

    • When vl_high_resolution_images is false:

      • Qwen3-VL, qwen-vl-max-0813, qwen-vl-plus-0815, and : Default: 2621440. Maximum: 16777216.

      • QVQ and other Qwen2.5-VL models: Default: 1003520. Maximum: 12845056.

    • When vl_high_resolution_images is true:

      • For Qwen3-VL, qwen-vl-max-0813, qwen-vl-plus-0815, and , the max_pixels parameter is not supported. The maximum pixel count is fixed at 16777216.

      • QVQ and other Qwen2.5-VL models: The max_pixels parameter is invalid. The maximum pixel count is fixed at 12845056.

Example: {"image":"https://xxxx.jpeg","max-pixels": 2621440}

cache_control object (Optional)

Enables the explicit cache feature. This parameter is supported only by models that use the explicit cache feature.

Properties

type string(Required)

The value must be ephemeral.

role string (Required)

The role of the user message. The value must be user.

Assistant Message object (Optional)

The model's response to the user message.

Properties

content string (Optional)

The message content. This parameter is optional only when the tool_calls parameter is specified in the assistant message.

role string (Required)

The value must be assistant.

partial boolean (Optional)

Specifies whether to enable partial mode. For more information, see Partial mode.

Supported models

  • Qwen-Max series

    qwen3-max, qwen3-max-2025-09-23, qwen3-max-preview (non-thinking mode), qwen-max, qwen-max-latest, and snapshot models from qwen-max-2025-01-25 or later

  • Qwen-Plus series (non-thinking mode)

    qwen-plus, qwen-plus-latest, and snapshot models from qwen-plus-2025-01-25 or later

  • Qwen-Flash series (non-thinking mode)

    qwen-flash, and snapshot models from qwen-flash-2025-07-28 or later

  • Qwen-Coder series

    qwen3-coder-plus, qwen3-coder-flash, qwen3-coder-480b-a35b-instruct, qwen3-coder-30b-a3b-instruct

  • Qwen-VL series

    • qwen3-vl-plus series (non-thinking mode)

      qwen3-vl-plus, and snapshot models from qwen3-vl-plus-2025-09-23 or later

    • qwen3-vl-flash series (non-thinking mode)

      qwen3-vl-flash, and snapshot models from qwen3-vl-flash-2025-10-15 or later

    • qwen-vl-max series

      qwen-vl-max, qwen-vl-max-latest, and snapshot models from qwen-vl-max-2025-04-08 or later

    • qwen-vl-plus series

      qwen-vl-plus, qwen-vl-plus-latest, and snapshot models from qwen-vl-plus-2025-01-25 or later

  • Qwen-Turbo series (non-thinking mode)

    qwen-turbo, qwen-turbo-latest, and snapshot models from qwen-turbo-2024-11-01 or later

  • Qwen open-source series

    Qwen3 open-source models (non-thinking mode), Qwen2.5 series text models, Qwen3-VL open-source models (non-thinking mode)

tool_calls array (Optional)

The tool and input parameter information that the model returns after a function calling request. This array contains one or more objects and is retrieved from the tool_calls field in the previous model response.

Properties

id string

The ID of the tool call.

type string

The type of the tool. Currently, only function is supported.

function object

The tool and its input parameter information.

Properties

name string

The name of the tool.

arguments string

The input parameter information, which is a JSON-formatted string.

index integer

The index of the current tool call object in the tool_calls array.

Tool Message object (Optional)

The output from the tool.

Properties

content string (Required)

The output of the tool function. The value must be a string.

role string (Required)

The value must be tool.

tool_call_id string (Optional)

The ID of the tool call to which this message is a response. This ID links the tool output to the model's original request and corresponds to the `id` field in response.output.choices[0].message.tool_calls[$index]["id"].

temperature float (Optional)

The sampling temperature controls the diversity of the generated text.

A higher temperature value results in more diverse text. A lower value results in more deterministic text.

Value range: [0, 2)

For HTTP calls, place the temperature parameter in the parameters object.
Do not modify the default temperature value for QVQ models.

top_p float (Optional)

This parameter specifies the probability threshold for nucleus sampling and controls the diversity of the generated text.

A higher top_p value generates more diverse text. A lower value generates more deterministic text.

Value range: (0, 1.0].

Default top_p values

Qwen3 (non-thinking mode), Qwen3-Instruct series, Qwen3-Coder series, qwen-max series, qwen-plus series (non-thinking mode), qwen-flash series (non-thinking mode), qwen-turbo series (non-thinking mode), qwen open-source series, qwen-vl-max-2025-08-13, Qwen3-VL (non-thinking mode): 0.8.

: 0.01.

qwen-vl-plus series, qwen-vl-max, qwen-vl-max-latest, qwen-vl-max-2025-04-08, qwen2.5-vl-3b-instruct, qwen2.5-vl-7b-instruct, qwen2.5-vl-32b-instruct, qwen2.5-vl-72b-instruct: 0.001.

QVQ series, qwen-vl-plus-2025-07-10, qwen-vl-plus-2025-08-15 : 0.5.

qwen3-max-preview (thinking mode), Qwen3-Omni-Flash series: 1.0.

Qwen3 (thinking mode), Qwen3-VL (thinking mode), Qwen3-Thinking, QwQ series, Qwen3-Omni-Captioner: 0.95

In the Java SDK, this parameter is named topPtop_p in the parameters object.
Do not modify the default top_p value for the QVQ model.

top_k integer (Optional)

This parameter specifies the size of the candidate set for sampling during generation. For example, a value of 50 means that only the 50 tokens with the highest scores form the candidate set for sampling. A larger value increases randomness, and a smaller value increases determinism. If the value is set to None or is greater than 100, the top_k policy is disabled and only the top_p policy is active.

The value must be greater than or equal to 0.

Default top_k values

QVQ series, qwen-vl-plus-2025-07-10, and qwen-vl-plus-2025-08-15: 10.

QwQ series: 40.

other qwen-vl-plus series, models released before qwen-vl-max-2025-08-13, qwen-vl-ocr, qwen2.5-omni-7b: 1.

Qwen3-Omni-Flash series: 50.

All other models: 20.

In the Java SDK, the parameter is named topK. When you make an HTTP call, specify the parameter as top_k in the parameters object.
Do not change the default top_k value for QVQ models.

enable_thinking boolean (Optional)

Specifies whether to enable thinking mode when you use a hybrid thinking model. This parameter applies to the Qwen3 and Qwen3-VL models. For more information, see Deep thinking.

Valid values:

  • true: Enabled

    If this parameter is enabled, the thinking content is returned in the reasoning_content field.
  • false: Disabled

For the default value for each model, see Supported models.

In the Java SDK, the parameter is enableThinking. When you make an HTTP call, place enable_thinking in the parameters object.

thinking_budget integer (Optional)

Specifies the maximum length of the thinking process. This parameter applies to the commercial and open-source versions of the Qwen3-VL and Qwen3 models. For more information, see Limit thinking length.

The default value is the maximum chain-of-thought length of the model. For more information, see Model List.

For the Java SDK, the parameter is thinkingBudget. For HTTP calls, add thinking_budget to the parameters object.
The default value is the model's maximum chain-of-thought length.

enable_code_interpreter boolean (Optional) Defaults to false

Specifies whether to enable the Code Interpreter feature. This feature is available only for the qwen3-max-preview model in thinking mode. For more information, see Code Interpreter.

Valid values:

  • true: Enables the feature.

  • false: Disables the feature.

The Java SDK does not support this parameter. For HTTP calls, you can place the enable_code_interpreter parameter in the parameters object.

repetition_penalty float (Optional)

Controls the degree of repetition in the generated text. A higher value for this parameter reduces repetition. A value of 1.0 indicates that no penalty is applied. The value must be greater than 0.

In the Java SDK, use repetitionPenaltyrepetition_penalty in the parameters object.
When you extract text using the qwen-vl-plus_latest, or qwen-vl-plus_2025-01-25 models, set repetition_penalty to 1.0.
For the Qwen-OCR model, the default value of repetition_penalty is 1.05. Do not change this value because it significantly affects model performance.
Do not change the default repetition_penalty value for the QVQ model.

presence_penalty float (Optional)

Controls the repetition of content in the generated text.

The value ranges from -2.0 to 2.0. A positive value reduces repetition, and a negative value increases it.

You can increase this value for scenarios that require diversity and creativity, such as creative writing or brainstorming. You can decrease this value for scenarios that require consistency and term accuracy, such as technical documents or formal text.

Default presence_penalty values

qwen3-max-preview (thinking mode), Qwen3 (non-thinking mode), Qwen3-Instruct series, qwen3-0.6b/1.7b/4b (thinking mode), QVQ series, qwen-max, qwen-max-latest, qwen-max-latest qwen2.5-vl series, qwen-vl-max series, qwen-vl-plus, Qwen3-VL (non-thinking mode): 1.5.

qwen-vl-plus-latest, qwen-vl-plus-2025-08-15: 1.2.

qwen-vl-plus-2025-01-25: 1.0.

qwen3-8b/14b/32b/30b-a3b/235b-a22b (thinking mode), qwen-plus/qwen-plus-latest/2025-04-28 (thinking mode), qwen-turbo/qwen-turbo/2025-04-28 (thinking mode): 0.5.

All others: 0.0.

How it works

If the value is positive, the model applies a penalty to tokens that already exist in the text. The penalty is applied regardless of how many times a token has appeared. This reduces the likelihood of these tokens reappearing, which in turn reduces content repetition and increases word diversity.

Example

Prompt: Translate the following text into Chinese: “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.”

Parameter value: 2.0: This film is exceptional. The storyline is compelling, the performances are outstanding, and the score is beautiful. Overall, the entire movie is a masterpiece. It is truly superb. The plot is brilliantly crafted, the acting is top-notch, and the music is simply divine.

Parameter value: 0.0: This movie is good. The plot is good, the acting is good, and the music is also good. Overall, the whole movie is quite good. In fact, it is really great. The plot is very good, the acting is also excellent, and the music is equally wonderful.

Parameter value: -2.0: This movie is good. The plot is good, the acting is good, and the music is good. Overall, the whole movie is good. It is really good, in fact. The plot is so good, the acting is so good, and the music is so good.

When extracting text with the qwen-vl-plus-2025-01-25 model, set `presence_penalty` to 1.5.
Do not change the default `presence_penalty` value for QVQ models.
The Java SDK does not support this parameter. When you make an HTTP call, place presence_penalty in the parameters object.

vl_high_resolution_images boolean (Optional) Defaults to false.

Specifies whether to enable the high-resolution mode for images. In this mode, the token limit for a single input image is increased to 16,384 tokens. For more information, see Process high-resolution images.

  • vl_high_resolution_images: true: Uses a fixed resolution policy and ignores the max_pixels setting. If an image exceeds the pixel limit, it is scaled down to fit within the limit.

    Click to view the pixel limits for each model

    When vl_high_resolution_images is set to true, the pixel limits vary by model:

    • For Qwen3-VL series, qwen-vl-max-0813, qwen-vl-plus-0815, and models: 16777216 (Each Token corresponds to 32*32 pixels, and the total pixel count is calculated as 16384*32*32)

    • For QVQ series, Qwen2.5-VL series models: 12845056 (Each Token corresponds to 28*28 pixels, and the total pixel count is calculated as 16384*28*28)

  • When vl_high_resolution_images is set to false, the actual resolution is capped by a pixel limit. This limit is the greater of the max_pixels value and a default value. If an image exceeds this limit, it is scaled down to fit.

    Click to view the default pixel limits for each model

    When vl_high_resolution_images is set to false, the default pixel limits vary by model:

    • For Qwen3-VL series, qwen-vl-max-2025-08-13 and later, qwen-vl-plus-2025-08-15, and : 2621440 (2560*32*32, meaning the default Token limit is 2560)

    • For QVQ series, Qwen2.5-VL series models: 1003520 (1280*28*28, meaning the default Token limit is 1280)

For the Java SDK, use vlHighResolutionImages. Version 2.20.8 or later is required. When you make an HTTP call, place the vl_high_resolution_imagesparameters object.

vl_enable_image_hw_output boolean (Optional) Defaults to false

Specifies whether to return the height and width of the input image after the model scales it. If set to true, the model returns the height and width of the scaled image. When streaming output is enabled, this information is returned in the last data block (chunk). This parameter is supported by the Qwen-VL model.

In the Java SDK, this parameter is named vlEnableImageHwOutput, and the minimum required version is 2.20.8. When you make an HTTP call, place vl_enable_image_hw_output in the parameters object.

ocr_options object (Optional)

Specifies the parameters to configure when you call a built-in task using the Qwen-OCR model.

Properties

task string (Required)

The name of the built-in task. Valid values are:

  • "text_recognition": General text recognition

  • "key_information_extraction": Key information extraction

  • "document_parsing": Document parsing

  • "table_parsing": Table parsing

  • "formula_recognition": Formula recognition

  • "multi_lan": Multilingual recognition

  • "advanced_recognition": Advanced recognition

task_config array (Optional)

This parameter is used when the task is set to "key_information_extraction".

Properties

result_schema object (Required)

Specifies the fields to extract. The value must be a JSON structure with a maximum of three nested layers. Specify only the JSON object keys and leave their values empty.

Example:

"result_schema" : {
     "recipient_information" : {
          "recipient_name" : "",
          "recipient_phone_number" : "",
          "recipient_address":""
     }
}
The corresponding class in the Java SDK is OcrOptions. The minimum required version for the DashScope Python SDK is 1.22.2, and the minimum required version for the Java SDK is 2.18.4.
For HTTP calls, place the ocr_options object inside the parameters object.

max_input_tokens integer (Optional)

The maximum number of tokens in the input. This parameter is supported only by the qwen-plus-0728/latest model.

  • Default for qwen-plus-latest: 129,024

    The default value may change to 1,000,000 in the future.
  • Default for qwen-plus-2025-07-28: 1,000,000

The Java SDK does not currently support this parameter. When you make HTTP calls, you can specify max_input_tokens in the parameters object.

max_tokens integer (Optional)

Specifies the maximum number of tokens to generate. If the output exceeds this limit, generation stops, and the finish_reason field in the response is set to length.

The default and maximum values are the model's maximum output length. For more information, see Model List.

Use this parameter to set the maximum output length for generated content, such as summaries or keywords. This helps reduce costs and shorten response times.

When the max_tokens limit is reached, the value of the response's finish_reason field is length.

For the qwen-vl-ocr model, the max_tokens parameter (maximum output length) defaults to 4096. To increase this value to the 4097–8192 range, send a request by email to [email protected]. Include the following information: your Alibaba Cloud account ID, image type (such as document, E-commerce, or contract images), model name, estimated QPS and total daily requests, and the percentage of requests where the output length is expected to exceed 4096 tokens.
max_tokens does not limit the length of the model's chain-of-thought.
In the Java SDK, this parameter is named maxTokens. For Qwen-VL and OCR models, the parameter is named maxLength. However, maxTokens is also supported in version 2.18.4 and later. For HTTP calls, place max_tokens in the parameters

seed integer (Optional)

The random number seed. It ensures that results are reproducible for the same input and parameters. If you use the same seed value and other parameters in a call, the model attempts to return the same result.

Valid values: [0,2<sup>31</sup>−1].

For HTTP calls, place the seed parameter in the parameters object.

stream boolean (Optional) Defaults to false

Specifies whether to stream the response. Valid values:

  • false: The entire response is generated before it is returned.

  • true: The response is streamed in chunks as it is generated.

This parameter is supported only by the Python SDK. To use streaming output with the Java SDK, call the streamCall API. To use streaming output over HTTP, set X-DashScope-SSE to enable in the header.
The Qwen3 commercial model (in thinking mode), Qwen3 open-source models, QwQ, and QVQ support only streaming output.

incremental_output boolean (Optional) Defaults to false. However, the default value is true for models such as Qwen3-Max, Qwen3-VL, Qwen3 open-source edition, QwQ, and QVQ.

This parameter specifies whether to enable incremental output in streaming output mode. To enable this feature, set the parameter to true.

Parameter values:

  • false: Each output contains the entire sequence that is generated up to that point. The final output is the complete result.

    I
    I like
    I like apple
    I like apple.
  • true (Recommended): Enables incremental output. Subsequent outputs do not include previously sent content. You can read these segments sequentially in real time to retrieve the complete result.

    I
    like
    apple
    .
In the Java SDK, the parameter is incrementalOutput. When you make an HTTP call, add incremental_output to the parameters object.
The QwQ model and the Qwen3 model in thinking mode support only a value of true. Because the default value for the Qwen3 commercial model is false, you must set this parameter to true when you use the Qwen3 commercial model in thinking mode.
The Qwen3 open-source edition model does not support a value of false for this parameter.

response_format object (Optional) Defaults to {"type": "text"}

Specifies the format of the response. Valid values are {"type": "text"} and {"type": "json_object"}. If you set this parameter to {"type": "json_object"}, the model returns a standard JSON string. For more information, see Structured output.

If you set this parameter to {"type": "json_object"}, you must also instruct the model in the prompt to output content in JSON format. For example, you can use a prompt such as "Output in JSON format." Otherwise, an error occurs.
In the Java SDK, this parameter is named responseFormat. When you make an HTTP call, place the response_format parameter in the parameters object.

Supported models

  • Text generation models

    • Qwen-Max series: qwen3-max, qwen3-max-2025-09-23, qwen3-max-preview (non-thinking mode), qwen-max, qwen-max-latest, qwen-max-2025-01-25, and later snapshot models

    • Qwen-Plus series (non-thinking mode): qwen-plus, qwen-plus-latest, qwen-plus-2025-01-25, and later snapshot models

    • Qwen-Flash series (non-thinking mode): qwen-flash, qwen-flash-2025-07-28, and later snapshot models

    • Qwen-Turbo series (non-thinking mode): qwen-turbo, qwen-turbo-latest, qwen-turbo-2024-11-01, and later snapshot models

    • Qwen-Coder series: qwen3-coder-plus, qwen3-coder-plus-2025-07-22, qwen3-coder-flash, and qwen3-coder-flash-2025-07-28

    • Qwen-Long series: qwen-long-latest, and qwen-long-2025-01-25

  • Open-source text generation models

    • Qwen3 (non-thinking mode)

    • Qwen3-Coder

    • Qwen2.5 series text models (excluding math and coder models)

  • Multimodal models

    • Qwen3-VL-Plus series (non-thinking mode): qwen3-vl-plus, qwen3-vl-plus-2025-09-23, and later snapshot models

    • Qwen3-VL-Flash series (non-thinking mode): qwen3-vl-flash, qwen3-vl-flash-2025-10-15, and later snapshot models

    • QwenVL-Max series: qwen-vl-max (excluding the latest and snapshot versions)

    • QwenVL-Plus series: qwen-vl-plus (excluding the latest and snapshot versions)

  • Open-source multimodal models

    • Qwen3-VL (non-thinking mode)

output_format string (Optional) Defaults to "model_detailed_report"

Specifies the output format. This parameter is valid only when you use the Qwen deep-research model (qwen-deep-research).

Valid values:

  • "model_detailed_report": A detailed research report of approximately 6,000 words.

  • "model_summary_report": A summary research report of approximately 1,500 to 2,000 words.

result_format string (Optional) Defaults to text. However, for the Qwen3-Max, Qwen3-VL, QwQ, Qwen3 open-source (except for qwen3-next-80b-a3b-instruct), and models, the default value is message.

Specifies the format of the returned data. You can set this parameter to message to simplify multi-turn conversations.

The platform will update the default value to message in a future release.
In the Java SDK, this parameter is named resultFormatresult_format in the parameters object.
If you use the Qwen-VL, QVQ, OCR, or models, setting this parameter to text has no effect.
This parameter must be set to message for the Qwen3-Max, Qwen3-VL, and Qwen3 models in thinking mode. For Qwen3 commercial models, the default value is text. You must set this parameter to message.
If you use the Java SDK to call a Qwen3 open-source model, the model returns the response in the message format, even if you specify text

logprobs boolean (Optional) Defaults to: false.

Specifies whether to return the log probabilities of the output tokens. Valid values:

  • true

    Back

  • false

    Does not return

Supported models:

  • Snapshot models of the qwen-plus series (excluding mainline models)

  • Snapshot models of the qwen-turbo series (excluding mainline models)

  • qwen-vl-ocr models

  • Qwen3 open-source models

When you make HTTP calls, place logprobs in the parameters object.

top_logprobs integer (Optional) Defaults to: 0.

Specifies the number of tokens with the highest probability to return at each generation step.

Valid values: [0, 5]

This parameter is effective only when logprobs is set to true.

In the Java SDK, the parameter is called topLogprobs. For HTTP calls, place top_logprobs in the parameters object.

n integer (Optional) Defaults to: 1.

Specifies the number of responses to generate. The valid range is 1-4. For scenarios that require multiple responses, such as creative writing and ad copy, you can set a larger value for n.

This parameter is supported only for the qwen-plus, Qwen3 (non-thinking mode) models. The value is fixed to 1 when the tools parameter is specified.
Setting a larger value for n does not increase input token consumption, but it increases output token consumption.
For HTTP calls, place n in the parameters object.

stop string or array (Optional)

Specifies the stop words. When the model generates a string or a token_id specified in stop, generation stops immediately.

You can pass sensitive words to control the model's output.

If `stop` is an array, do not include both token_id values and strings as elements. For example, ["Hello",104307] is an invalid value.
For HTTP calls, place the stop parameter in the parameters object.

tools array (Optional)

An array of one or more tool objects that the model can call in Function Calling. For more information, see Function Calling.

When you use tools, you must set result_format to message.

You can set the tools parameter when you make a function calling request or submit the results of a tool execution.

Properties

type string (Required)

The type of the tool. Only function is supported.

function object (Required)

Properties

name string (Required)

The name of the tool function. The name can contain only letters, numbers, underscores, and hyphens. The maximum length is 64 characters.

description string (Required)

The description of the tool function. The model uses this description to decide when and how to call the function.

parameters object (Required)

The parameters of the tool function. The parameters must be in a valid JSON Schema format. For more information, see the JSON Schema documentation. If this object is empty, the function does not have any input parameters.

When you make an HTTP call, place the tools parameter inside the parameters object. The qwen-vl model series are not currently supported.

tool_choice string or object (Optional) Defaults to: auto.

The tool selection policy. You can set this parameter to force the model to call a specific tool or to disable all tool calls.

  • auto

    The model selects a tool automatically.

  • none

    To temporarily disable tool calling for a specific request, set the tool_choice parameter to none.

  • {"type": "function", "function": {"name": "the_function_to_call"}}

    To force the model to call a specific tool, set the tool_choice parameter to {"type": "function", "function": {"name": "the_function_to_call"}}, where the_function_to_call is the name of the function to call.

    Forcing a tool call is not supported when the model is in thinking mode.
In the Java SDK, this is called toolChoice. When calling via HTTP, you can place tool_choice in the parameters object.

parallel_tool_calls boolean (Optional) The default value is false.

Specifies whether to enable parallel tool calling.

Valid values:

  • true: Enabled

  • false: Disabled.

For more information, see Parallel tool calling.

In the Java SDK, specify the parallelToolCalls. For HTTP calls, specify the parallel_tool_calls parameter in the parameters object.

Chat response object (same for streaming and non-streaming outputs)

{
  "status_code": 200,
  "request_id": "902fee3b-f7f0-9a8c-96a1-6b4ea25af114",
  "code": "",
  "message": "",
  "output": {
    "text": null,
    "finish_reason": null,
    "choices": [
      {
        "finish_reason": "stop",
        "message": {
          "role": "assistant",
          "content": "I am a large-scale language model developed by Alibaba Cloud. My name is Qwen."
        }
      }
    ]
  },
  "usage": {
    "input_tokens": 22,
    "output_tokens": 17,
    "total_tokens": 39
  }
}

status_code string

The status code of the request. A value of 200 indicates that the request is successful. Any other value indicates that the request failed.

The Java SDK does not return this parameter. If a call fails, an exception is thrown. The exception message contains the values of the status_code and message parameters.

request_id string

The unique ID for the call.

The Java SDK returns this parameter as requestId.

code string

The error code. This parameter is empty if the call is successful.

Only the Python SDK returns this parameter.

output object

Information about the result of the call.

Properties

text string

The response generated by the model. This field contains the response content when the result_format input parameter is set to text.

finish_reason string

This parameter is not empty when the result_format input parameter is set to text.

The following four scenarios can occur:

  • The value is null during generation.

  • stop: The model finished generating the response naturally or a stop condition in the input parameters was triggered.

  • length: The generation stopped because the output reached the maximum length.

  • tool_calls: A tool was called.

choices array

The output information from the model. The choices parameter is returned when result_format is set to message.

Properties

finish_reason string

The four situations are as follows:

  • The value is null during generation.

  • stop: The model finished generating the response naturally or a stop condition in the input parameters was triggered.

  • length: The generation stopped because the output reached the maximum length.

  • tool_calls: A tool was called.

message object

The message object from the model's output.

Properties

phase string

The stage of the research task. This parameter is returned only for calls to the Qwen deep research model qwen-deep-research.

  • "ResearchPlanning": The research planning stage. The execution plan is in the content field.

  • "WebResearch": The web search stage. The search content is in the extra.deep_research.research field.

  • "KeepAlive": Maintains the streaming connection. This indicates that the program is running but is not sending useful content.

  • "answer": The answering stage. The research content is in the content field.

role string

The role of the output message. The value is always `assistant`.

content string or array

The content of the output message. The data type is array for models in the Qwen-VL or Qwen-Audio series, and string for all other models.

If function calling is initiated, this value is empty.

Properties

text string

The content of the output message when you use a model in the Qwen-VL or Qwen-Audio series.

image_hw array

If the vl_enable_image_hw_output parameter is enabled for a Qwen-VL series model, the following applies:

  • For image inputs, this parameter returns the height and width of the image in pixels.

  • For video inputs, this parameter returns an empty array.

ocr_result array

The result of a built-in task, such as information extraction or high-precision recognition, when you use a Qwen-OCR series model.

Properties

kv_result array

The output of the information extraction task.

words_info array

The output of the high-precision recognition task.

Properties

rotate_rect array

Example: [center_x, center_y, width, height, angle]

The rotated rectangle that represents the text box:

  • center_x and center_y: The x- and y-coordinates of the centroid of the text box.

  • width is the width of the text box, and height is its height.

  • angle: The rotation angle of the text box relative to the horizontal direction. The value range is [-90, 90].

location array

Example: [x1, y1, x2, y2, x3, y3, x4, y4]

The coordinates of the four vertices of the text box, listed in clockwise order starting from the top-left vertex: top-left, top-right, bottom-right, and bottom-left.

text string

The content of the text line.

extra dict

Additional information about the research task. This parameter is returned only for calls to the Qwen deep research model qwen-deep-research.

Properties

deep_research array

Information about the deep research task.

Properties

research object

Research task information.

Properties

id int

The ID of the research task.

webSites array

Information about the websites that were searched. This parameter is returned only when `status` is `streamingWebResult`.

Properties

title string

The title of the website.

description string

The description of the website.

url string

The URL of the website.

favicon string

The favicon of the website.

learningMap object

The content that the model summarized from tool calls.

reference object

Information about the reference. This is provided during the answering stage when the final report is generated.

Properties

icon string

The icon of the website.

index_number integer

The reference number.

description string

The description of the reference.

title string

The title of the reference.

url string

The link to the reference.

status string

The execution status of the task in the current stage. This parameter is returned only for calls to the Qwen deep research model `qwen-deep-research`.

  • "typing": The model is working and generating content.

  • "finished": The current stage is complete.

  • "streamingQueries": Research goals and search queries are being generated. This occurs during the WebResearch stage.

  • "streamingWebResult": The search, web page reading, and code execution are in progress. This occurs during the WebResearch stage.

  • "WebResultFinished": The web search stage is complete. This occurs during the WebResearch stage.

reasoning_content string

The deep thinking content from the Qwen3, QwQ model, and QVQ model.

tool_calls array

The `tool_calls` parameter is generated if the model needs to call a tool.

Properties

function object

The name of the tool to call and its input parameters.

Properties

name string

The name of the tool to call.

arguments string

The parameters to pass to the tool, in a JSON string format.

Because the responses of large language models have a degree of randomness, the output JSON string may not always meet the requirements of your function. You must validate the parameters before you pass them to the function.

index integer

The index of the current tool_calls object in the `tool_calls` array.

id string

The ID of this tool response.

type string

The type of the tool. The value is always function.

logprobs object

The probability information for the current `choices` object.

Properties

content array

An array of tokens with log probability information.

Properties

token string

The current token.

bytes array

A list of the raw UTF-8 bytes for the current token. This helps you accurately reconstruct the output, especially for emojis and Chinese characters.

logprob float

The log probability of the current token. A null value indicates an extremely low probability.

top_logprobs array

A list of the most likely tokens at the current token position and their log probabilities. The number of elements is the same as the value of the top_logprobs input parameter.

Properties

token string

The current token.

bytes array

A list of the raw UTF-8 bytes for the current token. This helps you accurately reconstruct the output, especially for emojis and Chinese characters.

logprob float

The log probability of the current token. A null value indicates an extremely low probability.

usage map

Information about the tokens used for the chat request.

Properties

input_tokens integer

The number of tokens in the user input after conversion.

output_tokens integer

The number of tokens in the model's output after conversion.

input_tokens_details integer

Details about the number of tokens in the input after conversion when you use the Qwen-VL model or the QVQ model.

Properties

text_tokens integer

The number of tokens in the input text after conversion. This parameter is returned when you use the Qwen-VL model or the QVQ model.

image_tokens integer

The number of tokens in the input image after conversion.

video_tokens integer

The number of tokens in the input video file or image list after conversion.

total_tokens integer

The total number of tokens for the request. This field is returned if the input is plain text and is the sum of input_tokens and output_tokens.

image_tokens integer

The number of tokens in the input image content after conversion. This field is returned if the input contains an image.

video_tokens integer

The number of tokens in the input video content after conversion. This field is returned if the input contains a video.

audio_tokens integer

The number of tokens in the input audio content after conversion. This field is returned if the input contains audio.

output_tokens_details integer

Details about the number of tokens in the output after conversion.

Properties

text_tokens integer

The number of tokens in the output text after conversion.

reasoning_tokens integer

The number of tokens in the Qwen3 model's thinking process after conversion.

prompt_tokens_details object

A fine-grained classification of input tokens.

Properties

cached_tokens integer

The number of tokens that hit the cache. For more information about the context cache, see Context cache.

cache_creation object

Information about explicit cache creation.

Properties

ephemeral_5m_input_tokens integer

The number of tokens used to create an explicit cache that is valid for 5 minutes.

cache_creation_input_tokens integer

The number of tokens used to create an explicit cache.

cache_type string

The type of cache used. When an explicit cache is used, the value of this parameter is ephemeral. Otherwise, this parameter is not returned.

Error codes

If a model call fails with an error message, see Error messages for troubleshooting information.