Skip to main content

Qwen-OCR API reference

Extract text, structured data, and key information from images using the Qwen-OCR model. Qwen-OCR supports two API protocols: the OpenAI-compatible API and the DashScope API.

This topic describes the input and output parameters for calling the Qwen OCR models through the OpenAI-compatible API or the DashScope API.
Related topic: Text extraction (Qwen-OCR)

OpenAI-compatible API

  • China (Beijing) region
  • Singapore region
  • US (Virginia) region
The base_url for SDK calls: https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1The endpoint for HTTP calls: POST https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1/chat/completions
Alibaba Cloud Model Studio has released workspace-specific domains for the China (Beijing) and Singapore regions, which deliver superior performance and higher stability for inference requests. We recommend migrating to the new domains:
  • China (Beijing): from https://dashscope.aliyuncs.com to https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com
  • Singapore: from https://dashscope-intl.aliyuncs.com to https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com
{WorkspaceId} is your workspace ID, which you can view on the Workspace Details page in the Alibaba Cloud Model Studio console. The existing domains remain fully functional.
You must first obtain and configure an API key and set the API key as an environment variable. If you call the API through the OpenAI SDK, install the SDK.

Request body

modelstring (required)The model name. For supported models, see Select a model.messagesarray (required)The context passed to the model, arranged in conversation order.
User Messageobject (required)The user message, used to pass instructions and the images to recognize to the model.
contentarray (required)The message content.
typestring (required)Valid values:
  • text Set to text when inputting text.
  • image_url Set to image_url when inputting an image.
textstring (optional)The input text.Default value: Please output only the text content from the image without any additional descriptions or formatting., that is, by default the model extracts all text from the image.image_urlobjectInformation about the input image. Required when type is image_url.
url string (required)The image URL or Base64 Data URL. To pass a local file, see Text extraction.
min_pixelsinteger (optional)Sets the minimum pixel threshold for the input image, in pixels.When the input image has fewer pixels than min_pixels, the image is enlarged until the total number of pixels exceeds min_pixels.
The number of pixels corresponding to each image token varies by model:
  • qwen3.5-ocr, 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.
  • qwen3.5-ocr, qwen-vl-ocr-2025-11-20: the default and minimum values are both 3072 (that is, 3×32×32)
  • qwen-vl-ocr and earlier models: the default and minimum values are both 3136 (that is, 4×28×28).
Example value: {"type": "image_url","image_url": {"url":"https://xxxx.jpg"},"min_pixels": 3072}max_pixelsinteger (optional)Sets the maximum pixel threshold for the input image, in pixels.When the input image is within the [min_pixels, max_pixels] range, the model recognizes the original image. When the input image has more pixels than max_pixels, the image is reduced until the total number of pixels falls below max_pixels.
The number of pixels corresponding to each image token varies by model:
  • qwen3.5-ocr, 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.
  • qwen3.5-ocr, qwen-vl-ocr-2025-11-20
    • Default value: 8388608 (that is, 8192x32x32)
    • Maximum value: 30720000 (that is, 30000x32x32)
  • qwen-vl-ocr and earlier models
    • Default value: 6422528 (that is, 8192x28x28)
    • Maximum value: 23520000 (that is, 30000x28x28)
Example value: {"type": "image_url","image_url": {"url":"https://xxxx.jpg"},"max_pixels": 8388608}
rolestring (required)The role of the user message, fixed to user.
streamboolean (optional) Default value: falseWhether to return responses in streaming mode.Valid values:
  • false: waits until the model has generated the complete response and returns it all at once.
  • true: the model returns data chunks as it generates. The client must read the chunks one by one to reassemble the complete response.
stream_optionsobject (optional)Configuration items for streaming output, effective only when stream is true.

Attributes

include_usageboolean (optional) Default value: falseWhether to include token usage information in the last data chunk.Valid values:
  • true: included;
  • false: not included.
max_tokensinteger (optional)Limits the maximum number of tokens the model generates. If the generated content exceeds this value, the response is truncated.
  • qwen3.5-ocr: the default and maximum values are both 32768.
  • qwen-vl-ocr-2025-11-20, qwen-vl-ocr-2024-10-28: the default and maximum values are both the model's maximum output length. See Model selection.
  • qwen-vl-ocr: the default and maximum values are both 4096.
    To increase this value (within the 4097~8192 range), contact your business manager to apply, and provide the following information: primary account ID, image type (such as document images, e-commerce images, and contracts), model name, estimated QPS and total daily requests, and the percentage of requests whose model output length exceeds 4096.
