GPT-4o mini Pricing (per 1M tokens)
Input โ€” Real-time$0.15
Input โ€” Batch$0.075 (50% off)
Output โ€” Real-time$0.60
Output โ€” Batch$0.30 (50% off)

Google Context Caching

Google's Context Caching is not a traditional batch API, but it achieves a similar cost reduction for workloads where the same (or very similar) prompt is reused across many requests. By caching a long prompt or system instruction, you avoid re-processing it on every call. For repeated prompts with small input variations, this can reduce costs by up to 75%.

DeepSeek: Already Cheap

DeepSeek's standard pricing is already among the lowest in the market. At $0.14 per 1M input tokens and $0.28 per 1M output tokens, batch processing offers only marginal additional savings. If you are already using DeepSeek for cost-sensitive workloads, the engineering effort to implement batch processing may not be justified.

Cost Savings Calculator: Batch vs Real-Time

Here is a concrete example showing the cost difference between real-time and batch processing for a GPT-4o workload. Assume 1,000 requests per day with an average of 800 input tokens and 400 output tokens per request.

Daily Cost โ€” GPT-4o (1,000 requests/day)
Real-time input cost$2.00
Real-time output cost$4.00
Real-time total$6.00/day
Daily Cost โ€” GPT-4o Batch (1,000 requests/day)
Batch input cost$1.00
Batch output cost$2.00
Batch total$3.00/day
Monthly Savings
Real-time monthly$180.00
Batch monthly$90.00
You save$90.00/month (50%)

At this scale, switching to batch processing saves over $1,000 per year. At higher volumes, the savings become even more significant.

When to Use Batch Processing

Batch processing is ideal for any workload where the response does not need to be delivered instantly. Common use cases include:

When NOT to Use Batch Processing

Batch processing is not a universal solution. Avoid it when:

Implementation Guide: OpenAI Batch API

Here is a practical guide to implementing batch processing with OpenAI's Batch API using Node.js and the native fetch API.

Step 1: Prepare Your Batch File

Create a JSONL file with one request per line. Each line must include a custom ID and the standard chat completion request format.

// prepare-batch.js
const fs = require('fs');

const requests = [
  'Summarize this product review: ...',
  'Classify this customer email: ...',
  'Extract entities from this document: ...',
];

const jsonl = requests.map((prompt, i) => {
  return JSON.stringify({
    custom_id: `request-${i}`,
    method: 'POST',
    url: '/v1/chat/completions',
    body: {
      model: 'gpt-4o',
      messages: [{ role: 'user', content: prompt }],
      max_tokens: 500,
    },
  });
}).join('\n');

fs.writeFileSync('batch-requests.jsonl', jsonl);
console.log(`Created batch file with ${requests.length} requests`);

Step 2: Upload and Create the Batch

// create-batch.js
const API_KEY = process.env.OPENAI_API_KEY;

// Step A: Upload the file
const formData = new FormData();
formData.append('file', fs.createReadStream('batch-requests.jsonl'));
formData.append('purpose', 'batch');

const fileRes = await fetch('https://api.openai.com/v1/files', {
  method: 'POST',
  headers: { Authorization: `Bearer ${API_KEY}` },
  body: formData,
});
const { id: fileId } = await fileRes.json();

// Step B: Create the batch
const batchRes = await fetch('https://api.openai.com/v1/batches', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    input_file_id: fileId,
    endpoint: '/v1/chat/completions',
    completion_window: '24h',
  }),
});
const { id: batchId } = await batchRes.json();
console.log(`Batch created: ${batchId}`);

Step 3: Poll for Completion

// check-batch.js
const checkBatch = async (batchId) => {
  const res = await fetch(
    `https://api.openai.com/v1/batches/${batchId}`,
    { headers: { Authorization: `Bearer ${API_KEY}` } }
  );
  const batch = await res.json();
  console.log(`Status: ${batch.status}`);

  if (batch.status === 'completed') {
    // Download results
    const resultRes = await fetch(
      `https://api.openai.com/v1/files/${batch.output_file_id}/content`,
      { headers: { Authorization: `Bearer ${API_KEY}` } }
    );
    const results = await resultRes.text();
    fs.writeFileSync('batch-results.jsonl', results);
    console.log('Results saved!');
  }
};

