Skip to main content
Specialized models

Document mining (Qwen-Doc)

Extract structured data from documents with qwen-doc-turbo: information extraction, content moderation, classification, and summarization.

Document mining models are designed for information extraction, content moderation, classification, and summarization. Compared with general-purpose chat models, qwen-doc-turbo returns well-formed structured output, such as JSON, quickly and precisely, and extracts information more accurately. Supported regions: China North 2 (Beijing) only. Use an API key created in that region and https://cn-beijing.maas.qwencloudapi.com. See Regions and endpoints.

Supported models

ModelContext windowMax inputMax outputInput cost (per 1M tokens)Output cost (per 1M tokens)
qwen-doc-turbo262,144253,9528,192$0.087$0.144
Explicit cache is supported. Cache writes cost $0.109 per 1M tokens and cache hits cost $0.009 per 1M tokens.

Input methods

You can pass document content to qwen-doc-turbo in three ways. For file size and type limits, see Limitations.
File URL (recommended)File IDPlain text
SourcePublic URLLocal file (upload first)String in the request
Input limitUp to 10 files, up to 253k tokensOne file, up to 253k tokensUp to 9,000 tokens
API compatibilityDashScope onlyUpload: OpenAI compatible. Chat: OpenAI compatible and DashScopeOpenAI compatible and DashScope
AdvantagesNo upload, batch callsReuse without re-uploadingNo file management

Pass files by URL

Pass public file URLs and use a prompt to constrain the output format. The following example extracts product information from two product manuals as a JSON array.
Passing files by URL is supported only over the DashScope protocol. Use the DashScope Python SDK or a direct HTTP call such as curl.
import os
import dashscope

# China North 2 (Beijing). This model is available only in this region.
# API keys are region-specific. See https://docs.qwencloud.com/developer-guides/getting-started/regions
dashscope.base_http_api_url = "https://cn-beijing.maas.qwencloudapi.com/api/v1"

response = dashscope.Generation.call(
  api_key=os.getenv("DASHSCOPE_API_KEY"),
  model="qwen-doc-turbo",
  messages=[
    {"role": "system", "content": "You are a helpful assistant."},
    {
      "role": "user",
      "content": [
        {
          "type": "text",
          "text": "Extract all product information from these two product manuals into a JSON array. Each object must contain model, name, and price. Remove currency symbols and thousands separators from price."
        },
        {
          "type": "doc_url",
          "doc_url": [
            "https://example.com/product-manual-a.docx",
            "https://example.com/product-manual-b.docx"
          ],
          "file_parsing_strategy": "auto"
        }
      ]
    }
  ]
)

if response.status_code == 200:
  print(response.output.choices[0].message.content)
else:
  print(f"Status: {response.status_code}, code: {response.code}, message: {response.message}")
file_parsing_strategy controls how files are parsed:
ValueBehavior
autoThe system decides based on file content.
text_onlyParses text only.
text_and_imagesParses both text and images. Takes longer.

Pass files by file ID

Upload a file through the OpenAI-compatible Files API to get a file_id, then reference it in a system message.

Upload a file

import os
from pathlib import Path
from openai import OpenAI

# China North 2 (Beijing). This model is available only in this region.
# API keys are region-specific. See https://docs.qwencloud.com/developer-guides/getting-started/regions
client = OpenAI(
  api_key=os.getenv("DASHSCOPE_API_KEY"),
  base_url="https://cn-beijing.maas.qwencloudapi.com/compatible-mode/v1",
)

file_object = client.files.create(file=Path("product-manual-a.docx"), purpose="file-extract")
print(file_object.id)

Chat with the file

Put fileid://<FILE_ID> in a system message. The first system message sets the assistant role, and the user message contains the question about the file.
import os
from openai import OpenAI, BadRequestError

# China North 2 (Beijing). This model is available only in this region.
# API keys are region-specific. See https://docs.qwencloud.com/developer-guides/getting-started/regions
client = OpenAI(
  api_key=os.getenv("DASHSCOPE_API_KEY"),
  base_url="https://cn-beijing.maas.qwencloudapi.com/compatible-mode/v1",
)

try:
  completion = client.chat.completions.create(
    model="qwen-doc-turbo",
    messages=[
      {"role": "system", "content": "You are a helpful assistant."},
      {"role": "system", "content": "fileid://<FILE_ID>"},
      {"role": "user", "content": "Extract all product information from this manual into a JSON array. Each object must contain model, name, and price."}
    ],
    stream=True,
    stream_options={"include_usage": True}
  )

  full_content = ""
  for chunk in completion:
    if chunk.choices and chunk.choices[0].delta.content:
      full_content += chunk.choices[0].delta.content
  print(full_content)

except BadRequestError as e:
  print(f"Error: {e}")
If the file is still being parsed, the API returns File parsing in progress, please try again later. Wait and retry. A successful response means the file is ready.

Pass plain text

You can also pass document content as a string. To keep the model from confusing the role instruction with the document content, always put the role instruction in the first system message.
Because of request body size limits, use a file URL or file ID when the content exceeds 9,000 tokens.
import os
from openai import OpenAI, BadRequestError

# China North 2 (Beijing). This model is available only in this region.
# API keys are region-specific. See https://docs.qwencloud.com/developer-guides/getting-started/regions
client = OpenAI(
  api_key=os.getenv("DASHSCOPE_API_KEY"),
  base_url="https://cn-beijing.maas.qwencloudapi.com/compatible-mode/v1",
)

try:
  completion = client.chat.completions.create(
    model="qwen-doc-turbo",
    messages=[
      {"role": "system", "content": "You are a helpful assistant."},
      {"role": "system", "content": "<document text>"},
      {"role": "user", "content": "Extract all product information from this manual into a JSON array. Each object must contain model, name, and price."}
    ],
    stream=True,
    stream_options={"include_usage": True}
  )

  full_content = ""
  for chunk in completion:
    if chunk.choices and chunk.choices[0].delta.content:
      full_content += chunk.choices[0].delta.content
  print(full_content)

except BadRequestError as e:
  print(f"Error: {e}")

Parse the response

The model usually returns JSON, but it may wrap the output in a Markdown code fence. Strip the fence before calling json.loads():
import json

content = completion.choices[0].message.content
lines = [line for line in content.strip().split("\n") if not line.startswith("`")]
data = json.loads("\n".join(lines))

Limitations

  • File URL (doc_url): Supported only over the DashScope protocol. Up to 10 public URLs per request.
  • File ID: Upload and manage files with the OpenAI-compatible SDK only. One file per request. Each file can be up to 150 MB. Each account can store up to 10,000 files and 100 GB in total, with no expiry. Use the Files API to delete files and free quota.
  • Supported formats: TXT, DOC, DOCX, PDF, XLS, XLSX, MD, PPT, PPTX, JPG, JPEG, PNG, GIF, BMP.
  • Input: The context window is 262,144 tokens when content is passed by doc_url or file ID. A single plain-text message is limited to 9,000 tokens.
  • Output: Up to 8,192 tokens.

FAQ

Where are uploaded files stored? Files uploaded through the OpenAI-compatible Files API are stored in your QwenCloud account storage at no cost. See Files API to manage them. Can a file ID be reused with other models? File IDs can be used with document mining and with Batch calls. Does file parsing cost anything? No. Document parsing is free. How do I know a file has finished parsing? Try a chat request with the file ID. If parsing is still in progress, the API returns File parsing in progress, please try again later. Retry after a short wait.