The Illustrated Batch API

TLDR

Batch processing (the Batch API) hands the requests to the provider all at once, and you do not wait for the results, in exchange for a 50% discount. It is cheap because you let the provider choose when to compute, not because the model computes faster.

Open the pricing pages for OpenAI, Anthropic, and Gemini, and you see the same option: Batch, half price. The condition is that you do not take the results right away. You wait up to 24 hours. Same model, same output. Why half price? This essay first looks at how each provider offers it and what they charge, then explains why it is cheap, and finally how LiteLLM wires them into one codebase.

Background: during inference the GPU reads the model weights over and over. Running several requests together is the most economical. See illustrate of vLLM. A cache hit being cheap is a different mechanism. See illustrate of KV Cache and illustrate of Prefix Caching (prefix caching). This essay is about a third way to save money: trade time for money.

All three major APIs charge half price for a wait of up to 24 hours

Look at it from the outside first. For the caller, batch processing is a "request file in, result file out" interface. There is no streaming output, and no promise of when it is done. The figure below is the official price of a few models (per million tokens, read on 2026-11-26). Claude's batch price comes from the price table in the Anthropic batch processing docs. The standard price comes from the official pricing page of 2026-11-24 (see the appendix of illustrate of KV Cache). DeepSeek has no batch processing interface. The matching price is the off-peak price on the official pricing page.

Two bars per model. Gray is the standard price. Blue is the batch price (the off-peak price for DeepSeek). Input and output each use their own scale. The right-hand column is blue ÷ gray. All 5 models are 0.5×.

The numbers are the same: input and output are both cut in half. Now look at how the rules differ:

VendorDiscountWait capPer-batch capResult retention / expiry
OpenAI50% of the standard price24 hours (completion_window can currently only be set to 24h)50,000 requests, input file 200 MBThe output file is kept for 30 days by default. Requests unfinished at the deadline are cancelled. Finished ones are billed as usual.
Anthropic (Message Batches)50% of the standard price24 hours. The docs say most finish within 1 hour100,000 requests or 256 MB, whichever comes firstResults are kept for 29 days. If it does not finish within 24 hours, it expires
Google Gemini50% of the standard priceTarget 24 hours, most finish sooner. Still unfinished after 48 hours counts as expired (JOB_STATE_EXPIRED)Inline requests < 20 MB; max file 2 GB—
Amazon BedrockSome models are 50% below the on-demand priceNot checked this timeNot checked this time—
DeepSeekNo batch processing interface. The off-peak price is half the peak price (synchronous calls)None——

Behind this table there are really three forms, and all three sell the same thing: flexibility in time.

How long do you actually wait? The docs only give a cap. Anthropic writes "most batches finish within 1 hour." OpenRouter's own batch processing beta (not OpenAI's data; I only read the summary) says a median of 7 minutes, and 90% within 1 hour. See their blog. 24 hours is the cap, not the typical value, but you cannot ask it to go faster.

A batch takes five steps, with no open connection and results matched by custom_id

The five steps are basically the same at each provider. The figure below uses OpenAI's format (LiteLLM follows it too). Click Next step to walk through them.

Five steps: write the file, upload, create the batch, queue, download. Only step 4 requires "waiting," and while you wait you hold no connection.

Watch two details. First, the results in the output file are not guaranteed to follow the input order. You have to match them with the custom_id you wrote. Second, a single request in the batch can fail while the others finish as usual. OpenAI writes the failures into a separate error file. Anthropic marks each result as success, error, cancelled, or expired. A retry uses custom_id to pick out the failed ones and resubmit only those. You do not rerun the whole batch.

Why it is cheap: GPU cost is fixed, and batch processing lets the provider put the work into idle time

(What follows is derived from the mechanism, not from a vendor document. Vendors have not published internal costs. The official docs only give prices and rules.)

A sketch. Through the day, real-time requests (gray) swing up and down. GPU capacity (the red dashed line) is fixed. Blue is the spare capacity, which batch processing can fill. The amber vertical bands are the peak hours marked in the DeepSeek docs. The shape of the gray curve is a sketch I drew, not real traffic.

First, the cost of a GPU is fixed. The machine is bought or rented. It costs money whether requests show up or not. The denominator in the cost formula is "how many tokens this card actually computed in a day." Idling is pure waste. Fill a little more, and the cost of each token drops a little.

