Skip to main content
When you need to process large-scale tasks with low real-time requirements, the Batch API is the ideal choice. It supports submitting tasks in bulk via files, saving 40% on inference costs compared to real-time API calls.
Batch API supports both the kimi-k2.6 and kimi-k2.5 models. The temperature, top_p, and other parameters cannot be modified for these models — 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:
FieldRequiredDescription
custom_idYesCustom request identifier for tracking results, must be unique within the file
methodYesRequest method, must be POST
urlYesRequest endpoint, must be /v1/chat/completions
bodyYesRequest body, same parameters as the Chat Completions API
The model in body must be either kimi-k2.6 or kimi-k2.5. The temperature, top_p, n, presence_penalty, and frequency_penalty parameters cannot be modified for these models. Do not include these parameters in the body.
Input file requirements:
  • File must be in .jsonl format, non-empty, and no larger than 100MB
  • Each line must be a valid JSON object containing custom_id, method, url, and body fields
  • custom_id must be unique within the file
  • All lines must use the same model — only one model per batch is allowed
  • method must be POST, url must 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 with purpose set to "batch".

3. Create the Task

Call the Create Batch endpoint with input_file_id and completion_window. We recommend setting a generous time window for larger datasets.

4. Wait for Completion

After creation, the task enters validating 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.
Each line in the output file corresponds to a processed request:

Complete Code Examples

Complete scripts combining all steps above — copy and run directly:

Batch Status Reference

StatusDescription
validatingCreated, input data validation in progress
failedData validation failed, batch terminated
in_progressValidation passed, execution in progress
finalizingExecution complete, preparing results
completedResults ready, batch complete
expiredDid not complete within completion_window
cancellingCancellation requested, pending
cancelledCancellation 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 in validating, 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.
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 using ms://<file_id>. Better for large images or image reuse.
Both methods are provided below — switch between them as needed:
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 using ms://<file_id>. Better for large videos or video reuse.
Both methods are provided below — switch between them as needed:

Best Practices

  • Set completion_window based on data volume — use 3d or 7d for 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