Overview
This API is an OpenAI compatible files API. When purpose=batch, it is used for uploading a batch task input file. Currently, this API is supported only by Alibaba Cloud's Qwen series of models.
Prerequisites
When purpose=batch, you need to prepare a JSONL-formatted (*.jsonl) batch task input file. Each line in the file represents an independent JSON object, indicating one batch request. The preparation requirements are as follows:
Each line must be a valid JSON object, separated by line breaks.
It is recommended to use the same
modelin a JSONL file to avoid processing exceptions in batch tasks due to different models.Each JSON object line contains the following fields:
FieldDescriptioncustom_id A custom request ID used to match the corresponding request and response in the batch results. It must be unique within the same file. method The request method. Currently, only POSTis supported.url The request path, for example, /v1/chat/completions.body The request body, containing parameters such as modelandmessages. The format is consistent with that of the corresponding Chat Completion API request body.
The following is an example of a test_model.jsonl file:
{"custom_id":"1","method":"POST","url":"/v1/chat/completions","body":{"model":"batch-test-model","messages":[{"role":"system","content":"You are a helpful assistant."},{"role":"user","content":"Hello! How can I help you?"}]}}
{"custom_id":"2","method":"POST","url":"/v1/chat/completions","body":{"model":"batch-test-model","messages":[{"role":"system","content":"You are a helpful assistant."},{"role":"user","content":"What is 2+2?"}]}}
API details
Constraints
- The caller must have an API Key. For more information, see Manage AI API Keys.
- This API is a general-purpose files API that supports file uploads for multiple purposes.
Request path
POST {BASE_URL}/api/v1/files
Request header
Name |
Required |
Example value |
Description |
|---|---|---|---|
| Authorization | Yes | Bearer {token} | Authentication information |
| Content-Type | No | multipart/form-data | Request body format |
Request parameters
Path
None
Query
None
Body
Name |
Type |
Required |
Example value |
Description |
|---|---|---|---|---|
| file | string | Yes | - | File content |
| purpose | string | Yes | batch | File usage. Valid values:batch(batch task input file) |
Response
Response parameters
Name |
Type |
Description |
|---|---|---|
| success | boolean | Whether the request was successful |
| code | string | Response code |
| message | string | Response information |
| data | object | Business response data |
data
Name |
Type |
Description |
|---|---|---|
| id | string | Unique ID of the file |
| object | string | Object type, for example,file |
| bytes | integer | File size (bytes) |
| created_at | integer | File creation time |
| filename | string | File name |
| purpose | string | File purpose |
Request example
curl --request POST '{BASE_URL}/api/v1/files' \
--header 'Authorization: Bearer {token}' \
--header 'Content-Type: multipart/form-data' \
--form 'file=@"/path/to/test_model.jsonl"' \
--form 'purpose="batch"'
Response example
{
"success": true,
"code": "200",
"message": "successful",
"data": {
"id": "file-123456",
"object": "file",
"bytes": 1024,
"created_at": 1712736000,
"filename": "your_file.jsonl",
"purpose": "batch"
}
}
