What you will be able to do
- Decide whether a workload belongs on the synchronous Messages API or the Message Batches API from its latency requirement
- Build valid batch requests with custom_id values and size batches within the per-batch limits
- Calculate how often to submit batches so a delivery SLA holds in the worst case
- Recover from a partially failed batch by resubmitting only the failed custom_ids with a fix, after refining the prompt on a sample first
Key concept
Batch as a delivery contract — The Message Batches API charges half price because it gives up any promise about when a result comes back. Each request is processed on its own, finishes at some point within a 24-hour expiry window, and is matched back to its input only through its custom_id.
1.What a batch is, what it saves, and how custom_id ties it together
A Message Batch is a list of ordinary Messages API requests that you submit together and that get processed asynchronously. You don't wait on an open connection. You create the batch, poll its status, and download the results once processing has ended. Each request inside the batch is handled independently, so one batch can mix plain prompts, system prompts, multi-turn histories and images.
In return for giving up immediacy you pay 50% of standard prices on all usage: input tokens, output tokens and any special tokens. Prompt caching still applies inside a batch, so the two discounts stack. If ten triage requests cost about $0.74 run synchronously, the same ten cost about $0.37 as a batch, with identical token counts.
Every request in a batch has two parts: a custom_id and a params object holding the standard Messages parameters. The custom_id is the only link between a result and the request that produced it. It must be unique within the batch, 1 to 64 characters long, and built only from letters, digits, hyphens and underscores, matching ^[a-zA-Z0-9_-]{1,64}$. Spaces, slashes, colons, hashes and dots all break that pattern. A descriptive label like doc/2026/report:final therefore fails validation, while doc-2026-report_final passes. Readability has to come from hyphens and underscores, not from punctuation.
message_batch = client.messages.batches.create(
requests=[
Request(
custom_id="my-first-request",
params=MessageCreateParamsNonStreaming(
model="claude-opus-5-5",
max_tokens=1024,
messages=[
{
"role": "user",
"content": "Hello, world",
}
],
),
),A few Messages parameters are rejected inside a batch. stream: true fails because batch results come back as a single file. speed (Fast mode) fails because it tunes synchronous latency. max_tokens: 0 fails because a cache entry written during batch processing would likely expire before the follow-up request ran. Including any of them returns a validation error.
Checkpoint 1 of 9· Fill the gap
Results from a batch can come back in any order. Which field name completes this request so each result can be matched to the request that produced it?
message_batch = client.messages.batches.create(
requests=[
Request(
? ="my-first-request",
params=MessageCreateParamsNonStreaming(
model="claude-opus-5-5",
max_tokens=1024,
messages=[
{
"role": "user",
"content": "Hello, world",
}
],
),
),Each batch Request has a custom_id next to its params object. This developer-provided ID must be unique within the batch, and it is the only link between a result and its request. The API generates the batch's own id, so you don't set it per request.
Source: platform.claude.comCheckpoint 2 of 9· Exam question
A developer is assembling a batch of translation requests and needs to assign each one an identifier that the Message Batches API will accept and later use to correlate a result with its original request. Which identifier is valid for this purpose?
Correct answer: A — doc-2026-report_final, since it uses only letters, digits, hyphens, and underscores, staying under the 64-character limit
- A. Correct. custom_id must match ^[a-zA-Z0-9_-]{1,64}$, meaning only alphanumeric characters, hyphens, and underscores are allowed; this identifier satisfies that constraint.
- B. Incorrect. Slashes and colons are not permitted characters in a custom_id and would cause the request to be rejected.
- C. Incorrect. Spaces are not permitted characters in a custom_id, regardless of how readable they make the identifier.
- D. Incorrect. The hash character is not part of the allowed character set for custom_id, so this identifier would fail validation.
2.Sizing a batch within its limits
A single batch holds at most 100,000 requests or 256 MB, whichever comes first. Both caps apply at once. A nightly job of 150,000 invoices needs at least two batches on the request count alone. If the invoices are scanned images that push the payload past 256 MB, it needs more, even though each batch is under 100,000 requests. A batch that is too large is rejected with a 413 request_too_large error.
Splitting large datasets into several batches is a good idea even below the caps, because smaller batches are easier to manage. It also helps later: when one batch fails or expires, the scope of the recovery work is that batch, not the whole night's run.
Checkpoint 3 of 9· Check yourself
A nightly job submits 60,000 document-review requests in one batch. Each one embeds scanned page images, and the batch payload comes to about 400 MB. What happens, and what should the team change?
Both per-batch caps apply at once, and whichever is reached first sets the limit. This batch is under the request cap but over the 256 MB size cap, so it is rejected and has to be split. No per-hour batch cap exists, and Batches usage does not count against Messages API rate limits.
“A Message Batch is limited to either 100,000 Message requests or 256 MB in size, whichever is reached first.”Source: platform.claude.com
Checkpoint 4 of 9· Exam question
A data-ingestion job needs to classify 150,000 scanned invoices in one nightly run using the Message Batches API. What must the team account for given the platform's per-batch limits?
Correct answer: A — Split the 150,000 invoices across at least 2 batch submissions, because a single Message Batch is capped at 100,000 requests or 256 MB total payload, whichever comes first. (More batches may be needed if the total payload exceeds 256 MB.)
- A. Correct. According to the current Anthropic Message Batches API documentation, each Message Batch can contain up to 100,000 requests or 256 MB of total payload, whichever limit is reached first. Since 150,000 invoices exceed the request limit, the team must split them into at least 2 batch submissions (150,000 ÷ 100,000 = 1.5, rounded up to 2). If the combined payload of any batch exceeds 256 MB, additional batches will be necessary.
- B. Incorrect. The Message Batches API does have explicit request and payload limits: up to 100,000 requests per batch and a total size of 256 MB, whichever comes first. Submitting 150,000 invoices in one batch would exceed the request limit.
- C. Incorrect. The maximum batch size is 100,000 requests, not exactly 1,000. While splitting large workloads into smaller independent batches may improve reliability and incremental processing, it is not a platform maximum.
- D. Incorrect. The Batches API is not limited to 500 requests per hour; it supports batches of up to 100,000 requests with a processing SLA of up to 24 hours. The synchronous Messages API can be used for real-time calls, but it is not required and is typically less cost-effective for large batch classification.
Sources1
3.Matching the API to the workflow's latency requirement
The only timing promise the Batches API makes is an upper bound: results become available when every request has finished or after 24 hours, whichever comes first, and anything unprocessed by then expires. How long processing actually takes depends on batch size, current demand and your own volume. Under heavy load, more requests expire. No latency SLA means you can't plan around the typical case.
So the deciding question is whether something is blocked while it waits. A pre-merge check blocks a developer, so it belongs on the synchronous Messages API, and the gate reads its verdict straight from the response. Wrapping the synchronous call in a background job that lets the check pass while the verdict arrives later as a comment is also wrong: the gate no longer depends on the review it is supposed to enforce. Overnight reports, weekly audits and nightly test generation block nobody. Nobody notices whether they finish in forty minutes or nine hours, so they should take the 50% discount.
| Workload | Is anything waiting on the result? | API | Why |
|---|---|---|---|
| Pre-merge code-review gate | Yes, the PR cannot merge until it returns | Synchronous Messages API | The verdict is needed in seconds and the batch window has no latency SLA |
| Nightly regression-test generation for 40,000 modules | No, reviewed the next day | Message Batches API | Latency-tolerant and high volume, so 50% off all usage |
| Weekly compliance audit report | No | Message Batches API | Finishes well before anyone reads it |
| User-facing chat reply | Yes, a person is waiting | Synchronous Messages API | Deadline-bound work stays on the synchronous path |
Checkpoint 5 of 9· Check yourself
Four teams want to move their Claude workloads to the Message Batches API to get the 50% discount. Which workload should stay on the synchronous Messages API?
The deciding question is whether anyone is blocked while waiting. A customer waiting in a chat is blocked, and the batch window only promises completion or expiry within 24 hours, with no latency SLA. The audit, the test generation and the overnight report block nobody, so they can take the discount.
“that window is an expiry, not an SLA, so keep anything user-facing or deadline-bound on the synchronous path.”Source: platform.claude.com
Checkpoint 6 of 9· Exam question
A platform team runs an automated code-review gate that blocks a pull request from merging until Claude returns a verdict on the diff, typically within a few seconds. Which approach should they use for this workflow?
Correct answer: A — Call the Messages API synchronously for each diff, and have the merge check read the verdict directly from the API response
- A. Correct. The merge is blocked until a verdict arrives within a few seconds, and a synchronous Messages API call returns the result in the same request. The Message Batches API has no guaranteed turnaround and can take up to 24 hours.
- B. Incorrect. A batch holding a single request is still processed asynchronously, and its completion time is not guaranteed. The pull request could stay blocked for hours, not the few seconds the gate needs.
- C. Incorrect. The 50% discount comes with asynchronous processing and no guaranteed completion time, which can be up to 24 hours. A gate that blocks merging until a verdict arrives within seconds cannot wait on a batch to end.
- D. Incorrect. The Messages API is the right API, but letting the merge check pass before the verdict exists removes the gate. The workflow must block the pull request until Claude returns its verdict.
4.Why client-side tool loops cannot run inside a batch request
A batch request is single-shot. Your code builds the full request up front, and one result comes back later in a file. That rules out the agentic loop driven by stop_reason, where the client reads tool_use, runs the tool and sends back a tool_result. No client is present mid-request to run your tool and continue the conversation. A workload that needs your own tools called across several turns, such as an agent that looks up a database and then decides what to do next, can't be expressed as one batch request.
This is narrower than "no tools in batches". A request can include tool definitions and earlier turns of a conversation, and server tools such as web search run inside the batch, because the batch worker runs the same server-side loop as the synchronous API. If such a result comes back with stop_reason: "pause_turn", the turn didn't finish, and continuing it means submitting a new request. The usual pattern is to batch the single-pass step and leave the loop on the synchronous path. In a claims pipeline, for example, the triage pass that decides which claims need the agent at all can be batched, while the tool-calling agent itself can't.
Checkpoint 7 of 9· Check yourself
An insurer's claims agent calls the company's own policy-database lookup tool, reads what comes back, and then decides on its next step, often over several turns. To get the 50% discount, the team wants to move the pipeline to the Message Batches API. What is the right design?
A batch request is single-shot. No client is present mid-request to run your own tool and return a tool_result, so a multi-turn loop with client tools stays synchronous. Tool definitions themselves are allowed in a batch, and stream: true is rejected. The one-prompt, one-answer triage pass is the part that can be batched.
“Batch requests are single-shot (no mid-batch tool loop), so the natural fit for our agent is the initial classification pass”Source: platform.claude.com
5.Calculating submission frequency from an SLA
When you promise stakeholders a delivery deadline, plan for the worst case at both ends. The unluckiest document arrives just after a submission cycle closes, so it waits one full interval before it's even submitted. After that, the batch can take the full 24 hours. The worst-case delivery time is therefore the submission interval plus 24 hours, and that sum must fit inside the SLA:
interval + 24 h ≤ SLA, so the interval can be at most SLA − 24 h.
A 48-hour promise allows submission cycles up to 24 hours apart, so a nightly batch works. A 30-hour promise leaves only 6 hours of slack, and the standard design submits every 4 hours. The remaining two hours cover collecting the documents, submitting the batch and processing the results. A once-a-day schedule against a 30-hour SLA fails for every document that arrives just after the daily run.
Barely. 12 + 24 = 36, so with zero overhead it lands exactly on the deadline. Any time spent assembling the batch or post-processing results breaks it. A shorter interval, such as 8 hours, leaves margin.
Long generations eat into the window too. A single request with a very large max_tokens can run for over an hour, so plan batch submissions around the 24-hour window rather than the typical completion time.
Checkpoint 8 of 9· Check yourself
Contracts arrive around the clock, and stakeholders have been promised every extraction result within 30 hours of a contract's arrival. The pipeline uses the Message Batches API. Which submission schedule keeps that promise in the worst case?
Worst-case delivery is the submission interval plus the full 24-hour batch window, so the interval can be at most 30 − 24 = 6 hours. Every 4 hours leaves room to assemble the batch and process the results. Nightly, 12-hour and 8-hour cycles all break the SLA for a document that arrives just after a cycle closes, because the typical completion time is not a guarantee.
“You can access batch results when all messages have completed or after 24 hours, whichever comes first.”Source: platform.claude.com
Sources1
6.Reading results and resubmitting only what failed
The batch's processing_status starts as in_progress and changes to ended once every request has finished. A simple loop polls the retrieval endpoint until that happens. Results then download as a .jsonl file, one line per request. The lines are not guaranteed to be in request order, so the only reliable way to join a result to its input is the custom_id.
import time
client = anthropic.Anthropic()
MESSAGE_BATCH_ID = "msgbatch_01HkcTjaV5uDC8jWR4ZsDV8d"
message_batch = None
while True:
message_batch = client.messages.batches.retrieve(MESSAGE_BATCH_ID)
if message_batch.processing_status == "ended":
break
print(f"Batch {MESSAGE_BATCH_ID} is still processing...")
time.sleep(60)
print(message_batch)| Result type | Meaning | Billed? | Next step |
|---|---|---|---|
| succeeded | Request succeeded and includes the message | Yes | Validate and store, keyed by custom_id |
| errored | Request hit an error (invalid request or internal server error) and no message was created | No | Read the error details, fix the cause, resubmit |
| canceled | Batch was canceled before this request was sent to the model | No | Resubmit if still needed |
| expired | Batch hit its 24-hour expiry before this request was sent to the model | No | Resubmit, keeping the SLA in mind |
A failed request doesn't affect the rest of the batch, so after a run of 10,000 documents with 37 errors you already have 9,963 valid results. Rerunning all 10,000 would pay again for work already done. You also can't edit the batch, because a submitted batch can't be modified. The recovery is a **new batch containing only the failed custom_ids**, each carrying a fix for its particular error. Resubmitting the same request unchanged only helps with transient failures like internal server errors or expiry.
The fix depends on the error. A document whose input alone exceeds the model's context window gets a 400 invalid_request_error ("prompt is too long"), and it will fail again every time it's resubmitted unchanged. Split it into chunks that each fit, give each chunk its own derived custom_id such as contract-0412_part1 and contract-0412_part2, and recombine the parts afterwards. The token counting API can catch oversized documents before the first submission.
The expensive failures are the ones that don't show up as errors. Errored requests are free, but a request that succeeds with a wrong or badly formatted answer from a weak prompt is billed at the batch rate and costs you a full processing cycle before you notice. Before batching tens of thousands of documents, dry run the request shape through the synchronous Messages API to catch validation errors. Then refine the prompt on a representative sample, measured against an eval, until it passes. Each point of first-pass success gained on the sample saves a resubmission cycle across the full volume.
Checkpoint 9 of 9· Fill the gap
A nightly job polls its batch and should only download the .jsonl results after every request has finished. Which value completes the status test so the loop exits at the right moment?
import time
client = anthropic.Anthropic()
MESSAGE_BATCH_ID = "msgbatch_01HkcTjaV5uDC8jWR4ZsDV8d"
message_batch = None
while True:
message_batch = client.messages.batches.retrieve(MESSAGE_BATCH_ID)
if message_batch.processing_status == " ? ":
break
print(f"Batch {MESSAGE_BATCH_ID} is still processing...")
time.sleep(60)
print(message_batch)The batch's processing_status starts as in_progress and changes to ended once every request has finished, whatever its outcome. "succeeded" is a per-request result type, not a batch status. A batch that ends with some errored or expired requests is still ended, and those failed custom_ids are what you resubmit in a new batch.
Source: platform.claude.comSources
(4)
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.
“The batch is then processed asynchronously, with each request handled independently.”
↩︎ What a batch is, what it saves, and how custom_id ties it together“All usage is charged at 50% of the standard API prices.”
↩︎ What a batch is, what it saves, and how custom_id ties it together“Must be 1 to 64 characters and contain only alphanumeric characters, hyphens, and underscores”
↩︎ What a batch is, what it saves, and how custom_id ties it together“Batch results come back as a single file, not a stream.”
↩︎ What a batch is, what it saves, and how custom_id ties it together“A Message Batch is limited to either 100,000 Message requests or 256 MB in size, whichever is reached first.”
↩︎ Sizing a batch within its limits“If the request size is too large, you may get a 413 request_too_large error.”
↩︎ Sizing a batch within its limits“Consider breaking very large datasets into multiple batches for better manageability.”
↩︎ Sizing a batch within its limits“Usage of the Batches API does not affect rate limits in the Messages API.”
↩︎ Sizing a batch within its limits“You can access batch results when all messages have completed or after 24 hours, whichever comes first.”
↩︎ Matching the API to the workflow's latency requirement“Actual processing time depends on the size of the batch, current demand, and your request volume.”
↩︎ Matching the API to the workflow's latency requirement“The batch worker runs the same server-side agentic loop as the synchronous Messages API.”
↩︎ Why client-side tool loops cannot run inside a batch request“If a batch result comes back with pause_turn, the turn did not finish”
↩︎ Why client-side tool loops cannot run inside a batch request“Batches expire if processing does not complete within 24 hours.”
↩︎ Calculating submission frequency from an SLA“A single 300k-token generation can take over an hour to complete, so plan your batch submissions with the 24-hour processing window in mind.”
↩︎ Calculating submission frequency from an SLA“You will not be billed for these requests.”
↩︎ Reading results and resubmitting only what failed“Note that the failure of one request in a batch does not affect the processing of other requests.”
↩︎ Reading results and resubmitting only what failed“No, once a batch has been submitted, it cannot be modified.”
↩︎ Reading results and resubmitting only what failed“Dry run a single request shape with the Messages API to avoid validation errors.”
↩︎ Reading results and resubmitting only what failed“It is possible for a batch to expire and not complete within 24 hours.”
↩︎ Exam trap 1“Must be 1 to 64 characters and contain only alphanumeric characters, hyphens, and underscores”
↩︎ Exam trap 2“Note that the failure of one request in a batch does not affect the processing of other requests.”
↩︎ Exam trap 4“Batches may take up to 24 hours for processing, but many finish sooner.”
↩︎ Prediction“You can access batch results when all messages have completed or after 24 hours, whichever comes first.”
↩︎ Checkpoint - 2.
“Prompt caching still applies within the batch, so the discounts stack.”
↩︎ What a batch is, what it saves, and how custom_id ties it together“that window is an expiry, not an SLA, so keep anything user-facing or deadline-bound on the synchronous path.”
↩︎ Matching the API to the workflow's latency requirement“Batch requests are single-shot (no mid-batch tool loop)”
↩︎ Why client-side tool loops cannot run inside a batch request“get it working on a capable model, build an eval, and measure a baseline”
↩︎ Reading results and resubmitting only what failed“that window is an expiry, not an SLA, so keep anything user-facing or deadline-bound on the synchronous path.”
↩︎ Key concept“Batch requests are single-shot (no mid-batch tool loop)”
↩︎ Exam trap 5“Batch requests are single-shot (no mid-batch tool loop), so the natural fit for our agent is the initial classification pass”
↩︎ Checkpoint - 3.
“Results are not guaranteed to be in the same order as requests. Use the custom_id field to match results to requests.”
↩︎ Reading results and resubmitting only what failed“Results are not guaranteed to be in the same order as requests. Use the custom_id field to match results to requests.”
↩︎ Exam trap 3 - 4.
“If the input alone already exceeds the model's context window, the API returns a 400 invalid_request_error”
↩︎ Reading results and resubmitting only what failed“use the token counting API to estimate token usage before sending messages to Claude.”
↩︎ Reading results and resubmitting only what failed