logprobs boolean (optional) Default value: falseWhether to return the log probabilities of output tokens. Valid values:
  • true Return
  • false Do not return
top_logprobs integer (optional) Default value: 0Specifies the number of the most likely candidate tokens to return at each generation step.Value range: [0,5]Effective only when logprobs is true.temperaturefloat (optional) Default value: 0.01The sampling temperature, which controls the diversity of the text generated by the model.A higher temperature produces more diverse text, while a lower temperature produces more deterministic text.Value range: [0, 2)Both temperature and top_p control the diversity of generated text. We recommend setting only one of them.
We recommend keeping the default value.
top_pfloat (optional) Default value: 0.001The probability threshold for nucleus sampling, which controls the diversity of the text generated by the model.A higher top_p produces more diverse text, while a lower top_p produces more deterministic text.Value range: (0,1.0]Both temperature and top_p control the diversity of generated text. We recommend setting only one of them.
We recommend keeping the default value.
top_kinteger (optional) Default value: 1The size of the candidate set sampled during generation. For example, when set to 50, only the 50 highest-scoring tokens from a single generation form the random sampling candidate set. A larger value increases randomness, while a smaller value increases determinism. When set to None or greater than 100, the top_k policy is not enabled and only the top_p policy takes effect.The value must be greater than or equal to 0.This is not an OpenAI standard parameter. When calling through the Python SDK, put it in the extra_body object, configured as: extra_body={"top_k": xxx}; when calling through the Node.js SDK or HTTP, pass it as a top-level parameter.
We recommend keeping the default value.
repetition_penaltyfloat (optional) Default value: 1.0The repetition level in consecutive sequences during model generation. Increasing repetition_penalty reduces the repetition in model output, and 1.0 means no penalty. This parameter has a significant impact on model performance, so we recommend keeping the default value.
We recommend keeping the default value.
presence_penalty float (optional) Default value: 0.0Controls the content repetition level when the model generates text.Value range: [-2.0, 2.0]. Positive values reduce repetition, and negative values increase it.We recommend increasing this value in scenarios that require diversity, fun, or creativity such as creative writing or brainstorming; we recommend decreasing it in scenarios that emphasize consistency and terminology accuracy such as technical documents or formal text.
If the parameter value is positive, the model applies a penalty to tokens already present in the current text (the penalty is independent of how many times the text appears), reducing the chance of these tokens appearing again, thereby reducing content repetition and increasing word diversity.
We recommend keeping the default value.
seedinteger (optional)The random number seed, used to ensure that results are reproducible with the same input and parameters. If the same seed is passed with other parameters unchanged, the model will return the same result as much as possible.Value range: [0,2 31 −1].
We recommend keeping the default value.
stopstring or array (optional)Specifies stop words. When a string or token_id specified by stop appears in the text generated by the model, generation stops immediately.You can pass sensitive words to control the model output.
When stop is an array, you cannot mix token_id and strings as elements, for example, you cannot specify ["Hello",104307].
  • Non-streaming output
  • Streaming output
Python
from openai import OpenAI
import os

PROMPT_TICKET_EXTRACTION = """
Please extract the invoice number, train number, departure station, arrival station, departure date and time, seat number, seat class, ticket price, ID card number, and passenger name from the train ticket image.
You must accurately extract the key information. Do not omit or fabricate information. Replace any single character that is blurry or obscured by strong light with an English question mark (?).
Return the data in JSON format as follows: {'invoice_number': 'xxx', 'departure_station': 'xxx', 'arrival_station': 'xxx', 'departure_date_and_time':'xxx', 'seat_number': 'xxx','ticket_price':'xxx', 'id_card_number': 'xxx', 'passenger_name': 'xxx'},
"""

