Skip to main content

POST /v1/batches

Create a batch of API requests to be processed asynchronously. Batches are useful for processing large volumes of requests that don’t require immediate responses.

Authentication

Requires provider authentication headers:

Request

Headers

string
required
The provider to route the request to (e.g., openai)
string
required
Bearer token for the provider API

Body Parameters

string
required
The ID of an uploaded file that contains requests for the batch. The file must be a JSONL file with each line containing a request object.
string
required
The endpoint to be used for all requests in the batch. Currently supports:
  • /v1/chat/completions
  • /v1/completions
  • /v1/embeddings
string
required
The time frame within which the batch should be processed. Currently only 24h is supported.
object
Optional metadata to attach to the batch

Response

string
The batch identifier
string
The object type, always “batch”
string
The endpoint used for the batch
object
Error information if any requests failed
string
The ID of the input file
string
The completion time frame
string
The status of the batch: validating, in_progress, finalizing, completed, failed, or cancelled
string
The ID of the file containing the outputs (available when status is completed)
string
The ID of the file containing errors (if any)
integer
Unix timestamp of when the batch was created
integer
Unix timestamp of when the batch started processing
integer
Unix timestamp of when the batch completed
object
Custom metadata attached to the batch

Example

Input File Format

First, create a JSONL file with your requests:

Response Example

Best Practices

  • Keep batch sizes reasonable (1,000 - 50,000 requests)
  • Monitor processing times and adjust batch sizes accordingly
  • Split very large jobs into multiple batches
  • Always check the error_file_id after batch completion
  • Implement retry logic for failed requests
  • Use the custom_id field to track individual requests
  • Batch API typically offers 50% cost savings compared to real-time API
  • Use batches for non-time-sensitive workloads
  • Combine similar requests to maximize efficiency

Retrieve Batch

Check batch status and results

Cancel Batch

Cancel a running batch

List Batches

View all batches