Upload files for document Q&A and data extraction with Qwen-Long and Qwen-Doc-Turbo , or prepare input files for batch tasks.
Usage
Call the File API through the OpenAI SDK (Python or Java) or HTTP. Supported operations: upload, query, and delete.
Prerequisites
- An Alibaba Cloud Model Studio API key: Create an API key and Export the API key as environment variable.
- To use the OpenAI SDK, install the OpenAI SDK.
Supported models
File IDs apply to the following scenarios:
- Qwen-Long: Answer questions about a long document by specifying its file ID
- Qwen-Doc-Turbo: Extract data and perform Q&A on files.
- Batch processing: Upload batch files.
Getting started
Upload a file
Model Studio allows up to 10,000 files totaling 100 GB. Files do not expire. Uploads fail when either limit is reached. Delete unused files to free quota.
- For document analysis
- For batch processing
Set
purpose to file-extract. Supported formats: text (TXT, DOCX, PDF, XLSX, EPUB, MOBI, MD, CSV, JSON) and image (BMP, PNG, JPG/JPEG, GIF, scanned PDF). Maximum file size: 150 MB.Document analysis with a file_id: long context (Qwen-Long).
Request examples
Sample response
Query file information
Retrieve file details by file_id.
- OpenAI Python SDK
- OpenAI Java SDK
- HTTP
Request examples
Sample response
Query a list of files
Returns all your files, including uploaded files and batch result files.
Additional filtering parameters are available. Parameter description.
- OpenAI Python SDK
- OpenAI Java SDK
- HTTP
Request examples
Sample response
Delete a file
Deletes a file by file_id. To find file IDs, use the Query a list of files API.
- OpenAI Python SDK
- OpenAI Java SDK
- HTTP
Request examples
Sample response
Billing
File upload, storage, and query operations are free. You are billed only for input and output tokens consumed by model calls.
Rate limiting
File upload: 3 QPS. File query, list, and delete combined: 10 QPS.
Production checklist
- Periodic cleanup: Delete unused files regularly to stay within the 10,000-file limit.
- Status check: Verify the
statusisprocessedbefore using a file. - Rate limit check: Upload: 3 QPS. Query, list, and delete combined: 10 QPS.
- Error handling: Implement exception handling for network and API errors.
FAQ
1. What do I do if the file status remains "processing" after upload?
Files are usually processed within seconds. If the status stays at "processing":
- Check whether the file format is supported.
- Check whether the file size exceeds the limit.
- Use the
retrieveAPI to periodically query the status.
2. Can file IDs be used across different accounts?
No. File IDs are scoped to the Alibaba Cloud account that created them.
3. Are uploaded files stored permanently?
Yes. Files persist until you delete them. Clean up unused files periodically.
4. Why did my file upload fail?
- The API key is invalid or missing.
- The file format is not supported.
- The file size exceeds the limit (file-extract: 150 MB, batch: 500 MB).
- The maximum number of files (10,000) or the total size limit (100 GB) has been reached.
- The file upload API has a QPS (Requests Per Second) limit of 3.
5. Which purpose value should I use?
file-extract: Document analysis with Qwen-Long or Qwen-Doc-Turbo.batch: Batch processing. File must be JSONL and meet format requirements.
Parameter description
| Interface Category | Parameter | Type | Required | Description | Example value |
|---|---|---|---|---|---|
| File upload | file | File | Yes | The file to upload. | Path("test.txt") |
| purpose | String | Yes | The intended use of the file. Format and size requirements vary by purpose. Valid values:file-extract: For document understanding and data extraction with the Qwen-Long and Qwen-Doc models.batch: For OpenAI compatible - Batch jobs. | "file-extract" | |
| File query | file_id | String | Yes | The ID of the file to query. | "file-fe-xxx" |
| after | String | No | Pagination cursor for the Query a list of files API.Set after to the file_id of the last item on the current page to fetch the next page.Example: if the last file_id is file-batch-xxx, set after="file-batch-xxx" to retrieve the next page. | "file-fe-xxx" | |
| create_before | String | No | Timestamp filter for the Query a list of files API. Returns files created before the specified time. | "20250306123000", "2025-11-12 10:10:10", "2025-11-12", "20251112" | |
| create_after | String | No | Timestamp filter for the Query a list of files API. Returns files created after the specified time. | "20250306123000", "2025-11-12 10:10:10", "2025-11-12", "20251112" | |
| purpose | String | No | Purpose filter for the Query a list of files API. Returns files matching the specified purpose (file-extract or batch). | "batch" | |
| limit | Integer | No | Number of files per page in the Query a list of files API. Range: 1-2,000. Default: 2,000. | 2000 | |
| File deletion | file_id | String | Yes | The ID of the file to delete. | "file-fe-xxx" |
| Response parameters | |||||
| Common response parameters | id | String | \ | The ID of the file.In a Delete a file task, this is the ID of the successfully deleted file. | "file-fe-xxx" |
| bytes | Integer | The size of the file in bytes. | 81067 | ||
| created_at | Integer | The UNIX timestamp in seconds when the file was created. | 1617981067 | ||
| filename | String | The name of the uploaded file. | "text.txt" | ||
| object | String | The object type.For a Query a list of files task, the value is always "list".In other tasks, this is always "file". | "file" | ||
| purpose | String | The purpose of the file. Valid values are batch, file-extract, batch_output. | "file-extract" | ||
| status | String | The current status of the file: uploaded (uploaded, awaiting parsing), processing (being parsed; wait until parsing completes before referencing it), processed (parsing complete, ready to reference), or error (parsing failed). | "processed" | ||
| Query file list | has_more | Boolean | Indicates whether there is a next page of data. | false | |
| data | Array | The returned list of files. The format of each element in the list is consistent with the common response parameters. | |||
| Delete file | deleted | Boolean | Indicates whether the deletion was successful. A value of true indicates success. | true | |