Second, real-time traffic swings a lot through the day. Capacity has to be sized for the peak. Below the gray in the figure above is real-time requests. Blue is the gap at the valley. DeepSeek writes the peak hours on the pricing page (UTC 01:00–04:00 and 06:00–10:00, which is 09:00–12:00 and 14:00–18:00 Beijing time, exactly working hours). Off-peak is half price. That puts "the valley is cheaper" directly on the price list. The Gemini docs explain Flex with the same line: use "opportunistic, off-peak compute."

Third, batch processing gives the provider the freedom to pick the time. A real-time request has to start emitting tokens within a few seconds. It cannot wait. A batch request can sit in a queue and run when a gap opens. The provider's gain: the valley has work too. Your cost: you do not know exactly when it will be done.

Fourth, a batch uses a GPU's compute more fully. In the Decode stage, every step has to read tens of GB of weights once. Computing several requests together costs almost no extra time (see the mechanism in illustrate of vLLM). Batch processing has no time-to-first-token requirement. The scheduler can push the concurrency of one step up to the limit. It can also group requests that share a prefix and reuse the KV Cache. Anthropic's docs suggest this: a batch may run past 5 minutes, so use it with a 1-hour cache lifetime, and the cache hit rate is higher.

Fifth, batch processing can be interrupted and retried. Gemini describes batch processing as "preemptible (sheddable), but with a 24-hour system of automatic retries and queueing." When real-time traffic arrives, the compute for batch processing can be given up first, and the work finished later.

Why is every provider exactly 50%?

The test: was this discount computed from a cost formula, or is it a pricing decision?

One bill: a million requests on Sonnet 5.5 drop from $9,000 to $4,500

Assume 2,000 input tokens and 500 output tokens per request, and 1,000,000 requests in total. The standard price for Claude Sonnet 5.5 is $2 / $10 (per million input / output tokens). The batch price is $1 / $5.

InputOutputTotal
Token total2,000 MTok (2 billion)500 MTok (500 million)—
Standard price2,000 × $2 = $4,000500 × $10 = $5,000$9,000
Batch price2,000 × $1 = $2,000500 × $5 = $2,500$4,500

(MTok means million tokens.) 1,000,000 requests are over Anthropic's per-batch cap of 100,000, so you split them into at least 10 batches. Assumptions in this bill: the output length and the input length are both estimates. The real bill is the usage returned by the API. If a few hundred thousand requests share a long system prompt, you can also stack prompt caching. The official docs suggest a 1-hour cache. How much extra discount stacks depends on each provider's pricing page (I did not check them one by one).

LiteLLM puts every provider's batch API behind OpenAI's files + batches interface

LiteLLM is an open-source Python library plus a proxy server (Proxy). For batch processing, it does two things: A unified interface (you write OpenAI-format code once) and routing (it sends to different vendors according to the config). It does not make batch processing cheaper. The discount comes from the vendor.

According to the LiteLLM batch processing docs as of 2026-11-26, the providers that support batch processing are OpenAI, Azure, Vertex AI, Amazon Bedrock, Mistral, vLLM, and xAI. This list has no direct Anthropic. To use Claude batch processing, either go through Bedrock or Vertex, or call Anthropic's own SDK (software development kit).

The LiteLLM Proxy sits between your code and the providers: it checks the file, issues a managed file id, picks a deployment, and checks ownership.

Usage 1: call it directly in Python (SDK). Upload the file, then create the batch, poll, and finally download. The snippet below is the OpenAI example copied from the official docs. Match the function names.

import litellm, asyncio, os
os.environ["OPENAI_API_KEY"] = "sk-..."

async def main():
    # 1. Upload mydata.jsonl (one request per line; the format is step 1 above)
    f = await litellm.acreate_file(
        file=open("mydata.jsonl", "rb"),
        purpose="batch",
        custom_llm_provider="openai",
    )
    # 2. Create the batch
    b = await litellm.acreate_batch(
        completion_window="24h",
        endpoint="/v1/chat/completions",
        input_file_id=f.id,
        custom_llm_provider="openai",
    )
    # 3. Poll until a terminal state (completed / failed / expired / cancelled)
    while True:
        b = await litellm.aretrieve_batch(batch_id=b.id, custom_llm_provider="openai")
        if b.status in ("completed", "failed", "expired", "cancelled"):
            break
        await asyncio.sleep(30)   # Batch processing is measured in minutes. Do not poll every 5 seconds
    # 4. Download the results (the output file id is on a completed batch)
    out = await litellm.afile_content(file_id=b.output_file_id, custom_llm_provider="openai")
    print(out.text)

asyncio.run(main())

