The PDF understanding feature enables models to parse text and images in PDF documents, and analyze them through Chat Completions, the Responses API, DashScope, or the Anthropic-compatible API.
Supported models
qwen4-max、qwen3.8-max、qwen3.8-max-0902、qwen3.8-flash、qwen3.8-27b
qwen3.8-27b supports PDF understanding only in the Beijing region via Chat Completions or DashScope.
QuickStart
Run the following code to pass a PDF file to the model.
You must have already obtained and configured an API Key and configured the API Key as an environment variable.
- OpenAI compatible
- DashScope
- Responses API
- Anthropic
- Python
- Node.js
- HTTP
Sample Code
Use Base64 input
If you cannot provide the file's URL address, 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 150MB file becomes about 200MB after encoding, which exceeds the request body size limit. For large files, use the URL method instead.
- Chat Completions / DashScope
- Anthropic
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 files via elements in the content array that contain file_url or file_data. For URL input, type is required and fixed to document; source is a required object, where type is a required string set to url, and url is a required string specifying the PDF file URL.
In the protocol, the URL part supports only string input, not the list (array) form.
Parameter | Type | Whether Required | Description |
|---|---|---|---|
| file_url | string | Required (choose one of the two) | The download address of the PDF file. Either this parameter or file_data is required. |
| file_data | string | The PDF file input in Base64 format, in the format data:application/pdf;base64,xxx. Either this parameter or file_url is required. | |
| filename | string | Conditionally required | The file name. Required when file_data is used as the input parameter. |
| file_format | string | No | The file format. Optional. Currently only pdf is supported, and the default is pdf. |
Limits
Item | Limit |
|---|---|
| Single file size limit | 150MB |
| Page limit per document | 256 pages |
PDF parsing may take longer than plain text requests. The first-token timeout can be up to 300 s. We recommend using streaming output to obtain results in real time and avoid long waits.
Billing Details
Billing involves the following aspects:
- Model invocation fees: The text and images parsed from the PDF file are counted toward the model's input tokens and billed at the model's standard input price.
- Document parsing fees: Billed by the number of parsed PDF pages, with unit prices varying by region: China (Beijing) $0.003/page, Singapore $0.0033/page. Global deployment mode: $0.003/page.
View the number of parsed PDF pages
The Responses API of qwen4-max uses the top-level tool_usage of the response, where num_requests of each tool is the number of billable calls, and pdf_page_parser.num_requests is the number of parsed pages. The Responses examples for Qwen3.8 still use usage.x_tools.
Chat Completions and the Responses API (Qwen3.8) can pass in include_tool_usage: true at the top level of the request body and view the number of parsed pages from usage.x_tools.pdf_page_parser.count; for DashScope, view it from usage.plugins.pdf_page_parser.count. The number of parsed pages returned by the Anthropic-compatible API is located at the top level of the response in x_tools.pdf_page_parser.count. If the parsing count is not returned, it does not mean that no parsing fee was incurred for this request.