Skip to main content
Qwen-OCR

Qwen-OCR text extraction models

Extract text from images with Qwen-OCR through the DashScope native HTTP API.

POST
/api/v1/services/aigc/multimodal-generation/generation
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

string
header
required

API key authentication. Get an API key from the QwenCloud console.

Body

application/json
string
required

The name of the model. See Qwen-OCR for a list of supported models.

qwen-vl-ocr-2025-11-20
object
required

The input object containing messages.

object

Model parameters.

Response

200-application/json
integer

Request status code. 200 = success. Not returned by Java SDK.

string

Unique identifier for this call. Java SDK returns requestId.

string

Error code. Empty on success. Only returned by Python SDK.

string

Error message. Empty on success.

object

Call result information.

object

Token usage information.