Batch API currently only supports the
kimi-k2.5 model. The temperature, top_p, and other parameters cannot be modified for this model — do not include them in the request body.Create Batch
Upload a JSONL file and create a batch task
List Batches
List batch tasks for your organization
Retrieve Batch
Get status and details for a specific batch task
Cancel Batch
Cancel an in-progress batch task
Workflow
This guide walks through a complete text classification example using the Batch API:1. Build the Input File
Each line in the JSONL file is an independent JSON object representing a single inference request:| Field | Required | Description |
|---|---|---|
custom_id | Yes | Custom request identifier for tracking results, must be unique within the file |
method | Yes | Request method, must be POST |
url | Yes | Request endpoint, must be /v1/chat/completions |
body | Yes | Request body, same parameters as the Chat Completions API |
Input file requirements:
- File must be in
.jsonlformat, non-empty, and no larger than 100MB - Each line must be a valid JSON object containing
custom_id,method,url, andbodyfields custom_idmust be unique within the file- All lines must use the same
model— only one model per batch is allowed methodmust bePOST,urlmust be/v1/chat/completions- The specified model must exist and the user must have access to it
2. Upload the File
Upload the JSONL file via the Upload File endpoint withpurpose set to "batch".
3. Create the Task
Call the Create Batch endpoint withinput_file_id and completion_window. We recommend setting a generous time window for larger datasets.
4. Wait for Completion
After creation, the task entersvalidating status for input validation. Once validated, it moves to in_progress. Use the Retrieve Batch endpoint to poll for status updates.
5. Process Results
When complete,output_file_id contains the results file ID. Download it via the Get File Content endpoint. If any requests failed, error_file_id contains the error details.
Complete Code Examples
Complete scripts combining all steps above — copy and run directly:Batch Status Reference
| Status | Description |
|---|---|
validating | Created, input data validation in progress |
failed | Data validation failed, batch terminated |
in_progress | Validation passed, execution in progress |
finalizing | Execution complete, preparing results |
completed | Results ready, batch complete |
expired | Did not complete within completion_window |
cancelling | Cancellation requested, pending |
cancelled | Cancellation complete, batch terminated |
Task Management
List Batches
Use the List Batches endpoint to view all batch tasks in your organization.Cancel a Batch
Use the Cancel Batch endpoint to cancel an in-progress task. Only tasks invalidating, in_progress, or finalizing status can be cancelled. After cancellation, the status changes to cancelling and then cancelled.
Multi-modal Batch Tasks
The Batch API supports image and video content in the input file. The key difference from text tasks is in building the input file — the rest of the workflow (upload, create task, poll, process results) is identical.Image Batch Processing Example
Image Batch Processing Example
There are two ways to include images:
- Base64 inline: Encode images as base64 directly in the JSONL. Suitable for small images. Note that base64 inflates file size by ~33% — keep the 100MB file size limit in mind.
- File reference: Upload images first via the Files API (
purpose="image"), then reference them in the JSONL usingms://<file_id>. Better for large images or image reuse.
Video Batch Processing Example
Video Batch Processing Example
There are two ways to include videos:
- Base64 inline: Encode videos as base64 directly in the JSONL. Suitable for small videos. Note that base64 inflates file size by ~33% — keep the 100MB file size limit in mind.
- File reference: Upload videos first via the Files API (
purpose="video"), then reference them in the JSONL usingms://<file_id>. Better for large videos or video reuse.
Best Practices
- Set
completion_windowbased on data volume — use3dor7dfor larger datasets - Poll every 10-60 seconds to avoid excessive requests
- Process results into databases or reports as needed
- For very large files, consider splitting into multiple batches