try:
    client = OpenAI(
        # If the environment variable is not configured, replace the following line with your Model Studio API key: api_key="sk-xxx"
        # API keys differ by region. Get an API key: https://help.aliyun.com/zh/model-studio/get-api-key
        api_key=os.getenv("DASHSCOPE_API_KEY"),
        # The following is the base_url for the China (Beijing) region. For the US (Virginia) region, replace base_url with https://{WorkspaceId}.us-east-1.maas.aliyuncs.com/compatible-mode/v1
        # For the Singapore region, replace base_url with: https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1
        base_url="https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1",
    )
    completion = client.chat.completions.create(
        model="qwen3.5-ocr",
        messages=[
            {
                "role": "user",
                "content": [
                    {
                        "type": "image_url",
                        "image_url": {"url":"https://img.alicdn.com/imgextra/i2/O1CN01ktT8451iQutqReELT_!!6000000004408-0-tps-689-487.jpg"},
                        # Minimum pixel threshold for the input image. Images below this value are enlarged until the total pixels exceed min_pixels
                        "min_pixels": 32 * 32 * 3,
                        # Maximum pixel threshold for the input image. Images above this value are reduced until the total pixels fall below max_pixels
                        "max_pixels": 32 * 32 * 8192
                    },
                    # The model supports passing a prompt in the text field below. If not passed, the default prompt is used: Please output only the text content from the image without any additional descriptions or formatting.
                    {"type": "text",
                     "text": PROMPT_TICKET_EXTRACTION}
                ]
            }
        ])
    print(completion.choices[0].message.content)
except Exception as e:
    print(f"Error message: {e}")

chat response object (non-streaming output)

idstringThe unique identifier of this request.choicesarrayThe array of content generated by the model.

Attributes

finish_reasonstringThe reason the model stopped generating.There are two cases:
  • stop when output ends naturally;
  • length when generation ends because the output is too long.
indexintegerThe index of the current object in the choices array.messageobjectThe message output by the model.

Attributes

content stringThe result returned by the model.processed_text stringThe post-processed result of the model's raw output, which automatically removes repeated segments. When the model output contains repeated content, this field provides the cleaned text.
Returned only when called through the DashScope SDK and curl. The OpenAI-compatible SDK does not return this field.
refusal stringThis parameter is currently fixed to null.role stringThe role of the message, fixed to assistant.audio objectThis parameter is currently fixed to null.function_call objectThis parameter is currently fixed to null.tool_calls arrayThis parameter is currently fixed to null.
createdintegerThe timestamp when this request was created.modelstringThe model used for this request.object stringAlways chat.completion.service_tier stringThis parameter is currently fixed to null.system_fingerprintstringThis parameter is currently fixed to null.usage objectThe token usage information of this request.
completion_tokens integerThe number of tokens generated by the model.prompt_tokens integerThe number of input tokens.total_tokens integerThe total number of tokens consumed, the sum of prompt_tokens and completion_tokens.completion_tokens_details objectThe fine-grained classification of output tokens.
accepted_prediction_tokensintegerThis parameter is currently fixed to null.audio_tokens integerThis parameter is currently fixed to null.reasoning_tokens integerThis parameter is currently fixed to null.text_tokens integerThe number of tokens corresponding to the model's text output.rejected_prediction_tokensintegerThis parameter is currently fixed to null.
prompt_tokens_details objectThe fine-grained classification of input tokens.
audio_tokens integerThis parameter is currently fixed to null.cached_tokens integerThis parameter is currently fixed to null.text_tokens integerThe number of tokens corresponding to the model's text input.image_tokens integerThe number of tokens corresponding to the model's image input.
{
  "id": "chatcmpl-ba21fa91-dcd6-4dad-90cc-6d49c3c39094",
  "choices": [
    {
      "finish_reason": "stop",
      "index": 0,
      "logprobs": null,
      "message": {
        "content": "```json\n{\n    \"seller_name\": \"null\",\n    \"buyer_name\": \"Cai Yingshi\",\n    \"price_excluding_tax\": \"230769.23\",\n    \"organization_code\": \"null\",\n    \"invoice_code\": \"142011726001\"\n}\n```",
        "refusal": null,
        "role": "assistant",
        "annotations": null,
        "audio": null,
        "function_call": null,
        "tool_calls": null
      }
    }
  ],
  "created": 1763283287,
  "model": "qwen3.5-ocr",
  "object": "chat.completion",
  "service_tier": null,
  "system_fingerprint": null,
  "usage": {
    "completion_tokens": 72,
    "prompt_tokens": 1185,
    "total_tokens": 1257,
    "completion_tokens_details": {
      "accepted_prediction_tokens": null,
      "audio_tokens": null,
      "reasoning_tokens": null,
      "rejected_prediction_tokens": null,
      "text_tokens": 72
    },
    "prompt_tokens_details": {
      "audio_tokens": null,
      "cached_tokens": null,
      "image_tokens": 1001,
      "text_tokens": 184
    }
  }
}

