Qwen-Long handles documents up to 10 million tokens through a file upload and reference mechanism, overcoming standard model context limits.
This document applies only to the Chinese mainland (Beijing) region. To use the model, you must use an API key from theChinese mainland (Beijing) region.
How to use
Use Qwen-Long in two steps: upload files, then call the API.
-
File upload and parsing:
- Upload a file using the API. For details about supported file formats and size limits, see Supported formats.
- After a successful upload, the system returns a unique
file-idfor your account and starts parsing. No fees are charged for file upload, storage, or parsing.
-
API call and billing:
- When you call the model, reference one or more
file-ids in thesystemmessage. - The model performs inference based on the text content associated with the
file-id. - For each API call, the number of tokens in the referenced file content is counted as input tokens for that request.
- When you call the model, reference one or more
Getting started
Prerequisites
- Obtain an API key and configure it as an environment variable.
- To call the model via SDK, install the OpenAI SDK.
Upload a document
This example uploads Model_Studio_Phone_Product_Introduction.docx to Model Studio's secure storage via the OpenAI-compatible interface and gets a file-id. See the API documentation for upload parameters.
Python
file-id for the uploaded file.
Pass information and chat using a file ID
Pass the file-id in system messages: first message defines the role, second contains the file-id, then add user questions.
Longer documents need more parsing time. Wait for parsing to complete before calling.
Python
Pass multiple documents
Pass multiple file-ids in one system message or add separate system messages for each document.
- Pass multiple documents
- Append documents
Python
Pass information as plain text
Instead of using file-ids, pass document content directly as a string. Add role settings in the first message to prevent confusion with document content.
If document content exceeds 1 million tokens, use a file ID instead due to API size limits.
- Simple example
- Pass multiple documents
- Append documents
You can input the document content directly into the System Message.
Python
Model pricing
| Model name | Version | Context length | Max input | Max output | Input cost | Output cost |
|---|---|---|---|---|---|---|
| (Tokens) | (per 1 million tokens) | |||||
qwen-long-latestAlways has the same capabilities as the latest snapshot version. | Latest | 10,000,000 | 10,000,000 | 32,768 | $0.072 | $0.287 |
qwen-long-2025-01-25Also known as qwen-long-0125. | Snapshot | |||||
FAQ
- Does the Qwen-Long model support submitting batch jobs? Yes. Qwen-Long supports the OpenAI Batch API at 50% of real-time call rates. Submit batch jobs as files; jobs run asynchronously and return results on completion or timeout.
- Where are files saved after they are uploaded using the OpenAI-compatible file API? Files are uploaded to your Model Studio bucket at no cost. See the OpenAI File API for querying and managing files.
-
What is
qwen-long-2025-01-25? This is a version snapshot frozen at a specific point in time. More stable thanlatest, with no expiration date. -
How can I know when a file has finished parsing?
To check parsing progress without repeated trial calls, query the file's status: call the retrieve file interface and check the
statusfield—processingmeans parsing is still in progress,processedmeans parsing is complete and the file can be referenced, anderrormeans parsing failed. Once the status isprocessed, you can call the model. For details, see the OpenAI File API. Alternatively, call the model with thefile-iddirectly: if parsing is incomplete, you'll get error 400: "File parsing in progress, please try again later."; a successful response means parsing is complete. -
How can I ensure the model outputs a JSON string in a standard format?
qwen-longand all snapshots support structured output. Specify a JSON Schema to ensure valid JSON that matches your structure.
API reference
Refer to Qwen API details for the input and output parameters of the Qwen-Long model.
Error codes
If the model call fails and returns an error message, see Error codes for resolution.
Limits
-
SDK dependencies:
- File operations (upload, delete, query) require an OpenAI-compatible SDK.
- Invoke models using an OpenAI-compatible SDK or Dashscope SDK.
-
File upload:
- Supported formats: TXT, DOCX, PDF, XLSX, EPUB, MOBI, MD, CSV, JSON, BMP, PNG, JPG/JPEG, and GIF.
- File size: The maximum size for image files is 20 MB. The maximum size for other file formats is 150 MB.
- Account quota: Maximum 10,000 files or 100 GB per account. Uploads fail when either limit is reached. Delete files to free quota. See OpenAI compatible - File.
- Storage period: Currently, there is no expiration limit for stored files.
-
API inputs:
- The first
systemmessage defines the role. The second contains document content orfileid://xxx. Theusermessage contains the query. - When referencing files using a
file-id, a single request can reference a maximum of 100 files. - With a second
systemmessage,usermessage limit is 9,000 tokens. No limit with only one system message. - The total context length is limited to 10 million tokens.
- The first
-
API outputs:
- The maximum output length is 32,768 tokens.
-
File sharing:
file-ids are account-specific and cannot be used cross-account or with RAM user API keys.
- Throttling: For information about model throttling conditions, see Throttling.