By Abhijith N M · Reviewed 24 October 2026 · Editorial standards
You have 40,000 support transcripts to classify and a report that is read tomorrow afternoon. Sending them one at a time means you pay full price for work nobody is waiting on, and you spend the night watching a progress bar. The Message Batches API exists for exactly this shape of work.
A batch is a large set of requests submitted together. You get an id, you poll it, and you read results when the batch ends. The trade is simple and it is the whole lesson: you give up latency, and you get a lower price and a simpler operational path.
Five properties decide your design. Read them before you pick a workload, because each one rules something out.
| Property | What it means | What it changes in your design |
|---|---|---|
| Price | About half the standard rate; confirm on the current pricing page | Batch the work where nobody is waiting |
| Window | Up to 24 hours before the batch ends | Your deadline must sit beyond the ceiling, not at it |
| Correlation | Every request carries your custom_id | Join results by id, never by position |
| Ordering | Results are not in submission order | Build a map from id to result before you write anything |
| Tool use | One turn per request; no multi-turn tool loop | A tool round trip needs separate batches or real-time calls |
The last row is the one teams miss. A single request can call a tool, but the batch will not run the next turn for you. If your design needs the model to read a tool result and call a second tool, that conversation does not finish inside one batch submission.
custom_id is the identifier you attach to each request. It is how you find the answer later. Make it unique inside the batch, stable across resubmissions, and derived from something you already own, such as the document id and a prompt version.
Stability matters because a batch can expire before every request ends. When you resubmit the stragglers, the same ids let you dedupe the results you already stored and avoid processing a document twice.
DOCUMENTS = [f"doc-{n}" for n in range(1, 6)]
def make_requests(documents: list[str]) -> list[dict]:
return [
{
"custom_id": f"extract-{doc}",
"params": {
"messages": [
{"role": "user", "content": f"Extract fields from {doc}."}
]
},
}
for doc in documents
]
def integrate(requests: list[dict], results: list[dict]) -> dict:
by_id = {item["custom_id"]: item["result"] for item in results}
matched = [
request["custom_id"]
for request in requests
if request["custom_id"] in by_id
]
missing = [
request["custom_id"]
for request in requests
if request["custom_id"] not in by_id
]
return {"matched": len(matched), "missing": missing}
requests = make_requests(DOCUMENTS)
ids = [request["custom_id"] for request in requests]
# Results arrive out of order, and one request has not ended yet.
results = [
{"custom_id": custom_id, "result": {"status": "ok"}}
for custom_id in reversed(ids[:-1])
]
print(integrate(requests, results))Treat the window as a ceiling, not a schedule. Most batches finish sooner, but the one that matters is the one that runs long. Work backwards from your deadline: if the report is read at 14:00 tomorrow, submit early enough that a resubmission still lands in time.
Split large volumes into chunks you can resubmit independently. A chunk of 5,000 documents that expires costs you one chunk, not the night. Keep a record per chunk: what was submitted, when, and which ids came back.
Batching is for work that can wait and has volume. It is the wrong tool for anything a person is watching, anything that needs an approval before the next step, and anything that needs more than one tool turn.
Sort three real jobs into batch and real-time, then write the failure path for the one you keep.
custom_id scheme for a batched job, including a prompt version so a resubmission cannot mix schema versions.Key takeaways
Batches trade latency for price: about half the standard rate for work that can wait.
The window is up to 24 hours, so plan a deadline beyond it and a resubmission path.
Join results by custom_id; results are not ordered and can arrive incomplete.
A batch request is one turn, so multi-turn tool loops do not fit inside it.
Monitor submitted, ended, expired and missing counts, or the savings hide lost work.
Written and edited by the nexGenCoders team. Spotted a mistake? Tell us and we will fix it.
Don't lose this lesson
Create a free account to save your progress, keep your streak, and work toward a shareable certificate.