chat response chunk object (streaming output)

idstringThe unique identifier of this call. Each chunk object has the same id.choicesarrayThe array of content generated by the model. Empty in the last chunk if include_usage is set to true.

Attributes

delta objectThe output content returned in streaming mode.

Attributes

content stringThe result returned by the model.function_call objectThis parameter is currently fixed to null.refusal objectThis parameter is currently fixed to null.role stringThe role of the message object, which only has a value in the first chunk.
finish_reasonstringThe reason the model stopped generating. There are three cases:
  • stop when output ends naturally;
  • null when generation is not finished;
  • length when generation ends because the output is too long.
index integerThe index of the current response in the choices array.
createdintegerThe timestamp when this request was created. Each chunk has the same timestamp.modelstringThe model used for this request.object stringAlways chat.completion.chunk.service_tier stringThis parameter is currently fixed to null.system_fingerprintstringThis parameter is currently fixed to null.usage objectThe tokens consumed by this request. Returned only in the last chunk when include_usage is true.
completion_tokens integerThe number of tokens generated by the model.prompt_tokens integerThe number of input tokens.total_tokens integerThe total number of tokens consumed, the sum of prompt_tokens and completion_tokens.completion_tokens_details objectThe fine-grained classification of output tokens.
accepted_prediction_tokensintegerThis parameter is currently fixed to null.audio_tokens integerThis parameter is currently fixed to null.reasoning_tokens integerThis parameter is currently fixed to null.text_tokens integerThe number of tokens corresponding to the model's text output.rejected_prediction_tokensintegerThis parameter is currently fixed to null.
prompt_tokens_details objectThe fine-grained classification of input tokens.
audio_tokens integerThis parameter is currently fixed to null.cached_tokens integerThis parameter is currently fixed to null.text_tokens integerThe number of tokens corresponding to the model's text input.image_tokens integerThe number of tokens corresponding to the model's image input.
{"id":"chatcmpl-f6fbdc0d-78d6-418f-856f-f099c2e4859b","choices":[{"delta":{"content":"","function_call":null,"refusal":null,"role":"assistant","tool_calls":null},"finish_reason":null,"index":0,"logprobs":null}],"created":1764139204,"model":"qwen3.5-ocr","object":"chat.completion.chunk","service_tier":null,"system_fingerprint":null,"usage":null}
{"id":"chatcmpl-f6fbdc0d-78d6-418f-856f-f099c2e4859b","choices":[{"delta":{"content":"```","function_call":null,"refusal":null,"role":null,"tool_calls":null},"finish_reason":null,"index":0,"logprobs":null}],"created":1764139204,"model":"qwen3.5-ocr","object":"chat.completion.chunk","service_tier":null,"system_fingerprint":null,"usage":null}
{"id":"chatcmpl-f6fbdc0d-78d6-418f-856f-f099c2e4859b","choices":[{"delta":{"content":"json","function_call":null,"refusal":null,"role":null,"tool_calls":null},"finish_reason":null,"index":0,"logprobs":null}],"created":1764139204,"model":"qwen3.5-ocr","object":"chat.completion.chunk","service_tier":null,"system_fingerprint":null,"usage":null}
{"id":"chatcmpl-f6fbdc0d-78d6-418f-856f-f099c2e4859b","choices":[{"delta":{"content":"\n","function_call":null,"refusal":null,"role":null,"tool_calls":null},"finish_reason":null,"index":0,"logprobs":null}],"created":1764139204,"model":"qwen3.5-ocr","object":"chat.completion.chunk","service_tier":null,"system_fingerprint":null,"usage":null}
{"id":"chatcmpl-f6fbdc0d-78d6-418f-856f-f099c2e4859b","choices":[{"delta":{"content":"{\n","function_call":null,"refusal":null,"role":null,"tool_calls":null},"finish_reason":null,"index":0,"logprobs":null}],"created":1764139204,"model":"qwen3.5-ocr","object":"chat.completion.chunk","service_tier":null,"system_fingerprint":null,"usage":null}
{"id":"chatcmpl-f6fbdc0d-78d6-418f-856f-f099c2e4859b","choices":[{"delta":{"content":"   ","function_call":null,"refusal":null,"role":null,"tool_calls":null},"finish_reason":null,"index":0,"logprobs":null}],"created":1764139204,"model":"qwen3.5-ocr","object":"chat.completion.chunk","service_tier":null,"system_fingerprint":null,"usage":null}
......
{"id":"chatcmpl-f6fbdc0d-78d6-418f-856f-f099c2e4859b","choices":[{"delta":{"content":"```","function_call":null,"refusal":null,"role":null,"tool_calls":null},"finish_reason":null,"index":0,"logprobs":null}],"created":1764139204,"model":"qwen3.5-ocr","object":"chat.completion.chunk","service_tier":null,"system_fingerprint":null,"usage":null}
{"id":"chatcmpl-f6fbdc0d-78d6-418f-856f-f099c2e4859b","choices":[{"delta":{"content":"","function_call":null,"refusal":null,"role":null,"tool_calls":null},"finish_reason":"stop","index":0,"logprobs":null}],"created":1764139204,"model":"qwen3.5-ocr","object":"chat.completion.chunk","service_tier":null,"system_fingerprint":null,"usage":null}
{"id":"chatcmpl-f6fbdc0d-78d6-418f-856f-f099c2e4859b","choices":[],"created":1764139204,"model":"qwen3.5-ocr","object":"chat.completion.chunk","service_tier":null,"system_fingerprint":null,"usage":{"completion_tokens":141,"prompt_tokens":513,"total_tokens":654,"completion_tokens_details":{"accepted_prediction_tokens":null,"audio_tokens":null,"reasoning_tokens":null,"rejected_prediction_tokens":null,"text_tokens":141},"prompt_tokens_details":{"audio_tokens":null,"cached_tokens":null,"image_tokens":332,"text_tokens":181}}}

