A batch API lets you send thousands of LLM requests as one job, which the provider processes asynchronously within 24 hours instead of answering each call immediately. In exchange for waiting, OpenAI and Anthropic both bill batch usage at 50% of their standard prices (as stated on their official docs, checked October 2026).
Use a batch API when nobody is waiting on the answer: classifying a backlog of support tickets, summarising 20,000 documents overnight, running an evaluation set, or generating embeddings for a search index. Use the normal synchronous API when a user is watching a spinner.
How a batch API works
The flow is the same at both providers, even though the request shapes differ:
- You build a list of ordinary requests, each tagged with a
custom_idthat you choose. - You submit the list as one batch and get back a batch ID.
- The provider works through the requests in the background, each one independently.
- You poll the batch status until it has ended.
- You download the results and match each one to its request by
custom_id.
Step 5 matters more than it looks. Both providers say results can come back in a different order from the input, so never match results by line number.
Batch API limits and discount: OpenAI vs Anthropic
These figures come from each provider's batch documentation as of October 2026. They change, so check the source pages before you plan capacity around them.
| OpenAI Batch API | Anthropic Message Batches API | |
|---|---|---|
| Discount | 50% vs synchronous APIs | 50% of standard API prices |
| Processing window | 24 hours (completion_window: "24h") | 24 hours; most batches finish in under 1 hour |
| Max requests per batch | 50,000 | 100,000 |
| Max size | 200 MB input file | 256 MB per batch |
| Input format | JSONL file uploaded via the Files API | JSON array in the request body |
| Endpoints | Responses, Chat Completions, Embeddings, Completions, Moderations, image generation and edits | Messages |
| Models per batch | One model per input file | Can mix request types in one batch |
| Results kept | Output file deleted 30 days after the batch completes | 29 days after the batch is created |
| Rate limits | Separate pool; does not consume per-model limits | Separate limits; does not affect Messages API limits |
OpenAI batch API: JSONL file, upload, create
OpenAI takes a JSONL file where every line is one complete request. The body holds exactly what you would send to the endpoint directly:
{"custom_id": "ticket-0001", "method": "POST", "url": "/v1/chat/completions", "body": {"model": "MODEL_NAME", "messages": [{"role": "user", "content": "Classify this ticket: Login page returns 500"}]}}
{"custom_id": "ticket-0002", "method": "POST", "url": "/v1/chat/completions", "body": {"model": "MODEL_NAME", "messages": [{"role": "user", "content": "Classify this ticket: Invoice shows wrong VAT"}]}}
Upload the file with purpose set to batch:
curl https://api.openai.com/v1/files \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-F purpose="batch" \
-F file="@batchinput.jsonl"
Then create the batch with the file ID the upload returned:
curl https://api.openai.com/v1/batches \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{"input_file_id": "file-abc123", "endpoint": "/v1/chat/completions", "completion_window": "24h"}'
A batch moves through these statuses: validating, in_progress, finalizing, completed, plus failed, expired, cancelling and cancelled. When it completes, successful responses are in the file named by output_file_id and failed ones in the file named by error_file_id. Both are downloaded through the Files API.
Every custom_id in a file must be unique, and a file can target only one model. If you need two models, submit two batches.
Anthropic Message Batches API: one JSON request
Anthropic skips the file upload. You post a requests array, and each item has a custom_id and a params object holding a normal Messages API request:
curl https://api.anthropic.com/v1/messages/batches \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{
"requests": [
{
"custom_id": "ticket-0001",
"params": {
"model": "MODEL_NAME",
"max_tokens": 200,
"messages": [{"role": "user", "content": "Classify this ticket: Login page returns 500"}]
}
},
{
"custom_id": "ticket-0002",
"params": {
"model": "MODEL_NAME",
"max_tokens": 200,
"messages": [{"role": "user", "content": "Classify this ticket: Invoice shows wrong VAT"}]
}
}
]
}'
The custom_id must be 1 to 64 characters of letters, digits, hyphens and underscores (^[a-zA-Z0-9_-]{1,64}$). A new batch has processing_status set to in_progress; it changes to ended when every request has finished. Poll it with:
curl "https://api.anthropic.com/v1/messages/batches/$MESSAGE_BATCH_ID" \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2023-06-01"
Once it has ended, the batch's results_url serves a JSONL stream with one result per line. Each result has one of four types: succeeded, errored, canceled or expired. Only succeeded requests are billed.
A few Messages parameters are rejected inside a batch: stream: true, speed (fast mode), fallbacks, and max_tokens: 0. Validation of each params object happens asynchronously, so a typo only shows up as an errored result after the whole batch ends. Anthropic's advice is to send one request of the same shape to the normal Messages API first.
What the 50% discount means in practice
Take a job of 10,000 requests, each using 1,500 input tokens and 200 output tokens. That is 15 million input tokens and 2 million output tokens. With a model priced at $2 per million input tokens and $10 per million output tokens on the synchronous API, the job costs:
- Synchronous: 15 × $2 + 2 × $10 = $50
- Batch at 50%: $25
The prices here are placeholders to show the arithmetic. Use the current per-model prices from your provider's pricing page. The discount applies to tokens, so it doesn't help a job whose cost is dominated by something else, such as your own compute or a downstream API. If token cost is the main line item, see how to reduce AI token usage for levers that stack with batching.
When a batch API is the wrong tool
- A user is waiting. 24 hours is the contract, and under load more requests can expire. Anthropic warns that processing may slow with demand, which can mean more expirations.
- Each step depends on the previous answer. An agent loop that feeds one response into the next prompt can't be batched, because the second request doesn't exist until the first one returns. You can batch one step across many independent items, then batch the next step.
- You need streaming. Neither provider streams batch output.
- The job is tiny. For 20 requests, the extra code for polling and result matching costs more time than the discount saves.
Practical tips that save a failed batch
- Make
custom_idmeaningful. Use your own record ID (ticket-48213) so a result maps straight back to a database row without a lookup table. - Ask for structured output. You'll parse thousands of responses with no one reading them, so request JSON and validate it. See how to get JSON from an LLM reliably.
- Retry only the failures. Collect the
custom_idvalues of errored and expired results and submit them as a new, smaller batch. - Split very large jobs. Several batches are easier to monitor and retry than one batch at the size limit. OpenAI allows up to 2,000 batch creations per hour, so batch count is rarely the bottleneck.
- Download results promptly. OpenAI deletes output files 30 days after completion; Anthropic results disappear 29 days after the batch was created, not after it ended.
If a batch keeps failing
An OpenAI batch stuck in failed usually means the input file didn't validate: a line that isn't valid JSON, a duplicate custom_id, or requests for two different models in one file. On Anthropic, an HTTP 413 request_too_large means the batch is over 256 MB, so split it. If every result comes back errored, the request shape is wrong; send one of the params objects to the synchronous endpoint and read the error it returns.
Frequently asked questions
- How long does a batch API request take?
- Both OpenAI and Anthropic process batches within a 24-hour window. Anthropic says most batches finish in under an hour, and OpenAI says batches often finish sooner than 24 hours. Neither guarantees a time below 24 hours, and requests still unprocessed at the deadline expire.
- Does the batch discount stack with prompt caching?
- Anthropic says prompt caching can be used inside a batch, but cache hits are best effort because batched requests run concurrently and in any order. It suggests the 1-hour cache duration for batches with shared context. Check the provider's pricing page for how the two discounts combine on a given model.
- Can I stream responses from a batch?
- No. Anthropic rejects stream: true inside a batch request with a validation error, and OpenAI returns batch output as a file. Results arrive only when processing has ended, so batching suits jobs where nobody is waiting on a reply.
- Am I charged for batch requests that fail or expire?
- Anthropic does not bill errored, canceled or expired requests. OpenAI charges for requests that completed before a batch expired, and lists unfinished requests in the error file with the code batch_expired.