OpenAI Batch API Guide: Cut Your Costs by 50%

The OpenAI Batch API is the simplest way to cut the bill for any workload that does not need an answer immediately. You package many requests into one file, submit it, and collect the results later, usually well inside a 24-hour window, at roughly half the standard price for both input and output tokens. For classification, extraction, embeddings, evaluation runs, and bulk content jobs, that discount is the difference between a comfortable budget and an expensive one. This guide explains how batching works, how to build a reliable pipeline around it, and when to use something else.

How the Batch API Works

A normal API call is synchronous: you send a request, wait, and pay the standard rate. The Batch API turns that into an asynchronous file job. You write each request as one line of a JSONL file, upload the file, create a batch that points at it, and then check the batch until it finishes. When it completes, you download an output file with one result line per request, plus a separate error file for any that failed. In exchange for giving OpenAI up to 24 hours of scheduling flexibility, you pay about half the real-time price. The models and outputs are the same as in real-time calls, so quality does not change. You are paying for patience, not for a weaker product.

Batch jobs also run in their own rate-limit pool, so a large overnight job does not eat into the quota that your live application uses. That separation is one of the quiet advantages: you can run both real-time traffic and heavy background processing at the same time without them competing.

Figure 1 — Real-time vs Batch vs Flex processing

Mode Price Turnaround Best for StandardFull priceImmediateUser-facing features BatchAbout 50% offWithin 24 hoursLarge offline jobs FlexAbout 50% offSlower, may be busyTolerant async calls

What Is Worth Batching

Batching suits any job where nobody is waiting at a screen. Classifying thousands of support tickets or product reviews, extracting fields from a backlog of documents, generating embeddings for a knowledge base, summarising an archive, running nightly evaluations of your prompts against a test set, backfilling metadata, and producing synthetic training data are all natural fits. The question to ask is whether the result is needed in minutes or by tomorrow. If tomorrow is fine, batch it. If a user is watching a spinner, it is not a batch job.

Building the Input File

Each line of the JSONL file is a complete JSON object describing one request. It has a unique custom_id that you choose, the HTTP method, the endpoint URL path, and a body containing the same parameters you would send in a normal call: the model, the messages or input, and options such as the maximum output length. The Batch API supports several endpoints, including chat completions, responses, embeddings, and moderations, but one batch file targets a single endpoint, so use separate files for different request types. Keep the custom_id meaningful, for example the ticket ID or document ID, because results are not guaranteed to come back in the order you submitted them, and the custom_id is how you match each answer to its source.

Two practical limits apply. A single file has a cap on the number of requests and on file size, and there are limits on the total queued tokens for your account, so very large jobs need to be split into several batches. Limits change, so confirm the current numbers in OpenAI’s batch documentation. Validate your file locally before uploading: every line must be valid JSON, every custom_id must be unique, and every body must match the endpoint’s schema, because a malformed file is rejected or partially failed after you have already waited.

Submitting and Monitoring a Batch

The workflow has four steps. Upload the JSONL file with the purpose set to batch, which returns a file ID. Create the batch by passing that file ID, the endpoint, and the completion window of 24 hours. Poll the batch status periodically, where it moves through validating, in progress, finalizing, and then completed, or ends as failed, expired, or cancelled. Finally, download the output file, and the error file if there is one, using the IDs on the finished batch object. Polling every few minutes is plenty, and for production systems a webhook or scheduled worker that checks status is more robust than a script left running on a laptop. You can also cancel a batch you no longer need, and requests that completed before cancellation are still returned and charged.

Handling Results and Errors

Treat the output file as a lookup table keyed by custom_id. Each successful line contains the response body, and each failed line appears in the error file with a reason. Expect a small fraction of failures even in healthy jobs, such as a prompt that exceeded the context window or a request the safety system declined. Collect the failed custom_ids, fix the cause, and submit them as a new, smaller batch rather than rerunning everything. If a batch expires before every request finishes, the completed requests are still delivered and billed, and the remainder can be resubmitted. Store results in a database keyed by custom_id as soon as you download them, so a rerun never duplicates work.

Working Out the Savings

The arithmetic is simple, so do it before building anything. As an illustration, imagine classifying 100,000 support tickets, each with about 400 input tokens and 50 output tokens. That is 40 million input tokens and 5 million output tokens. If a model charged one dollar per million input tokens and four dollars per million output tokens, the real-time cost would be about 60 dollars, and the batch cost about 30. The absolute figures depend entirely on the model you choose, so substitute current prices from OpenAI’s pricing page. The principle holds at every scale: the discount is a flat percentage, so the larger the job, the more it saves, and the model choice usually matters even more than the batch discount, which is why you should pick the cheapest model that passes your quality tests first and then batch it.

Combining Batch with Other Cost Levers

Batching is one of several levers, and they work best together. Choose the smallest model that meets your accuracy target, using an evaluation set rather than a guess. Keep long shared instructions at the start of each prompt so automatic prompt caching can reduce the cost of repeated prefixes, and check the pricing page to see how caching and batch discounts apply together for your model. Cap output length so verbose answers do not waste tokens, and use structured outputs so that results are short and machine-readable. For work that is not quite urgent but not overnight either, OpenAI’s Flex processing offers a similar discount on ordinary synchronous calls, in exchange for slower responses and the occasional need to retry when capacity is tight.

Common Mistakes

  • Using batch for interactive features. If a person is waiting, use the standard or a priority path.
  • Weak custom IDs. Random or duplicate IDs make it painful to join results back to your data.
  • No local validation. Check the file before upload, or you will discover problems hours later.
  • Submitting one giant batch. Smaller batches finish and fail independently, which makes recovery simpler.
  • Forgetting to cap output tokens. A missing limit can inflate cost on long generations.
  • Not testing the prompt first. Run a small real-time sample before spending a whole batch on a flawed prompt.

Other Providers Offer Similar Discounts

The pattern is not unique to OpenAI. Anthropic offers a Message Batches API with a comparable discount and a 24-hour window, and Google offers batch prediction on its platform. If you already structure your work as large offline jobs, the same pipeline design, with unique IDs, local validation, result storage, and a retry path for failures, transfers across providers with little change, which also makes it easier to compare costs between them.

Frequently Asked Questions

How much cheaper is the Batch API?
OpenAI prices batch requests at roughly half the standard rate for both input and output tokens. Check the pricing page for the exact figures for your model, as rates and eligible models change.
How long does a batch take?
The completion window is 24 hours, and many batches finish much sooner, but there is no guaranteed faster turnaround. Do not plan anything time-critical around it.
Can I mix different models or endpoints in one file?
A batch targets one endpoint, so keep one request type per file. Check the current documentation on whether a single file may contain more than one model.
Do batch results differ in quality?
No. The same models process the requests, so quality is the same as real-time calls. The trade-off is only in latency.
Can I use structured outputs and tool calls in a batch?
Generally yes for supported models and endpoints, because each line is a normal request body, but confirm support for your specific model in the documentation before building a large job around it.

Last updated: November 2026. Prices, limits, and model availability change often, so confirm details on OpenAI’s pricing and batch documentation pages.

Leave a Comment