DashScope

  • China (Beijing) region
  • Singapore region
  • US (Virginia) region
The endpoint for HTTP calls: POST https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generationNo region configuration is required for SDK calls (defaults to cn-beijing).
You must first obtain and configure an API key and set the API key as an environment variable. If you call the API through the DashScope SDK, install the DashScope SDK.

Request body

modelstring (required)The model name. For supported models, see Select a model.messagesarray (required)The context passed to the model, arranged in conversation order.
When calling through HTTP, put messages in the input object.
User Messageobject (required)The user message, used to pass questions, instructions, or context to the model.
contentstring or array (required)The message content. If the input is text only, it is of string type; if the input contains image data, it is of array type.
textstring (optional)The input text.Default value: Please output only the text content from the image without any additional descriptions or formatting., that is, by default the model extracts all text from the image.imagestring (optional)The image URL, Base64 Data URL, or local path. To pass a local file, see Passing local files.Example value: {"image":"https://xxxx.jpeg"}enable_rotateboolean (optional) Default value: falseWhether to correct skewed images.Valid values:
  • true: automatic correction
  • false: no correction
Example value: {"image":"https://xxxx.jpeg","enable_rotate": True}min_pixelsinteger (optional)Sets the minimum pixel threshold for the input image, in pixels.When the input image has fewer pixels than min_pixels, the image is enlarged until the total number of pixels exceeds min_pixels.
The number of pixels corresponding to each image token varies by model:
  • qwen3.5-ocr, 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.
  • qwen3.5-ocr, qwen-vl-ocr-2025-11-20: the default and minimum values are both 3072 (that is, 3×32×32)
  • qwen-vl-ocr and earlier models: the default and minimum values are both 3136 (that is, 4×28×28).
Example value: {"image":"https://xxxx.jpeg","min_pixels": 3072}max_pixelsinteger (optional)Sets the maximum pixel threshold for the input image, in pixels.When the input image is within the [min_pixels, max_pixels] range, the model recognizes the original image. When the input image has more pixels than max_pixels, the image is reduced until the total number of pixels falls below max_pixels.
The number of pixels corresponding to each image token varies by model:
  • qwen3.5-ocr, 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.
  • qwen3.5-ocr, qwen-vl-ocr-2025-11-20
    • Default value: 8388608 (that is, 8192x32x32)
    • Maximum value: 30720000 (that is, 30000x32x32)
  • qwen-vl-ocr and earlier models
    • Default value: 6422528 (that is, 8192x28x28)
    • Maximum value: 23520000 (that is, 30000x28x28)
