Skip to main content
POST
Create a batch

Overview

Creates a batch over a file uploaded with purpose: batch and returns it in validating. Poll GET /v1/batches/{batch_id} until status is terminal. Every line must target /v1/chat/completions and name the same model, custom_id must be unique within the file, and stream: true is rejected. Completed requests are billed at half the model’s synchronous rate; see the Batch guide for the full contract.

Authorizations

Authorization
string
header
required

Morph API key, passed as Authorization: Bearer sk-.... Create keys at https://www.morphllm.com/dashboard/api-keys.

Body

application/json

Which file to process and how long to keep its results.

Start a batch over an uploaded input file.

input_file_id
string
required

Id of a file uploaded with purpose: batch.

Example:

"file_9c2c1c3e-5b6a-4f0e-8d0f-2a1b3c4d5e6f"

endpoint
enum<string>
required

Must be /v1/chat/completions; every input line must use the same url.

Available options:
/v1/chat/completions
Example:

"/v1/chat/completions"

completion_window
enum<string>
required

Must be 24h. Requests not finished by then are expired, and the completed ones are still returned.

Available options:
24h
Example:

"24h"

metadata
object

Up to 16 string pairs to tag the batch. Keys up to 64 characters, values up to 512.

Example:
output_expires_after
object

Expiry policy for the output and error files. Defaults to 30 days.

Example:

Response

The new batch, in validating.

A batch and where it is in its lifecycle.

id
string
required

Batch identifier, batch_ prefixed.

Example:

"batch_5f4e3d2c-1b0a-4f9e-8d7c-6b5a4f3e2d1c"

object
string
required

Object type, always batch.

Example:

"batch"

endpoint
string
required

The endpoint every line targets. Always /v1/chat/completions.

Example:

"/v1/chat/completions"

input_file_id
string
required

The file the batch reads its requests from.

Example:

"file_9c2c1c3e-5b6a-4f0e-8d0f-2a1b3c4d5e6f"

completion_window
string
required

Always 24h. Requests still queued when the window closes are written to the error file as batch_expired.

Example:

"24h"

metadata
object | null
required

The key-value pairs you attached at creation, or null.

Example:
created_at
integer
required

Unix timestamp (seconds) for when the batch was created.

Example:

1780000000

status
enum<string>
required

Lifecycle state. completed, failed, expired, and cancelled are terminal. expired and cancelled batches still expose partial output.

Available options:
validating,
in_progress,
finalizing,
completed,
failed,
expired,
cancelling,
cancelled
Example:

"in_progress"

output_file_id
string | null
required

File holding one BatchOutputLine per request the model answered. Set once the batch is terminal; null before that and when nothing completed.

Example:

null

error_file_id
string | null
required

File holding one BatchErrorLine per request that never got a model response. Set once the batch is terminal; null before that and when nothing failed.

Example:

null

in_progress_at
integer | null
required

Unix timestamp (seconds) for when processing started. null until it happens.

Example:

1780000012

finalizing_at
integer | null
required

Unix timestamp (seconds) for when output files started being written. null until it happens.

Example:

null

completed_at
integer | null
required

Unix timestamp (seconds) for when the batch completed. null until it happens.

Example:

null

failed_at
integer | null
required

Unix timestamp (seconds) for when the batch failed. null until it happens.

Example:

null

expired_at
integer | null
required

Unix timestamp (seconds) for when the batch expired. null until it happens.

Example:

null

expires_at
integer | null
required

Unix timestamp (seconds) for when the completion window closes. null until it happens.

Example:

1780086400

cancelling_at
integer | null
required

Unix timestamp (seconds) for when cancellation was requested. null until it happens.

Example:

null

cancelled_at
integer | null
required

Unix timestamp (seconds) for when cancellation finished. null until it happens.

Example:

null

request_counts
object
required

Progress counters. Advance while the batch is in_progress; final once it is terminal.

Example:
errors
object | null
required

Why the batch failed validation, or null.

Example:

null

usage
object | null
required

Token totals so far, or null before any request has completed.

Example:
model
string

The model the batch runs on, once validation has read it from the input file.

Example:

"morph-glm53flash"