Parse text and images in PDF documents with 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 through Chat Completions or DashScope in Beijing.
Quick Start
The following examples demonstrate how to send a PDF file to the model.
You must have Obtain an API key and completed Configure API key as an environment variable.
- OpenAI Compatible
- DashScope
- Responses API
- Anthropic
- Python
- Node.js
- HTTP
Sample Code
Using Base64 Input
If you cannot provide a URL, you can pass the PDF file as a Base64-encoded string. The filename field is required when using file_data.
Base64 encoding increases the data size by about one third. For example, a 150 MB file becomes about 200 MB 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". For URL input, set source.type: "url" and source.url; for Base64 input, set source.type: "base64", source.media_type: "application/pdf", and source.data (a Base64 string without a Data URI prefix). URL input is supported by qwen3.8-max, qwen3.8-flash, and qwen4 series models. DashScope accepts files as items in the content array containing file_url or file_data.
The URL field only accepts a string. A list (array) of URLs is not supported.
Parameter | Type | Required | Description |
|---|---|---|---|
| file_url | string | Required (choose one of the two) | The download URL of the PDF file. Choose either this or file_data. |
| file_data | string | Base64-encoded PDF input in the format data:application/pdf;base64,xxx. Choose either this or 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 regular text requests. The first token timeout is up to 300 seconds. We recommend using streaming output to avoid long waits.
Billing
Billing involves the following:
- Model call fee: Text and images extracted from the PDF are counted as the model's input tokens and billed at the model's standard input token rate.
- Document parsing fee: Charged per page of the PDF document parsed. Unit prices vary by region: China (Beijing) ¥0.02 per page, Singapore ¥0.024 per page. Global deployment mode: CNY 0.02 per page.
View parsed PDF page count
For qwen4-max Responses, read the top-level tool_usage. Each tool’s num_requests is the billed request count; pdf_page_parser.num_requests is the parsed page count. Qwen3.8 Responses examples use usage.x_tools.
For Chat Completions and the Responses API (Qwen3.8), pass include_tool_usage: true at the top level of the request body and read usage.x_tools.pdf_page_parser.count. For DashScope, read usage.plugins.pdf_page_parser.count. The Anthropic-compatible API returns the count in the top-level response field x_tools.pdf_page_parser.count. An omitted count does not mean that no parsing fee was incurred.