Example value: {"image":"https://xxxx.jpeg","max_pixels": 8388608}
rolestring (required)The role of the user message, fixed to user.
max_tokensinteger (optional)Limits the maximum number of tokens the model generates. If the generated content exceeds this value, the response is truncated.
  • qwen3.5-ocr: the default and maximum values are both 32768.
  • qwen-vl-ocr-2025-11-20, qwen-vl-ocr-2024-10-28: the default and maximum values are both the model's maximum output length. See Model selection.
  • qwen-vl-ocr: the default and maximum values are both 4096.
    To increase this value (within the 4097~8192 range), contact your business manager to apply, and provide the following information: primary account ID, image type (such as document images, e-commerce images, and contracts), model name, estimated QPS and total daily requests, and the percentage of requests whose model output length exceeds 4096.
In the Java SDK, this is maxTokens. When calling through HTTP, put max_tokens in the parameters object.
ocr_optionsobject (optional)Parameters required when using the Qwen OCR model to call a built-in task. When calling a built-in task, you do not need to pass a User Message; the model uses the prompt of the corresponding task internally. For more information, see Calling built-in tasks.
task string (required)The name of the built-in task. Valid values:
  • 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: multi-language recognition
  • advanced_recognition: high-precision recognition
task_config object (optional)When task is set to key_information_extraction, this parameter specifies the specific fields to extract. If task_config is not specified, the model extracts all fields from the image by default.
result_schemaobject (optional)The fields for the model to extract. It must be a JSON object structure with up to three levels of nested JSON objects.Specify the name of the field to extract in the key of the JSON object. The corresponding value can be empty. We recommend providing a field description or format requirements in the value to improve extraction accuracy.Example value:
"result_schema": {
     "invoice_number": "The unique identification number of the invoice, usually a combination of numbers and letters.",
     "issue_date": "The date the invoice was issued. Extract it in YYYY-MM-DD format, for example, 2023-10-26.",
     "seller_name": "The full company name of the seller shown on the invoice.",
     "total_amount": "The total amount on the invoice, including tax. Extract the numerical value and keep two decimal places, for example, 123.45."
}
In the Java SDK, this is OcrOptions. The minimum DashScope Python SDK version is 2.0.1, and the minimum Java SDK version is 2.18.4.
When calling through HTTP, put ocr_options in the parameters object.
seedinteger (optional)The random number seed, used to ensure that results are reproducible with the same input and parameters. If the same seed is passed with other parameters unchanged, the model will return the same result as much as possible.Value range: [0,2 31 −1].
We recommend keeping the default value.
When calling through HTTP, put seed in the parameters object.
temperaturefloat (optional) Default value: 0.01The sampling temperature, which controls the diversity of the text generated by the model.A higher temperature produces more diverse text, while a lower temperature produces more deterministic text.Value range: [0, 2)Both temperature and top_p control the diversity of generated text. We recommend setting only one of them.
We recommend keeping the default value.
When calling through HTTP, put temperature in the parameters object.
top_pfloat (optional) Default value: 0.001The probability threshold for nucleus sampling, which controls the diversity of the text generated by the model.A higher top_p produces more diverse text, while a lower top_p produces more deterministic text.Value range: (0,1.0]Both temperature and top_p control the diversity of generated text. We recommend setting only one of them.
We recommend keeping the default value.
In the Java SDK, this is topP. When calling through HTTP, put top_p in the parameters object.
top_kinteger (optional) Default value: 1The size of the candidate set sampled during generation. For example, when set to 50, only the 50 highest-scoring tokens from a single generation form the random sampling candidate set. A larger value increases randomness, while a smaller value increases determinism. When set to None or greater than 100, the top_k policy is not enabled and only the top_p policy takes effect.The value must be greater than or equal to 0.This is not an OpenAI standard parameter. When calling through the Python SDK, put it in the extra_body object, configured as: extra_body={"top_k": xxx}; when calling through the Node.js SDK or HTTP, pass it as a top-level parameter.
We recommend keeping the default value.
repetition_penaltyfloat (optional) Default value: 1.0The repetition level in consecutive sequences during model generation. Increasing repetition_penalty reduces the repetition in model output, and 1.0 means no penalty. This parameter has a significant impact on model performance, so we recommend keeping the default value.
We recommend keeping the default value.
In the Java SDK, this is repetitionPenalty. When calling through HTTP, put repetition_penalty in the parameters object.
presence_penalty float (optional) Default value: 0.0Controls the content repetition level when the model generates text.Value range: [-2.0, 2.0]. Positive values reduce repetition, and negative values increase it.We recommend increasing this value in scenarios that require diversity, fun, or creativity such as creative writing or brainstorming; we recommend decreasing it in scenarios that emphasize consistency and terminology accuracy such as technical documents or formal text.
If the parameter value is positive, the model applies a penalty to tokens already present in the current text (the penalty is independent of how many times the text appears), reducing the chance of these tokens appearing again, thereby reducing content repetition and increasing word diversity.
We recommend keeping the default value.
streamboolean (optional) Default value: falseWhether to return responses in streaming mode. Parameter values:
  • false: the model returns the result all at once after generating all content.
  • true: output while generating, that is, a chunk is returned immediately each time part of the content is generated.
