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
The provider to route the request to (e.g.,
openai)Bearer token for the provider API
Body Parameters
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.
The endpoint to be used for all requests in the batch. Currently supports:
/v1/chat/completions/v1/completions/v1/embeddings
The time frame within which the batch should be processed. Currently only
24h is supported.Optional metadata to attach to the batch
Response
The batch identifier
The object type, always “batch”
The endpoint used for the batch
Error information if any requests failed
The ID of the input file
The completion time frame
The status of the batch:
validating, in_progress, finalizing, completed, failed, or cancelledThe ID of the file containing the outputs (available when status is
completed)The ID of the file containing errors (if any)
Unix timestamp of when the batch was created
Unix timestamp of when the batch started processing
Unix timestamp of when the batch completed
Custom metadata attached to the batch
Example
Input File Format
First, create a JSONL file with your requests:Response Example
Best Practices
Batch Size Recommendations
Batch Size Recommendations
- Keep batch sizes reasonable (1,000 - 50,000 requests)
- Monitor processing times and adjust batch sizes accordingly
- Split very large jobs into multiple batches
Error Handling
Error Handling
- Always check the
error_file_idafter batch completion - Implement retry logic for failed requests
- Use the
custom_idfield to track individual requests
Cost Optimization
Cost Optimization
- 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
Related Endpoints
Retrieve Batch
Check batch status and results
Cancel Batch
Cancel a running batch
List Batches
View all batches