For inference scenarios that do not require real-time responses, batch inference asynchronously processes large volumes of data requests at 50% of the cost of real-time inference. Its OpenAI-compatible API is ideal for batch jobs such as model evaluation and data labeling.
How it works
- Submit a task: Upload a JSONL file containing multiple requests to create a batch inference task.
- Asynchronous processing: The system processes tasks in a background queue. You can monitor task progress and status on the console or by using the API.
- Download results: After the task is complete, the system generates a result file (recording successful responses) and an error file (recording failure details, if any).
Scope
- China (Beijing)
- Singapore
-
Text generation models
- Qwen-Max: qwen4-max, qwen3.8-max, qwen3.7-max
- Qwen-Plus: qwen3.7-plus, qwen3.6-plus, qwen3.5-plus, qwen-plus, qwen-plus-latest
- Qwen-Flash: qwen3.8-flash, qwen3.7-flash, qwen3.6-flash, qwen3.5-flash, qwen-flash
- Qwen-Long: qwen-long
-
Multimodal models
- Image and video understanding: qwen4-max, qwen3.8-max, qwen3.8-flash, qwen3.7-plus, qwen3.6-plus, qwen3.7-flash, qwen3.6-flash, qwen3.5-plus, qwen3.5-flash, qwen3-vl-plus
- Text extraction: qwen-vl-ocr
- Omni-modal: qwen3.5-omni-plus, qwen3.5-omni-flash
- Embedding models: text-embedding-v1, text-embedding-v2, text-embedding-v3, text-embedding-v4, qwen3.7-text-embedding, qwen3.7-text-embedding-flash
Use batch inference
Step 1: Prepare the input file
Before creating a task, prepare a JSONL file that meets the following requirements:
- Format: UTF-8 encoded JSONL (one independent JSON object per line).
-
Scale limits: Up to 50,000 requests per file, and a maximum file size of 500 MB.
If the data volume exceeds these limits, split it into multiple tasks and submit them separately.
- Per-line limit: Each JSON object can be up to 1 MB and must not exceed the model context length.
- Consistency: All requests within the same file must use the same model and thinking mode (if applicable).
-
Unique identifier: Each request must include a custom_id field that is unique within the file for result matching.
custom_idsupports a maximum of 256 characters; exceeding this limit causes task validation to fail. To pass back longer identifier information, use a custom field ofmetadatawhen creating the task. For details, see Use metadata to return custom identifiers. -
Media file URLs: Media files referenced in the
bodyof a multimodal request through fields such asimage_urlandvideo_urlmust use publicly accessible URLs. Local file paths (such asfile:///home/user/test.mp4) and internal network addresses are not supported. Tasks created with such addresses can be submitted successfully but are never processed to completion. Upload the file to publicly accessible storage first, and then reference its URL.
Field | Type | Required | Description |
|---|---|---|---|
| string | Yes | A unique identifier for the request. |
| string | Yes | The HTTP method. Only |
| string | Yes | The request endpoint. Enter |
| object | Yes | The request body, whose format is consistent with the API corresponding to the specified |
Sample file
You can download the sample file test_model.jsonl. The content is as follows:
Usage
- Save the following code as
generate_batch_jsonl.py - Modify the request content of 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:
Embedding model request format
Embedding models use the/v1/embeddings endpoint, and the request format differs from that of text generation models. You can use the following standalone script to generate the file:
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, at the same level as model. The optional thinking_budget parameter sets an upper limit on the number of thinking tokens.
Example: Disable thinking mode
Step 2: Create a batch inference task
- On the Batch Inference page, click Create Batch Inference Task.
-
In the dialog box that appears, enter a Task Name and Task Description, set the Maximum Waiting Time (1 to 14 days), and upload the JSONL file.
You can click Download Sample File to obtain the template.
- When you are done, click Confirm.
Step 3: Monitor and manage tasks
-
View:
- On the task list page, view the task's progress (processed requests/total requests) and status.
- Search by task name or ID, or filter by workspace to quickly locate the target task.
-
Manage:
- Cancel: Tasks in the "Executing" state can be cancelled in the Actions column.
- Troubleshoot: For a failed task, hover over the status to view an error summary, or download the error file for details. For example, if different models are mixed in the batch file, the task will show a Failed status. Example error message:
The model 'qwen-plus' for this request does not match the rest of the batch. Each batch must contain requests for a single model.
Step 4: Download results
When the task is complete, click View Results to download the output files:
- Result 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 Model Usage page, filter and view the usage statistics of batch inference.
- View data overview: Select Time (up to 30 days), set Inference Type to Batch Inference to view the model call overview of batch inference.
-
View model details:
- Click a model category, such as Large Language Model, to go to the details page. On the details page, Select Time (up to 30 days), set Inference Type to Batch Inference to view the call information of the models in that category.
- Click View Details to the right of the target model to view the call details of a single model.
Use metadata to return custom identifiers
custom_id supports a maximum of 256 characters. To pass back longer identifier information in the result file, use a custom field of metadata.
Metadata fields
metadata is an optional parameter for creating a Batch task. It supports the following fields:
ds_name: The task name. When set, it is displayed in the Task Name column on the console.ds_description: The task description. When set, it is displayed in the Task Description column on the console.- Custom fields: In addition to the official fields above,
metadataalso supports any custom fields, and the values of custom fields are not limited to 256 characters. When you query task details, all custom fields are returned in full.
Code example
The following example shows how to use a custom field of metadata to pass back identifier information longer than 256 characters:
GET /v1/batches/{batch_id}) to obtain the complete metadata information, including all custom fields and their full content.
API reference
In a production environment, use the OpenAI-compatible API to automate the creation and management of Batch tasks. The core workflow is as follows:
Example:
-
Upload a file
Call
POST /v1/filesto upload a file and record the returned file ID. -
To create a task, pass in the file ID or an OSS path, call
POST /v1/batches, and record the returnedbatch_id. -
Poll the status: Use
batch_idto pollGET /v1/batches/{batch_id}. Whenstatuschanges tocompleted, record theoutput_file_idand stop polling. -
To download the result file, use
output_file_idto callGET /v1/files/{output_file_id}/content.
Task lifecycle
Status | Description |
|---|---|
validating (validation in progress) | The system is validating the file format (JSONL specification) and the API format of each request line. |
in_progress (executing) | The file has passed validation, and the system has started processing the inference requests line by line. |
finalizing (executing) | All requests have been processed, and the results are being written to the result file and error file respectively. In the console task list, this stage shares the Executing status label with in_progress and has no separate display text. |
completed (completed) | The result file and error file have been written and are available for download. |
failed (failed) | The task failed during the validating stage, usually due to file-level errors (such as JSONL format errors or an oversized file). In this state, no inference requests are executed, and no result file is generated. |
expired (terminated) | The task ran longer than the maximum waiting time set at creation and was terminated by the system. When creating a new task, consider setting a longer waiting time. |
cancelled (terminated) | The user cancelled the task. Requests that have not started processing will be terminated. |
Billing
- Pricing: For all successful requests, the unit price of both input and output tokens is 50% of the real-time inference price of the corresponding model. For details, see Model list.
-
Billing scope:
- You are billed only for the requests that are successfully executed in the task.
- File parsing failures, task execution failures, or line-level request errors do not incur charges.
- For a cancelled task, requests that were successfully completed before cancellation are billed normally.
- Batch inference is a separate billable item and supports the AI Universal Savings Plan. However, it is not eligible for other promotions like prepaid plans (Savings Plans) and new user free quotas, or features like context caching.
- Some models, such as qwen3.7-plus, qwen3.7-max, and the qwen3.6 and qwen3.5 series, have thinking mode enabled by default. This generates additional thinking tokens, which are billed at the output token price and increase costs. To control costs, set the enable_thinking parameter based on task complexity. For details, see Deep Thinking.
FAQ
- Do I need to purchase or enable anything extra to use batch inference? No. The feature is available after you activate Alibaba Cloud Model Studio. Charges are incurred on a pay-as-you-go basis and deducted from your account balance.
-
Why did my task fail immediately after submission (status changed to failed)?
This typically indicates a file-level error, and no inference requests were executed. Check the following in order:
- File format: Verify that the file uses the strict JSONL format, with one complete JSON object per line.
- File scale: Ensure the file size and number of lines do not exceed the limits. For details, see Step 1: Prepare the input file.
- Model consistency: Check that the
body.modelfield is identical for all requests in the file, and that the model used is supported in the current region.
- How long does a task take to process? Processing time mainly depends on the system load at that time. During busy periods, tasks may need to be queued. A result (success or failure) is always returned within the specified maximum waiting time.