This parameter is supported only by the Python SDK. For streaming output through the Java SDK, use the streamCall interface; for streaming output through HTTP, set X-DashScope-SSE to enable in the header.
incremental_outputboolean (optional) Default value: falseWhether to enable incremental output in streaming mode. We recommend setting it to true first.Parameter values:
  • false: each output is the entire sequence generated so far, and the last output is the complete result.
I
I like
I like apple
I like apple.
  • true (recommended): incremental output, that is, subsequent output does not contain the content already output. You need to read these chunks one by one in real time to obtain the complete result.
I
like
apple
.
In the Java SDK, this is incrementalOutput. When calling through HTTP, put incremental_output in the parameters object.
stopstring or array (optional)Specifies stop words. When a string or token_id specified by stop appears in the text generated by the model, generation stops immediately.You can pass sensitive words to control the model output.
When stop is an array, you cannot mix token_id and strings as elements, for example, you cannot specify ["Hello",104307].
logprobs boolean (optional) Default value: falseWhether to return the log probabilities of output tokens. Valid values:
  • true Return
  • false Do not return
Supported models: qwen-vl-ocr-2025-11-20 and later models
When calling through HTTP, put logprobs in the parameters object.
top_logprobs integer (optional) Default value: 0Specifies the number of the most likely candidate tokens to return at each generation step. Effective only when logprobs is true.Value range: [0,5]
In the Java SDK, this is topLogprobs. When calling through HTTP, put top_logprobs in the parameters object.
  • High-precision recognition
  • Key information extraction
  • Table parsing
  • Document parsing
  • Formula recognition
  • General text recognition
  • Multi-language recognition
  • Streaming output
The following is a code example for calling the high-precision recognition built-in task. For more information, see Calling built-in tasks.
python
import os
import dashscope

# The following is the URL for the China (Beijing) region. Replace {WorkspaceId} with your actual workspace ID when calling. The URL varies by region.
dashscope.base_http_api_url = "https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1"

messages = [{
            "role": "user",
            "content": [{
                "image": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241108/ctdzex/biaozhun.jpg",
                # Minimum pixel threshold for the input image. Images below this value are enlarged until the total pixels exceed min_pixels
                "min_pixels": 32 * 32 * 3,
                # Maximum pixel threshold for the input image. Images above this value are reduced until the total pixels fall below max_pixels
                "max_pixels": 32 * 32 * 8192,
                # Whether to enable automatic image rotation correction
                "enable_rotate": False}]
            }]

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"
    # API keys differ by region. Get an API key: https://help.aliyun.com/zh/model-studio/get-api-key
    api_key=os.getenv('DASHSCOPE_API_KEY'),
    model='qwen3.5-ocr',
    messages=messages,
    # Set the built-in task to high-precision recognition
    ocr_options={"task": "advanced_recognition"}
)
# The text and coordinate results of the high-precision recognition task are obtained from the ocr_result field
print(response["output"]["choices"][0]["message"].content[0]["ocr_result"])

chat response object (identical format for streaming and non-streaming output)

The following is the raw response returned by the HTTP interface. If the call fails, the Python SDK raises a DashScopeError exception, and you can obtain error information from the exception attributes e.status_code/e.code/e.message/e.request_id; a failed Java SDK call throws an exception whose message contains status_code and message.
request_idstringThe unique identifier of this call.
In the Java SDK, the return parameter is requestId.
outputobjectThe call result information.

Attributes

textstringThis parameter is currently fixed to null.finish_reasonstringThe reason the model stopped generating. There are the following cases:
  • null while generating;
  • stop when the model output ends naturally;
  • length when generation ends because the output is too long;
