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 cancelledstring
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
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