Usage 2: start the LiteLLM Proxy, and call it with any OpenAI SDK. It fits several people and several services sharing one set of keys and limits. Minimal config (from the official docs):

model_list:
  - model_name: gpt-6.1-sol
    litellm_params:
      model: openai/gpt-6.1-sol
      api_key: os.environ/OPENAI_API_KEY

files_settings:
  - custom_llm_provider: openai
    api_key: os.environ/OPENAI_API_KEY

general_settings:
  master_key: os.environ/LITELLM_MASTER_KEY
litellm --config config.yaml      # RUNNING on http://0.0.0.0:4000

Then the client points base_url at the proxy. Everything else is exactly the same as calling OpenAI directly:

from openai import OpenAI
client = OpenAI(base_url="http://0.0.0.0:4000", api_key="sk-<your-litellm-key>")

f = client.files.create(file=open("request.jsonl", "rb"), purpose="batch")
b = client.batches.create(input_file_id=f.id, endpoint="/v1/chat/completions",
                          completion_window="24h")
# Then poll with client.batches.retrieve(b.id), and download with client.files.content(b.output_file_id)

Usage 3: managed files (Managed Files): one model name, several deployments, load balancing. Put the same batch model name on several deployments, and set mode: batch. On upload, pass target_model_names. The file is written to every matching deployment, and batches are load-balanced across them. From the Managed Files docs (this feature is marked BETA, the SDK does not support it, and it needs Postgres to store file ids):

model_list:
  - model_name: "gpt-5.4-mini-batch"
    litellm_params:
      model: azure/gpt-5.4-mini-general-deployment
      api_base: os.environ/AZURE_API_BASE
      api_key: os.environ/AZURE_API_KEY
    model_info:
      mode: batch          # mark this as a batch-processing model

  - model_name: "gpt-5.4-mini-batch"
    litellm_params:
      model: openai/gpt-5.4-mini
      api_key: os.environ/OPENAI_API_KEY
    model_info:
      mode: batch
f = client.files.create(
    file=open("request.jsonl", "rb"), purpose="batch",
    extra_body={"target_model_names": "gpt-5.4-mini-batch"},   # must match the model inside the jsonl
)
b = client.batches.create(input_file_id=f.id, endpoint="/v1/chat/completions",
                          completion_window="24h")

A few pitfalls (all from the two official docs above):

Only tasks that are "not urgent" are worth batch processing. An agent's online path is not

  1. Suitable: offline evals, data labeling, summarizing or tagging a large pile of documents, generating embeddings in bulk, overnight reports. What they share: nobody minds if the result is a few hours late, and the requests are independent of each other.
  2. Not suitable: a chat where the user is waiting; an agent loop where "call N+1 depends on the output of call N." Every step of that loop has to queue. A 10-step chain waits for 10 batch cycles in the worst case. For this, look at a synchronous cheap tier such as Gemini Flex or the DeepSeek off-peak price.
  3. Small first, then large: Run the whole flow with 10 requests first. Confirm that custom_id, output parsing, and error-file handling are all correct, then scale up.
  4. Split at the per-batch cap: OpenAI 50,000 / 200 MB, Anthropic 100,000 / 256 MB, Gemini files 2 GB. The LiteLLM docs also list caps for Vertex (200,000 rows / 1 GB) and Bedrock (1 GB per file). Whichever provider you route to, split to the smallest of those caps.
  5. Put the shared prefix first: When the whole batch uses the same system prompt, keep it identical, character for character, or a cache hit may not happen (see illustrate of Prefix Caching (prefix caching)).
  6. Leave room for expiry: An OpenAI batch that hits the time limit cancels the unfinished requests. Finished ones are billed as usual. An Anthropic batch that has not finished in 24 hours also expires. Design it so that you "resubmit only the failed ones."

Explained for a 10-year-old

  1. A restaurant has two ways to order. A meal you order on the spot has to hit the table right away, so the cook has to stand by. "Reserve a takeout and pick it up tomorrow" can wait until the cook is not busy.
  2. The kitchen spends money even when it is not busy. The stove and the cook's wages do not get smaller just because there are no customers. So the cook is glad to make a few extra portions while idle.
  3. So reserved takeout is half price. The food is not cheaper. You let the cook pick the time. An AI company's Batch works the same way.
  4. Give every meal a number. Takeout is not necessarily ready in the order you placed it. The number (custom_id) is how you tell which meal is which.
  5. LiteLLM is the switchboard. You talk into one phone. It transfers you to different restaurants. It will not discount the meal on the restaurant's behalf.

Recap

Further reading