choicesarrayThe output information of the model.
finish_reasonstringThere are the following cases:
  • null while generating;
  • stop when the model output ends naturally;
  • length when generation ends because the output is too long;
messageobjectThe message object output by the model.
rolestringThe role of the output message, fixed to assistant.contentobjectThe content of the output message.
ocr_resultobjectThe task result information output when the Qwen-OCR series models call the built-in key information extraction or high-precision recognition tasks.
kv_resultarrayThe output result of the key information extraction task.words_infoarrayThe output result of the high-precision recognition task.
rotate_rect arrayExample value: [center_x, center_y, width, height, angle]The rotated rectangle representation of the text box:
  • center_x, center_y are the coordinates of the text box center
  • width is the width of the text box, height is the height
  • angle is the rotation angle of the text box relative to the horizontal direction, with a value range of [-90, 90]
location arrayExample value: [x1, y1, x2, y2, x3, y3, x4, y4]The coordinates of the four vertices of the text box, starting from the top-left corner and arranged clockwise in the order top-left → top-right → bottom-right → bottom-left.textstringThe content of the text line.
textstringThe content of the output message.
processed_textstringThe post-processed result of the model's raw output, which automatically removes repeated segments. When the model output contains repeated content, this field provides the cleaned text.
logprobsobjectThe probability information of the current choices object.
content arrayThe token array with log probability information.
token stringThe current token.bytes arrayThe list of raw UTF-8 bytes of the current token, used to precisely restore the output content, which is helpful for processing emoji and Chinese characters.logprob floatThe log probability of the current token. A null return value indicates an extremely low probability.top_logprobs arrayThe several most likely tokens at the current token position and their log probabilities. The number of elements is consistent with the input parameter top_logprobs.
token stringThe current token.bytes arrayThe list of raw UTF-8 bytes of the current token, used to precisely restore the output content, which is helpful for processing emoji and Chinese characters.logprob floatThe log probability of the current token. A null return value indicates an extremely low probability.
usageobjectThe token usage information of this request.

Attributes

input_tokens integerThe number of input tokens.output_tokens integerThe number of output tokens.characters integerThis parameter is currently fixed to 0.input_tokens_detailsobjectThe fine-grained classification of input tokens.
image_tokens integerThe number of tokens corresponding to the model's image input.text_tokens integerThe number of tokens corresponding to the model's text input.
output_tokens_detailsobjectThe fine-grained classification of output tokens.
text_tokens integerThe number of tokens corresponding to the model's text input.
total_tokens integerThe total number of tokens consumed, the sum of input_tokens and output_tokens.image_tokens integerThis field is returned when the input contains image. It is the length of the user's input image content after being converted into tokens.
{
  "request_id": "8f8c0f6e-6805-4056-bb65-d26d66080a41",
  "output": {
    "text": null,
    "finish_reason": null,
    "choices": [
      {
        "finish_reason": "stop",
        "message": {
          "role": "assistant",
          "content": [
            {
              "ocr_result": {
                "kv_result": {
                  "price_excluding_tax": "230769.23",
                  "invoice_code": "142011726001",
                  "organization_code": "null",
                  "buyer_name": "Cai Yingshi",
                  "seller_name": "null"
                }
              },
              "text": "```json\n{\n    \"price_excluding_tax\": \"230769.23\",\n    \"invoice_code\": \"142011726001\",\n    \"organization_code\": \"null\",\n    \"buyer_name\": \"Cai Yingshi\",\n    \"seller_name\": \"null\"\n}\n```",
              "processed_text": "```json\n{\n    \"price_excluding_tax\": \"230769.23\",\n    \"invoice_code\": \"142011726001\",\n    \"organization_code\": \"null\",\n    \"buyer_name\": \"Cai Yingshi\",\n    \"seller_name\": \"null\"\n}\n```"
            }
          ]
        }
      }
    ],
    "audio": null
  },
  "usage": {
    "input_tokens": 926,
    "output_tokens": 72,
    "characters": 0,
    "image_tokens": 754,
    "input_tokens_details": {
      "image_tokens": 754,
      "text_tokens": 172
    },
    "output_tokens_details": {
      "text_tokens": 72
    },
    "total_tokens": 998
  }
}

Error codes

If the model call fails and returns an error, see Error codes.