You can call Qwen models using the DashScope API. This topic describes the input and output parameters and provides call examples.
- Singapore
- US (Virginia)
- China (Beijing)
- Hong Kong (China)
- Germany (Frankfurt)
- Japan (Tokyo)
HTTP request address:
- Plain text models, such as qwen-plus:
POST https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/text-generation/generation - Multimodal models, such as qwen3.7-plus or qwen3-vl-plus:
POST https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation
base_url for the SDK call configuration is as follows:- Python code
- Java code
{WorkspaceId} with your actual workspace ID.
You must obtain an API key and configure it as an environment variable. If you use the DashScope SDK to make calls, you must also install the DashScope SDK.
Request bodymodelstring(Required)The name of the model to use.Supported models include Qwen large language models (commercial and open source editions), Qwen-VL, Qwen-Coder, math models, DeepSeek, Kimi, GLM, and MiniMax.For specific model names and billing details, seeSelect a model.messagesarray(Required)The context to pass to the large language model (LLM), arranged in conversational order.When you call over HTTP, place messages in the input object.
Message types System Message object (Optional)A system message that is used to set the role, tone, task objectives, or constraints for the LLM. It is usually placed first in the messages array.We do not recommend that you set a system message for QwQ models. A system message does not take effect for QVQ models.
Properties content string(Required)The content of the message.rolestring(Required)The role for the system message. The value is fixed to system.object(Required)A user message that is used to pass questions, instructions, or context to the model.
Properties content string or array(Required)The content of the message. If the input is only text, this parameter is a string. If the input includes multimodal data, such as images, or if explicit caching is enabled, this parameter is an array.
Properties text string(Required)The input text.imagestring (Optional)The image file for image understanding. You can pass an image in one of the following three ways:
{"image":"https://xxxx.jpeg"}videoarray or string (Optional)The video to pass when you use a Qwen-VL model or a QVQ model.
float(Optional)The number of frames to extract per second. The value must be in the range of [0.1, 10]. The default value is 2.0.
Description The fps parameter has two functions:
fps value is suitable for high-speed motion scenarios, such as sports events and action movies. A smaller fps value is suitable for long videos or scenarios with relatively static content.
Examples
integer(Optional)The maximum number of frames that can be extracted from a video. If the number of frames calculated based on fps exceeds max_frames, the system automatically adjusts to extract frames uniformly within the max_frames limit. This ensures that the total number of frames does not exceed the limit.
Value range
Sample value {"type": "video_url","video_url": {"url":"https://xxxx.mp4"},"max_frame": 2000}
When you call with an OpenAI-compatible API, you cannot customize the min_pixelsinteger(Optional)Sets the minimum pixel threshold for the input image or video frames. If the total pixels of an input image or video frame are less than min_pixels, the image or frame is enlarged until its total pixels are higher than min_pixels.
Value range
Examples
integer(Optional)Sets the maximum pixel threshold for the input image or video frames. If the total pixels of an input image or video are within the [min_pixels, max_pixels] range, the model recognizes the original image. If the total pixels of the input image are greater than max_pixels, the image is scaled down until the total pixels are below max_pixels.
Value range
Examples
integer(Optional)Limits the total pixels of all frames that are extracted from a video (pixels of a single frame × total number of frames). If the total pixels of the video exceed this limit, the system scales down the video frames but still ensures that the pixel value of a single frame is within the [min_pixels, max_pixels] range. This applies to Qwen-VL and QVQ models.For long videos with many extracted frames, you can appropriately lower this value to reduce token consumption and processing time, but this may result in the loss of image details.
Value range
Examples
object(Optional)This is supported only by models that support explicit caching. It is used to enable explicit caching.
Properties type string(Required)The value must be ephemeral.string(Required)The role for a user message. The value must be user.object(Optional)The model's reply to the user message.
Properties content string(Optional)The content of the message. This is optional only if the tool_calls parameter is specified in the assistant message.rolestring(Required)The value must be assistant.partialboolean(Optional)Specifies whether to enable partial mode. For more information and a list of supported models, see Partial mode.tool_calls array(Optional)The tool and input parameter information that is returned after you initiate a function call. It contains one or more objects. This is obtained from the tool_calls field of the previous model response.
Properties id stringThe ID of the tool response.type stringThe tool type. Currently, only function is supported.function objectThe tool and input parameter information.
Properties name stringThe tool name.arguments stringThe input parameter information, in JSON string format.integerThe index of the current tool information in the tool_calls array.object (Optional)The output information of the tool.
Properties content string(Required)The output content of the tool function. It must be in string format.rolestring(Required)The value must be tool.tool_call_idstring(Optional)The ID that is returned after you initiate a function call. You can retrieve it using response.output.choices[0].message.tool_calls[$index]["id"]. It is used to mark the tool that corresponds to the tool message.float(Optional)The sampling temperature, which controls the diversity of the text that is generated by the model.A higher temperature results in more diverse text, and a lower temperature results in more deterministic text.Value range: [0, 2)When you call over HTTP, place temperature in the parameters object. We do not recommend that you 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 is generated by the model.A higher top_p value results in more diverse text, and a lower top_p value results in more deterministic text.Value range: (0, 1.0].In the Java SDK, this parameter is topP. When you call over HTTP, place top_p in the parameters object.
We do not recommend that you modify the default top_kinteger(Optional)The size of the candidate set for sampling during generation. For example, if you set this parameter to 50, only the 50 tokens with the highest scores in a single generation are used to form the candidate set for random sampling. A larger value increases randomness, and a smaller value increases determinism. A value of None or a value greater than 100 indicates that the top_k strategy is not enabled and only the top_p strategy takes effect.The value must be greater than or equal to 0.
Default top_k values QVQ series: 10QwQ series: 40models before the rest of the qwen-vl-plus series, : 1All other models: 20GLM series (provided by Alibaba Cloud): 20DeepSeek, Kimi, and MiniMax series do not support the top_k parameter.In the Java SDK, this parameter is topK. When you call over HTTP, place top_k in the parameters object.
We do not recommend that you modify the default enable_thinking boolean (Optional)Specifies whether to enable thinking mode for a hybrid thinking model. This applies to Qwen3.7, Qwen3.6, Qwen3.5, Qwen3, and Qwen3-VL models, along with the DeepSeek-V4-Pro/V4-Flash series, DeepSeek-V3.2/V3.2-exp/V3.1 series, Kimi-K2.6/K2.5 series, and GLM series. The DeepSeek-V4 series has thinking mode enabled by default. You can adjust the inference effort with the reasoning_effort parameter.Valid values:
In the Java SDK, this parameter is preserve_thinking boolean (Optional) The default value is false. (Default value for qwen3.8-max/qwen3.8-flash:true)Specifies whether to append the reasoning_content from assistant messages in the conversation history to the model input. This is suitable for scenarios where the model needs to refer to the historical thinking process.Currently supported by qwen3.7-max, qwen3.7-max-2026-05-20 and subsequent snapshots, qwen3.6-max-preview, qwen3.7-plus, qwen3.7-plus-2026-05-26, qwen3.6-plus, qwen3.6-plus-2026-04-02, qwen3.7-flash, qwen3.7-flash-2026-07-15, qwen3.6-flash, qwen3.6-flash-2026-04-16, qwen3.8-max (enabled by default), qwen3.8-flash (enabled by default), kimi-k2.6 (deployed on Alibaba Cloud Model Studio), kimi-k2.7-code (deployed on Alibaba Cloud Model Studio, enabled by default), kimi/kimi-k2.7-code-highspeed (supplied by Moonshot AI, enabled by default), and kimi/kimi-k2.7-code (supplied by Moonshot AI, enabled by default).Important (qwen3.8-max/qwen3.8-flash): When using qwen3.8-max/qwen3.8-flash, preserve_thinking defaults to true. You must send back all historical reasoning_content in the reasoning_content field. Do NOT concatenate reasoning_content into the content field. Doing so may degrade model performance.
When you call over HTTP, place preserve_thinking in the parameters object. The Java SDK is not supported.thinking_budget integer (Optional)The maximum length of the thinking process. This applies to Qwen3.8, Qwen3.7, Qwen3.6, Qwen3.5, Qwen3-VL, Qwen3, GLM and Kimi models, except kimi-k3, which does not support this parameter. For more information, see Limit thinking length.The default value is the maximum chain-of-thought length for the model. For more information, see Select a model.
In the Java SDK, this parameter is The default value is the maximum chain-of-thought length for the model.reasoning_effort string (Optional)Controls the inference intensity of models. The valid values and default values vary by model.DeepSeek-V4 and GLM series (Default value: high)Valid values: high (high-intensity inference) and max (maximum-intensity inference). low and medium are mapped to high, and xhigh is mapped to max.This applies to glm-5.2, glm-5.1, glm-5, deepseek-v4-pro, and deepseek-v4-flash.qwen3.8-max/qwen3.8-flash: Default value:xhighValid values:
max is mapped to xhigh, high is mapped to xhigh, minimal is mapped to low, and none is mapped to enable_thinking=False.Setting values other than the above valid values and mapped values will cause an error.For the qwen3.8 series, reasoning_effort and thinking_budget cannot be set at the same time. Setting both will cause an error. However, they support mutual conversion:
When you call over HTTP, place reasoning_effort in the parameters object.tool_stream boolean (Optional) The default value is false.This parameter only affects the streaming output behavior of complex tool parameters and is effective only in streaming calls. Simple tool parameters, where all parameter types are strings, can be streamed as long as streaming calls are enabled. tool_stream has no effect on them. Complex tools are tools where some parameter types in the tool definition are arrays or objects. Currently, only the Qwen and GLM series support this.Qwen series support list:
Complex tools are tools where some parameter types in the tool definition are arrays or objects.GLM series support list: glm-4.6, glm-4.7, glm-5, and glm-5.1.GLM series usage reference:
When you call over HTTP, place tool_stream in the parameters object.enable_code_interpreter boolean (Optional) The default value is false.Specifies whether to enable the code interpreter feature. For more information, see Code interpreter.Valid values:
The Java SDK is not supported. When you call over HTTP, place enable_code_interpreter in the parameters object.clear_thinking boolean(Optional) The default value is false.Controls whether to use the reasoning_content (thinking process) from previous turns as context input for the model in a multi-turn conversation. This is supported only by the GLM series models glm-5.2, glm-5.1, glm-5, and glm-4.7.
float(Optional)The penalty for repeating consecutive sequences during model generation. A higher repetition_penalty value can reduce repetition in the model's output. A value of 1.0 indicates no penalty. The value must be greater than 0.In the Java SDK, this parameter is repetitionPenalty. When you call over HTTP, place repetition_penalty in the parameters object.
When you use the qwen-vl-plus_2025-01-25 model for text extraction, we recommend that you set
We do not recommend that you modify the default presence_penaltyfloat(Optional)Controls the content repetition when the model generates text.Value range: [-2.0, 2.0]. Positive values reduce repetition, while negative values increase it.In scenarios that require diversity, fun, or creativity, such as creative writing or brainstorming, you can increase this value. In scenarios that emphasize consistency and term accuracy, such as technical documents or formal texts, you can decrease this value.
Default presence_penalty values Qwen3.8 (non-thinking mode), Qwen3.7 (non-thinking mode), Qwen3.6 (non-thinking mode), Qwen3.5-Omni, Qwen3.5 (non-thinking mode), qwen3-max-preview (thinking mode), Qwen3 (non-thinking mode), Qwen3-Instruct series/1.7b/4b (thinking mode), QVQ series, qwen-max, qwen2.5-vl series, qwen-vl-max series, qwen-vl-plus, Qwen3-VL (non-thinking): 1.5;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 are 0.0.DeepSeek series (supplied by Alibaba Cloud): deepseek-r1, deepseek-r1-0528, deepseek-r1-distill-qwen distilled version: 1;Kimi series (supplied by Alibaba Cloud): kimi-k2.7-code, kimi-k2.6, kimi-k2.5: 0.0;Kimi series (supplied by Moonshot AI): 0.0;MiniMax series (supplied by Alibaba Cloud): MiniMax-M2.5, MiniMax-M2.1: 0.0;Other DeepSeek, Kimi, GLM, and MiniMax models have no default value.
How it works If the parameter value is positive, the model applies a penalty to tokens that already exist in the text. The penalty is not related to the number of times the token appears. This reduces the likelihood of these tokens reappearing, thus reducing content repetition and increasing word diversity.
Example Prompt: Translate this sentence 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 movie is great. The plot is fantastic, the acting is superb, and the music is also very beautiful. Overall, the entire film is just incredible. It is actually truly outstanding. The storyline is very exciting, the performances are excellent, and the soundtrack is so moving.Parameter value 0.0: This movie is good. The plot is good, the acting is good, and the music is good. Overall, the whole movie is very good. In fact, it is really great. The plot is very good, the acting is also very excellent, and the music is equally outstanding.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. In fact, it is really good. The plot is very good, the acting is very good, and the music is very good. When you use the qwen-vl-plus model for text extraction, set presence_penalty to 1.5. Do not modify the default presence_penalty value for QVQ models. The Java SDK does not support setting this parameter*.* When you call over HTTP, place presence_penalty in the parameters object.vl_high_resolution_images boolean(Optional) Default value: falseSpecifies whether to increase the pixel limit for input images to the pixel count that corresponds to 16384 tokens. For more information, see Processing high-resolution images.
In the Java SDK, this parameter is vlHighResolutionImages (requires V2.20.8 or later). When you call over HTTP, place vl_high_resolution_images in the parameters object.vl_enable_image_hw_output boolean(Optional) The default value is false.Specifies whether to return the dimensions of the scaled image. The model scales the input image. If you set this parameter to True, it returns the height and width of the scaled image. If streaming output is enabled, this information is returned in the last chunk. This is supported by Qwen-VL models.In the Java SDK, this parameter is vlEnableImageHwOutput. The minimum required Java SDK version is 2.20.8*.* When you call over HTTP, place vl_enable_image_hw_output in the parameters object.max_tokens integer(Optional, to be deprecated)
This parameter will be deprecated. For new integrations, use The meaning of this parameter varies by model:
In the Java SDK, this parameter is maxTokens. For Qwen-VL models, it is maxLength in the Java SDK, but versions later than 2.18.4 also support setting it as max_completion_tokensinteger(Optional)The maximum length of the model's output, including the chain-of-thought and the model's answer. If the model's output exceeds this value, generation stops early, and the returned finish_reason is length.The default and maximum values are both the model's maximum output length.Difference from max_tokens: max_completion_tokens limits the complete model output (chain-of-thought + answer), while max_tokens only limits the answer part. For thinking models, we recommend that you use max_completion_tokens.The following models are supported:
The models listed above do not include models supplied directly by third parties.
There may be a difference of up to 10 tokens between the actual output token count and the specified The Java SDK does not currently support this parameter. When you call over HTTP, place max_completion_tokens in the parameters object.seed integer(Optional)A random number seed. This parameter is used to ensure reproducible results with the same input and parameters. If you pass the same seed value in a call and other parameters remain unchanged, the model returns the same result as much as possible.Value range: [0,2<sup>31</sup>−1].When you call over HTTP, place seed in the parameters object.stream boolean(Optional)The default value is false.Specifies whether to stream the reply. The valid values are:
This parameter is supported only by the Python SDK. To implement streaming output with the Java SDK, call the Qwen3 commercial edition (thinking mode), Qwen3 open source edition, QwQ, and QVQ support only streaming output.incremental_output boolean(Optional) The default is false. For Qwen3-Max, Qwen3-VL, Qwen3 open source edition, QwQ, and QVQ models, the default is true.Specifies whether to enable incremental output in streaming output mode. We recommend that you set this parameter to true.Value:
In the Java SDK, this parameter is incrementalOutput. When you call over HTTP, place incremental_output in the parameters object. QwQ models and Qwen3 models in thinking mode support only setting this parameter to
Qwen3 open source edition models do not support setting this parameter to response_formatobject (Optional) The default value is {"type": "text"}.The format of the returned content. The valid values are:
For more information, see Structured output. For a list of supported models, see Supported models.
If you specify
In the Java SDK, this parameter is
Properties type string(Required)The format of the returned content. The valid values are:
string(Optional)The default is text. For Qwen3-Max, Qwen3-VL, QwQ models, Qwen3 open source models (except qwen3-next-80b-a3b-instruct), the default is message.The format of the returned data. We recommend that you set this parameter to message to facilitate multi-turn conversations.
The platform will later unify the default value to In the Java SDK, this parameter is resultFormat. When you call over HTTP, place result_format in the parameters object.
If the model is Qwen-VL, QVQ, setting the value to Qwen3-Max, Qwen3-VL, and Qwen3 models in thinking mode can only be set to If you use the Java SDK to call a Qwen3 open source model and passlogprobs boolean (Optional) The default value is false.Specifies whether to return the log probabilities of the output tokens. The valid values are:
When you call over HTTP, place logprobs in the parameters object.top_logprobs integer (Optional) The default value is 0.Specifies the number of most likely candidate tokens to return at each generation step.Value range: [0, 5]This parameter takes effect only if logprobs is true.In the Java SDK, this parameter is topLogprobs. When you call over HTTP, place top_logprobs in the parameters object.n integer(Optional) The default value is 1.The number of responses to generate. The value range is 1-4. For scenarios that require multiple responses to be generated, such as creative writing or ad copy, you can set a larger n value.
Currently, only Qwen3 (non-thinking mode) models are supported. The value is fixed at 1 if the
Setting a larger When you call over HTTP, place n in the parameters object.stop string or array(Optional)Used to specify stop words. When a string or token_id specified in stop appears in the generated text, generation stops immediately.You can pass sensitive words to control the model's output.When stop is an array, you cannot input both When you call over HTTP, place stop in the parameters object.tools array(Optional)An array that contains one or more tool objects for the model to call during function calling. For more information, see Function calling.When you use tools, you must set result_format to message.When you initiate function calling or submit tool execution results, you must set the tools parameter.
Properties type string(Required)The tool type. Currently, only function is supported.functionobject(Required)
Properties name string(Required)The name of the tool function. It must consist of letters and numbers, and can contain underscores and hyphens. The maximum length is 64 characters.descriptionstring(Required)A description of the tool function, which helps the model to choose when and how to call the tool function.parametersobject(Optional) The default value is {}.A description of the tool's parameters, which needs to be a valid JSON Schema. For a description of JSON Schema, see this link. If the parameters parameter is empty, it means the tool has no input parameters, such as a time query tool.
To improve the accuracy of tool calls, we recommend that you pass When you call over HTTP, place tools in the parameters object. This is temporarily not supported for qwen-vl series models.tool_choice string or object(Optional) The default value is auto.The tool selection strategy. You can set this parameter to force a tool call method for a specific type of problem, such as always using a certain tool or disabling all tools.
In the Java SDK, this parameter is toolChoice. When you call over HTTP, place tool_choice in the parameters object.parallel_tool_calls boolean (Optional) The default value is false.Specifies whether to enable parallel tool calls.Valid values:
In the Java SDK, this parameter is parallelToolCalls. When you call over HTTP, place parallel_tool_calls in the parameters object. |
|
Chat response object (streaming and non-streaming output formats are consistent)status_codestringThe status code of the request. A value of 200 indicates that the request was successful. Otherwise, the request failed.The Java SDK does not return this parameter. If the call fails, an exception is thrown. The exception message contains the content of status_code and message.request_id stringThe unique ID for this call.The Java SDK returns the parameter as requestId.code stringThe error code. This field is empty if the call is successful.Only the Python SDK returns this parameter.output objectThe information about the call result.
Properties text stringThe reply that is generated by the model. If the input parameter result_format is set to text, the reply content is returned in this field.finish_reasonstringThis parameter is not empty if the input parameter result_format is set to text.This can occur in the following four situations:
arrayThe model's output information. The choices parameter is returned if result_format is message.
Properties finish_reason stringThe value can be one of the following:
objectThe message object that is output by the model.
Properties role stringThe role of the output message, which must be assistant.contentstring or arrayThe content of the output message. This is an array if you use qwen-vl or qwen-audio series models, and a string in other cases.If function calling is initiated, this value is empty.
Properties text stringThe content of the output message if you use qwen-vl or qwen-audio series models.image_hwarrayIf the vl_enable_image_hw_output parameter is enabled for a Qwen-VL series model, there are two cases:
stringThe model's deep thinking content.tool_callsarrayIf the model needs to call a tool, the tool_calls parameter is generated.
Properties function objectThe name of the tool that is being called and its input parameters.
Properties name stringThe name of the tool that is being called.argumentsstringThe parameters to be input into the tool, as a JSON string.Due to the randomness of the LLM's response, the output JSON string may not always satisfy your function. We recommend that you validate the parameters before you input them into the function. integerThe index of the current tool_calls object in the tool_calls array.id stringThe ID of this tool response.type stringThe tool type, which must be function.objectThe probability information for the current choices object.
Properties content arrayAn array of tokens with log probability information.
Properties token stringThe current token.bytes arrayA list of the raw UTF-8 bytes of the current token. This is useful for accurately reconstructing the output content, especially when you handle emojis and Chinese characters.logprob floatThe log probability of the current token. A null value indicates an extremely low probability.top_logprobs arrayThe most likely tokens at the current token position and their log probabilities. The number of elements is consistent with the input parameter top_logprobs.
Properties token stringThe current token.bytes arrayA list of the raw UTF-8 bytes of the current token. This is useful for accurately reconstructing the output content, especially when you handle emojis and Chinese characters.logprob floatThe log probability of the current token. A null value indicates an extremely low probability.mapThe token information for this chat request.
Properties input_tokens integerThe length of the user input content after it is converted to tokens. For more information, see Additional information.output_tokens integerThe length of the model output content after it is converted to tokens.input_tokens_details object (Optional)Details of the length of the input content after it is converted to tokens.
Properties text_tokens integer (Optional)The length of the input text after it is converted to tokens.image_tokens integer (Optional)The length of the input image after it is converted to tokens.video_tokens integer (Optional)The length of the input video file or image list after it is converted to tokens.integerThis field is returned if the input is plain text. It is the sum of input_tokens and output_tokens.image_tokens integerThis field is returned if the input content includes an image. It is the length of the user's input image content after it is converted to tokens.video_tokens integerThis field is returned if the input content includes a video. It is the length of the user's input video content after it is converted to tokens.audio_tokens integerThis field is returned if the input content includes an audio. It is the length of the user's input audio content after it is converted to tokens.output_tokens_details object (Optional)Details of the length of the output content after it is converted to tokens. This field is returned only by some models.
Properties text_tokens integer (Optional)The length of the output text after it is converted to tokens.reasoning_tokens integer (Optional)The length of the thinking process after it is converted to tokens. This field is returned only for reasoning models.audio_tokens integer (Optional)The length of the output audio after it is converted to tokens. This field is returned only for audio output models.objectA fine-grained classification of input tokens.
Properties cached_tokens integerThe number of tokens that hit the cache. For more information about context cache, see Context cache.cache_creation objectInformation about explicit cache creation.
Properties ephemeral_5m_input_tokens integerThe length of the tokens that are used to create an explicit cache with a 5-minute validity period.integerThe length of the tokens that are used to create an explicit cache.cache_type stringIf you use explicit caching, the parameter value is ephemeral. Otherwise, this parameter does not exist. |