The Batch API lets you submit large batches of requests asynchronously. In exchange for flexible completion times (up to 24 hours), you get a 50% discount on input/output tokens.
| ✅ Good Fit | ❌ Bad Fit |
|---|---|
| Bulk classification (10K+ items) | Real-time chat responses |
| Dataset labeling/annotation | User-facing interactions |
| Content moderation queues | Time-sensitive queries |
| Embedding generation at scale | Interactive agents |
// 1. Create a JSONL file of requests
// 2. Upload it
const file = await openai.files.create({
file: fs.createReadStream("batch_requests.jsonl"),
purpose: "batch"
});
// 3. Submit the batch
const batch = await openai.batches.create({
input_file_id: file.id,
endpoint: "/v1/responses",
completion_window: "24h"
});
// 4. Poll for completion
const status = await openai.batches.retrieve(batch.id);
// status.status: "completed" → download results