PDF understanding enables the model to parse and comprehend PDF documents, extracting text and images for analysis. You can pass PDF files via URL or Base64 encoding.
Parse text and images in PDF documents with Chat Completions, the Responses API, DashScope, or the Anthropic-compatible API.
qwen4-max-preview (Token Plan only), qwen3.8-max, qwen3.8-max-0902, qwen3.8-flash, qwen3.8-27b
Run the following code to send a PDF file to the model.
Get a QwenCloud API key and configure it as an environment variable.
If you cannot provide a file URL, you can also pass the PDF file as a Base64-encoded string. When using
The following parameter table applies to Chat Completions. The Responses API uses
OpenAI-compatible format:
Billing involves the following:
For Chat Completions and the Responses API, pass
If a call fails, see Error messages.
Supported models
qwen4-max-preview (Token Plan only), qwen3.8-max, qwen3.8-max-0902, qwen3.8-flash, qwen3.8-27b
qwen3.8-27b supports PDF understanding only through Chat Completions or DashScope in China North 2 (Beijing).
Quick start
Run the following code to send a PDF file to the model.
Get a QwenCloud API key and configure it as an environment variable.
- OpenAI compatible
- DashScope
- Responses API
Base64 input
If you cannot provide a file URL, you can also pass the PDF file as a Base64-encoded string. When using file_data, the filename field is required.
Base64 encoding increases the data size by about 1/3. For example, a 150 MB file becomes roughly 200 MB after encoding, which exceeds the request body size limit. For large files, pass the file by URL instead.
- OpenAI compatible
- DashScope
- Anthropic
Python
Request parameters
The following parameter table applies to Chat Completions. The Responses API uses type: "input_file" and file_url. The Anthropic-compatible API uses type: "document" and sets type: "base64", media_type: "application/pdf", and data (a Base64 string without the Data URI prefix) in source. DashScope passes the file as an element containing file_url or file_data in the content array.
The URL field in the protocol only accepts a string. A list (array) of URLs is not supported.
| Parameter | Type | Required | Description |
|---|---|---|---|
file_url | string | One of the two required | The download URL of the PDF file. Mutually exclusive with file_data. |
file_data | string | One of the two required | Base64-encoded PDF input in the format data:application/pdf;base64,xxx. Mutually exclusive with file_url. |
filename | string | Conditionally required | The file name. Required when using file_data. |
file_format | string | No | The file format. Currently only pdf is supported. Defaults to pdf. |
Limits
| Item | Limit |
|---|---|
| Maximum file size | 150 MB |
| Maximum page count | 256 pages |
PDF parsing may take longer than a regular text request. The first-token timeout is up to 300 seconds. We recommend using streaming output to get results in real time and avoid long waits.
Billing
Billing involves the following:
- Model input tokens: Text and images parsed from the PDF are counted as input tokens, billed at the model's standard input token rate. For per-model input and output token prices, see Pricing.
- Document parsing fee: Charged per page of the PDF document parsed, corresponding to the metering item
document_parsing(pdf). Unit prices vary by region: China North 2 (Beijing) $0.003 per page, Singapore $0.0033 per page.
View PDF page count
For Chat Completions and the Responses API, pass include_tool_usage: true at the top level of the request body and read the page count from usage.x_tools.pdf_page_parser.count. For DashScope, read it from usage.plugins.pdf_page_parser.count. The Anthropic-compatible API returns the page count at the top level of the response in x_tools.pdf_page_parser.count. If the parse count is not returned, it does not mean that no parsing fee was incurred.