For inference scenarios that do not require real-time responses, batch inference can asynchronously process large batches of data requests at only 50% of the cost of real-time inference, with an OpenAI-compatible API. It is ideal for batch jobs such as model evaluation and data annotation.
How it works
- Submit the task: Upload a JSONL file containing multiple requests to create a batch inference task.
- Asynchronous processing: The system processes the task in a background queue. You can query task progress and status via the console or API.
- Download the results: After the task is completed, the system generates a result file (recording successful responses) and an error file (recording failure details, if any).
Applicable scope
- Singapore
- China (Beijing)
-
Text generation models
- Qwen Max: qwen3.8-max, qwen-max
- Qwen Plus: qwen3.7-plus, qwen-plus
- Qwen Flash: qwen-flash
-
Multi-modal models
- Image and video understanding: qwen3.8-max, qwen3.7-plus
Use batch inference
Step 1: Prepare the input file
Before creating a task, prepare a JSONL file that complies with the following specifications:
- Format: UTF-8 encoded JSONL (one independent JSON object per line).
-
Size limits: Up to 50,000 requests and 500 MB per file.
If your data volume exceeds these limits, split it into multiple tasks and submit them separately.
- Per-line limit: Each JSON object must be ≤ 1 MB and must not exceed the model's context length.
- Consistency requirement: All requests in the same file must use the same model.
-
Unique identifier: Each request must include a custom_id field that is unique within the file, used for matching results.
custom_idsupports up to 256 characters; exceeding this limit causes task validation to fail. To pass longer identifier information, use a custom field ofmetadatawhen creating the task. For more information, see Using metadata to return custom identifiers. -
Media file addresses: Media files referenced via fields such as
image_urlandvideo_urlin thebodyof multimodal requests must use publicly accessible URLs. Local file paths (such asfile:///home/user/test.mp4) and intranet addresses are not supported. Tasks created with such addresses can be submitted successfully but will never be processed to completion. Upload the files to publicly accessible storage first, then reference their URLs.
Field | Type | Whether Required | Description |
|---|---|---|---|
| string | Yes | Unique identifier of the request |
| string | Yes | HTTP method; only |
| string | Yes | The request endpoint. Enter |
| object | Yes | The request body, whose format is the same as the API corresponding to the specified |
Sample file
You can download the sample file test_model.jsonl, which contains:
Usage
- Save the following code as
generate_batch_jsonl.py - Modify the request content in the
TASKSlist in the script - Run
python generate_batch_jsonl.py - The generated
batch_input.jsonlfile can be used directly for Batch inference tasks
Text generation model JSONL generation script
Multimodal model request format
Thecontent field of multimodal models is in array format, containing media objects and text questions. The media URLs in each request line must be of the same type (image, video, or audio). Replace TASKS in the script above with the following format:
Text embedding model request format
Text embedding models use the/v1/embeddings API, and the request format differs from that of text generation models. You can use the following standalone script to generate it:
Configure thinking mode in batch inference
Some models (such as qwen3.7-plus, qwen3.7-max, and the qwen3.6 and qwen3.5 series) have thinking mode enabled by default, which generates additional thinking tokens. To configure thinking mode in batch inference, set the enable_thinking parameter in the body of each request line in the JSONL file, placing it at the same level as model. The optional parameter thinking_budget is used to limit the maximum number of thinking tokens.
Example: Disable thinking mode
Step 2: Create a batch inference task
- On the **Batch inference** page, click Create Batch.
-
In the dialog box that appears: enter the Task Name and Task Description, set the Maximum Waiting Time (1–14 days), and upload a JSONL file.
You can click Download Sample File to get a template.
- After completing the form, click Confirm.
Step 3: Monitor and manage tasks
-
View:
- On the Tasks page, view the progress (number of processed requests/total number of requests) and status of a task.
- Search by task name or ID, or filter by workspace to quickly locate the target task.
-
Manage:
- Cancel: tasks in the "Running" state can be canceled in the Actions column.
Step 4: Download the results
After a task is completed, click View Results to download the output files:
- Results file: records all successful requests and their
responseresults. - Error file (if any): records all failed requests and their
errordetails.
custom_id field, which is used to match the original input data, associate results, or locate errors.
Step 5: View usage statistics (Optional)
On the Monitoring page, filter and view the usage statistics of batch inference.
-
View data overview: select a time (up to 30 days), set Inference Type to Batch Inference, and you can view:
- Monitoring Data: Summary statistics of all models within the time period, such as total number of calls and total number of failures.
- Models: Detailed data of each model, such as total calls, failure rate, and average call duration.
To view inference data from more than 30 days ago, go to the Bill page.
-
View model details: In the Models list, click Monitoring in the Actions column of the target model to view Call Statistics details (such as number of calls and call volume).

Use metadata to return custom identifiers
custom_id supports up to 256 characters. To return longer identifier information in the result file, you can use the custom fields of metadata.
metadata fields
metadata is an optional parameter when creating a Batch task and supports the following fields:
ds_name: Task name. Once set, it is displayed in the Task Name column of the console.ds_description: Task description. Once set, it is displayed in the Task Description column of the console.- Custom fields: In addition to the official fields above,
metadataalso supports arbitrary custom fields, and the values of custom fields are not subject to the 256-character limit. When you query task details, all custom fields are returned in full.
Sample Code
The following example shows how to return identifier information longer than 256 characters through the custom fields of metadata:
GET /v1/batches/{batch_id}) to obtain the complete metadata information, including all custom fields and their full content.
API Reference
In production environments, use OpenAI-compatible APIs to create and manage Batch tasks automatically. The core workflow is as follows:
Example:
-
Upload File
Call
POST /v1/filesto upload the file and record the returned file ID. -
Create Task Pass in the file ID and call
POST /v1/batchesto create a task, then record the returnedbatch_id. -
Poll the status Use
batch_idto pollGET /v1/batches/{batch_id}. Whenstatuschanges tocompleted, recordoutput_file_idand stop polling. -
Download results Use
output_file_idto callGET /v1/files/{output_file_id}/contentto download the result file.
Task lifecycle
Status | Description |
|---|---|
validating (Verifying) | The system is validating the file format (JSONL specification) and the API format validity of each request line. |
in_progress (Running) | The file has passed validation, and the system has started processing inference requests line by line. |
finalizing (Running) | All requests have been processed, and the results are being written to the result file and the error file respectively. In the console task list, this stage shares the Running status label with in_progress and has no separate display text. |
completed (Completed) | The result file and error file have been written and are ready for download. |
failed | The task failed during the validating stage, usually due to file-level errors (such as invalid JSONL format or oversized files). In this state, no inference requests are executed and no result file is generated. |
expired | The task's running time exceeded the maximum waiting time set at creation and was terminated by the system. When creating a new task, we recommend setting a longer waiting time. |
cancelled | The user cancels the task, and requests that have not started processing will be terminated. |
Billing Details
- Billing unit price: For all successful requests, the unit price of both input and output tokens is 50% of the corresponding model's real-time inference price. For more information, see Models.
-
Billing scope:
- Only requests that are successfully executed in the task are billed.
- File parsing failed, failed task execution, or row-level erroneous requests incur no fees.
- For cancelled tasks, requests that were successfully completed before cancellation are still billed normally.
- Batch inference is an independent billing item. It supports the AI Universal Savings Plan, but does not support discounts such as upfront (savings plan) and new-user free quota, or features such as context cache.
- Some models (such as qwen3.7-plus, qwen3.7-max, and the qwen3.6 and qwen3.5 series) have thinking mode enabled by default, which generates additional thinking tokens billed at the output token price, increasing costs. We recommend setting the enable_thinking parameter based on task complexity to control costs. For more information, see deep thinking.
FAQ
- Do I need to make an additional purchase or activation to use batch inference? No. You can use it once Alibaba Cloud Model Studio is activated, and fees are deducted from your account balance under the pay-as-you-go model.
-
Why does a task fail immediately after submission (status changes to failed)?
This is usually caused by file-level errors, and the task has not executed any inference requests. Troubleshoot in the following order:
- File format: Is it strict JSONL format, with one complete JSON object per line?
- File size: Do the file size, number of lines, etc. exceed the limits? For more information, see Prepare input files.
- Model consistency: Check that the
body.modelfield of all requests in the file is exactly the same, and that the models used are supported in the current region.
- How long does task processing take? Processing time mainly depends on the system load at the time. When the system is busy, tasks may need to queue, but the results, whether success or failure, will be returned within the set maximum waiting time.