Skip to main content
POST
/
v1
/
batches
Create Batch
curl --request POST \
  --url https://api.moonshot.ai/v1/batches \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "input_file_id": "<string>",
  "endpoint": "/v1/chat/completions",
  "completion_window": "<string>"
}
'
{
  "id": "<string>",
  "object": "batch",
  "endpoint": "<string>",
  "input_file_id": "<string>",
  "completion_window": "<string>",
  "status": "validating",
  "created_at": 123,
  "request_counts": {
    "completed": 123,
    "failed": 123,
    "total": 123
  },
  "output_file_id": "<string>",
  "error_file_id": "<string>",
  "in_progress_at": 123,
  "expires_at": 123,
  "finalizing_at": 123,
  "completed_at": 123,
  "failed_at": 123,
  "cancelling_at": 123,
  "cancelled_at": 123,
  "metadata": {}
}
Limits:
LimitDescription
File formatMust have .jsonl extension
File sizeMust be non-empty, max 100MB
Organization quotaUp to 1000 batch-purpose files per organization
Model consistencyAll requests in a batch must use the same model
custom_idMust be unique within the file
Model accessThe specified model must exist and the user must have access
For complete usage examples, see the Batch API Guide.

Authorizations

Authorization
string
header
required

The Authorization header expects a Bearer token. Use an MOONSHOT_API_KEY as the token. This is a server-side secret key. Generate one on the API keys page in your dashboard.

Body

application/json
input_file_id
string
required

ID of the input file, must be a .jsonl file uploaded with purpose="batch"

endpoint
enum<string>
required

Request endpoint, currently only /v1/chat/completions is supported

Available options:
/v1/chat/completions
completion_window
string
required

Time window for task processing, supports formats like 12h, 1d, 3d, minimum 12h, maximum 7d

metadata
object

Custom metadata, up to 16 key-value pairs, key max 64 chars, value max 512 chars

Response

The created batch task

id
string
required

Unique identifier for the batch task

object
string
required

Object type, always batch

Example:

"batch"

endpoint
string
required

Request endpoint

input_file_id
string
required

Input file ID

completion_window
string
required

Processing time window

status
enum<string>
required

Current status: validating, failed, in_progress, finalizing, completed, expired, cancelling, cancelled

Available options:
validating,
failed,
in_progress,
finalizing,
completed,
expired,
cancelling,
cancelled
created_at
integer
required

Creation timestamp (Unix)

request_counts
object
required
output_file_id
string | null

Output file ID for successful results

error_file_id
string | null

Error file ID for failed results

in_progress_at
integer | null

Execution start timestamp (Unix)

expires_at
integer | null

Expiration timestamp (Unix)

finalizing_at
integer | null

Result preparation start timestamp (Unix)

completed_at
integer | null

Completion timestamp (Unix)

failed_at
integer | null

Validation failure timestamp (Unix)

cancelling_at
integer | null

Cancellation request timestamp (Unix)

cancelled_at
integer | null

Cancellation completion timestamp (Unix)

metadata
object

Custom metadata