Batch API
Create Batch
Submit a batch job for asynchronous processing.
POST
Create Batch
Documentation Index
Fetch the complete documentation index at: https://budecosystem-b7b14df4.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
Overview
The Batch API enables asynchronous processing of large volumes of requests at reduced costs. It’s ideal for:- Bulk content generation
- Large-scale data analysis
- Embedding generation for datasets
- Any task that doesn’t require immediate responses
Endpoints
File Management
Batch Operations
Authentication
File Upload
Upload JSONL files containing batch requests.Request Format
Endpoint:POST /v1/files
Headers:
Authorization: Bearer YOUR_API_KEY(required)Content-Type: multipart/form-data(required)
| Field | Type | Required | Description |
|---|---|---|---|
file | file | Yes | JSONL file containing requests (max 100MB) |
purpose | string | Yes | Must be "batch" |
Response Format
JSONL Request Format
Each line in the JSONL file must be a valid JSON object:Request Fields
| Field | Type | Required | Description |
|---|---|---|---|
custom_id | string | Yes | Unique identifier for tracking |
method | string | Yes | Must be "POST" |
url | string | Yes | Target endpoint (e.g., /v1/chat/completions) |
body | object | Yes | Request body for the endpoint |
Create Batch
Submit a file for batch processing.Request Format
Endpoint:POST /v1/batches
Request Body:
Parameters
| Field | Type | Required | Description |
|---|---|---|---|
input_file_id | string | Yes | ID of uploaded JSONL file |
endpoint | string | Yes | Target API endpoint |
completion_window | string | No | Processing window (default: "24h") |
metadata | object | No | Key-value pairs (max 16) |
Response Format
Batch Status
Status Values
| Status | Description |
|---|---|
validating | Initial validation of batch request |
failed | Batch failed to process |
in_progress | Currently processing requests |
finalizing | Preparing result files |
completed | Successfully processed |
expired | Exceeded 24-hour window |
cancelling | Cancellation in progress |
cancelled | Successfully cancelled |
Retrieve Batch
Get the current status of a batch. Endpoint:GET /v1/batches/{batch_id}
Returns the same format as batch creation response with updated status and counts.
List Batches
List all batches with pagination support. Endpoint:GET /v1/batches
Query Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
after | string | No | Cursor for pagination |
limit | integer | No | Results per page (default: 20, max: 100) |
Response Format
Cancel Batch
Cancel an in-progress batch. Endpoint:POST /v1/batches/{batch_id}/cancel
Returns the batch object with updated cancellation timestamps.
Output Format
Completed batches produce JSONL output files where each line contains:Usage Examples
Complete Workflow
Python Example
JavaScript Example
Best Practices
- Batch Size: Keep batches under 50,000 requests for optimal processing
- File Size: Ensure JSONL files are under 100MB
- Custom IDs: Use meaningful identifiers for easy tracking
- Validation: Validate JSONL format before uploading
- Polling: Check status every 30-60 seconds to avoid rate limits
- Error Handling: Process partial failures gracefully
- Cleanup: Delete processed files to manage storage
- Metadata: Use metadata fields for additional context and filtering
Limitations
- Maximum requests per batch: 50,000
- Maximum file size: 100MB
- Completion window: 24 hours
- Metadata entries: Maximum 16 key-value pairs
- Supported endpoints:
/v1/chat/completions,/v1/embeddings, and other compatible endpoints
Error Handling
The batch API automatically retries transient failures. Failed requests are included in the output file with error details, allowing you to:- Identify specific failures
- Retry failed requests
- Adjust parameters based on error messages
- Track success rates
Supported providers
OpenAI
Native batch API support with cost savings for large-scale processing.
Anthropic
Batch processing for Claude models with automatic retry handling.
Together.AI
Efficient batch inference for open-source models at scale.
Create Batch