Batch Processing Pitfalls

Batch processing is not without its challenges. Here are the most common pitfalls and how to avoid them:

Retry Logic

Individual requests within a batch can fail independently. OpenAI marks these as failed in the output file. You need logic to extract failed requests, diagnose the cause (rate limits, malformed input, content policy violations), and resubmit them in a new batch. Do not assume a "completed" batch means every request succeeded.

Error Handling

Every request in the output includes an error field when it fails. Common errors include invalid_prompt (malformed JSON or missing fields), content_policy_violation (content filtered by safety systems), and max_tokens_exceeded. Build a pipeline that parses these errors and routes them appropriately โ€” some are fixable (bad input), some are permanent (policy violations).

Monitoring

Batch processing runs asynchronously, which means you cannot rely on request-response timing for monitoring. Set up polling or webhooks to track batch status. Monitor for batches that stay in in_progress longer than expected, and alert on batches with high failure rates. Without monitoring, failed batches can go unnoticed for hours.

Concurrency Limits

OpenAI limits the number of concurrent batches you can run (typically one active batch at a time per organization). Plan your batch scheduling to avoid bottlenecks. If you have multiple daily workloads, stagger them or queue them sequentially.

Completion Window

OpenAI batches must specify a completion_window (e.g., 24h). If your batch cannot complete within that window, some requests may be left unprocessed. Size your batches appropriately and monitor completion times to avoid this.

Cost Comparison: Real-Time vs Batch at Scale

Here is what your monthly costs look like at three common volume levels using GPT-4o, assuming 800 input tokens and 400 output tokens per request:

10,000 Requests/Month
Real-time$60.00/month
Batch (50% off)$30.00/month
Monthly savings$30.00
100,000 Requests/Month
Real-time$600.00/month
Batch (50% off)$300.00/month
Monthly savings$300.00
1,000,000 Requests/Month
Real-time$6,000.00/month
Batch (50% off)$3,000.00/month
Monthly savings$3,000.00

At 1M requests per month, batch processing saves $3,000 every month โ€” that is $36,000 per year. Even at the lower end, $30 per month adds up to $360 per year of savings for very little engineering effort.

If your workload can tolerate a few hours of latency, batch processing is the single easiest way to cut your AI API bill in half.

Calculate your batch processing savings

Enter your request volume and see exactly how much you could save with batch vs real-time processing.

Try the APIpulse Calculator

โ€” See if you're overpaying for AI APIs

๐ŸŽฏ API Cost Score

Rate your API setup โ€” get a letter grade in 30 seconds

๐ŸŽฏ Rate Your API Setup in 30 Seconds

Get an A+ to F grade on your AI API costs. See how you compare and find cheaper alternatives instantly.

Get Your Cost Score โ†’

๐Ÿ“Š Generate Your Personalized API Cost Report

Select your model, enter your monthly spend, and get a custom savings report with cheaper alternatives โ€” free, in 60 seconds.

Found this useful? Share it:

๐ŸŽฏ API Cost Score

Rate your API setup โ€” get a letter grade in 30 seconds

Related Reading

Get notified when API prices change

No spam. Only pricing updates and new features. Unsubscribe anytime.

Want to optimize your AI API costs?

APIpulse includes free cost comparisons, exports, and recommendations that can save you up to 40%.

Free Cost Audit โ†’

Save money: ๐Ÿ“Š Live API Pricing ยท Cost Optimizer โ€” find out how much you could save by switching models. Free tool.

๐Ÿ”ง Free Embeddable Pricing Widget
Add live AI API pricing to your docs, blog, or README with one script tag. 88 models, auto-updating.
Get the Free Widget โ†’ Free MCP Server โ†’