import os
import dashscope
# Singapore (ap-southeast-1). For another region, replace ap-southeast-1 in the URL.
# API keys are region-specific. See https://docs.qwencloud.com/developer-guides/getting-started/regions
dashscope.base_http_api_url = 'https://ap-southeast-1.maas.qwencloudapi.com/api/v1'
messages = [{
"role": "user",
"content": [{
"image": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241108/ctdzex/biaozhun.jpg",
# The minimum pixel threshold for the input image. If the image is smaller than this value, it is scaled up until the total pixels are greater than min_pixels.
"min_pixels": 32 * 32 * 3,
# The maximum pixel threshold for the input image. If the image is larger than this value, it is scaled down until the total pixels are less than max_pixels.
"max_pixels": 32 * 32 * 8192,
# Specifies whether to enable automatic image rotation.
"enable_rotate": False}]
}]
response = dashscope.MultiModalConversation.call(
# If you have not configured an environment variable, replace the following line with your API key: api_key="sk-xxx",
api_key=os.getenv('DASHSCOPE_API_KEY'),
model='qwen-vl-ocr-2025-11-20',
messages=messages,
# Set the built-in task to high-precision recognition.
ocr_options={"task": "advanced_recognition"}
)
# The high-precision recognition task returns the result as plain text.
print(response["output"]["choices"][0]["message"].content[0]["text"]){
"status_code": 0,
"request_id": "<string>",
"code": "<string>",
"message": "<string>",
"output": {
"text": "<string>",
"finish_reason": "<string>",
"choices": [
{
"finish_reason": "<string>",
"message": {
"role": "assistant",
"content": [
{
"text": "<string>",
"ocr_result": {
"kv_result": {},
"words_info": [
{
"rotate_rect": [
0
],
"location": [
0
],
"text": "<string>"
}
]
}
}
],
"logprobs": {
"content": [
{
"token": "<string>",
"bytes": [
0
],
"logprob": 0,
"top_logprobs": [
{
"token": "<string>",
"bytes": [
0
],
"logprob": 0
}
]
}
]
}
}
}
]
},
"usage": {
"input_tokens": 0,
"output_tokens": 0,
"total_tokens": 0,
"characters": 0,
"image_tokens": 0,
"input_tokens_details": {
"image_tokens": 0,
"text_tokens": 0
},
"output_tokens_details": {
"text_tokens": 0
}
}
}Authorizations
API key authentication. Get an API key from the QwenCloud console.
Body
application/jsonThe name of the model. See Qwen-OCR for a list of supported models.
The input object containing messages.
Show child attributes
Show child attributes
The context for the model, provided as a sequence of messages.
Show child attributes
Show child attributes
Must be user.
The message content. Use an array for image input.
Show child attributes
Show child attributes
The input text. Default: Please output only the text content from the image without any additional descriptions or formatting.
The URL, Base64 Data URL, or local path of the image. For more information about passing a local file, see Passing local files.
Whether to correct skewed images.
The minimum pixel threshold for the input image in pixels. If an input image has a pixel count below min_pixels, it is enlarged until its total pixel count exceeds min_pixels.
Conversion between image tokens and pixels:
- qwen3.5-ocr and qwen-vl-ocr-2025-11-20: Each token corresponds to 32×32 pixels.
- qwen-vl-ocr and earlier models: Each token corresponds to 28×28 pixels.
Value range:
- qwen3.5-ocr and qwen-vl-ocr-2025-11-20: Default and minimum value is 3072 (3×32×32).
- qwen-vl-ocr and earlier models: Default and minimum value is 3136 (4×28×28).
The maximum pixel threshold for the input image in pixels. If the pixel count of the input image is within the [min_pixels, max_pixels] range, the model processes the original image without resizing. If the pixel count exceeds max_pixels, the image is scaled down until its pixel count is less than max_pixels.
Conversion between image tokens and pixels:
- qwen3.5-ocr and qwen-vl-ocr-2025-11-20: Each token corresponds to 32×32 pixels.
- qwen-vl-ocr and earlier models: Each token corresponds to 28×28 pixels.
Value range:
- qwen3.5-ocr and qwen-vl-ocr-2025-11-20: Default 8388608 (8192×32×32), maximum 30720000 (30000×32×32).
- qwen-vl-ocr and earlier models: Default 6422528 (8192×28×28), maximum 23520000 (30000×28×28).
Model parameters.
Show child attributes
Show child attributes
Configuration for built-in OCR tasks. When using a built-in task, the model uses a default prompt so you don't need to pass a User Message with text. Minimum SDK versions: Python 1.22.2, Java 2.18.4.
Show child attributes
Show child attributes
The built-in task name.
The maximum number of tokens to generate in the output. If the generated content exceeds this value, the response is truncated.
- For qwen3.5-ocr, qwen-vl-ocr-2025-11-20, and qwen-vl-ocr-2024-10-28, the default and maximum values are the same as the model's maximum output length.
A random number seed for reproducible results. Value range: [0, 2^31−1].
Sampling temperature. Higher = more diverse, lower = more deterministic. Range: [0, 2). Only set one of temperature or top_p.
Nucleus sampling threshold. Range: (0, 1.0]. Only set one of temperature or top_p.
Candidate set size for sampling. Larger = more random. Must be >= 0.
Penalty for repeated sequences. 1.0 means no penalty.
Controls content repetition. Range: [-2.0, 2.0].
Stop words. Can be a string or array. If stop is an array, you cannot mix token_ids and strings as elements.
Whether to return log probabilities. Supported: qwen-vl-ocr-2025-11-20 and later.
Number of most likely tokens to return per step. Range: [0, 5]. Only when logprobs is true.
When streaming, true returns only new content per chunk. false returns the full accumulated content.
Specifies whether to stream the response.
- Python SDK: Set
stream=Truein the call. - Java SDK: Use the
streamCallinterface. - HTTP: Set
X-DashScope-SSE: enablein the request header.
Response
Request status code. 200 = success. Not returned by Java SDK.
Unique identifier for this call. Java SDK returns requestId.
Error code. Empty on success. Only returned by Python SDK.
Error message. Empty on success.
Call result information.
Show child attributes
Show child attributes
Currently fixed to null.
null during generation, stop when complete, length when truncated.
Model output.
Show child attributes
Show child attributes
null during generation, stop when complete, length when truncated.
Show child attributes
Show child attributes
Always assistant.
Output message content.
Show child attributes
Show child attributes
Text content of the output.
Returned for information extraction (key_information_extraction) and high-precision recognition (advanced_recognition) tasks.
Show child attributes
Show child attributes
Result of the information extraction task.
Token usage information.
Show child attributes
Show child attributes
Number of input tokens.
Number of output tokens.
Sum of input_tokens and output_tokens.
Currently fixed to 0.
Tokens for image input.