Task Statement 4.5·Domain 4 — 20% of exam
Batch Processing Strategies
Design efficient batch processing strategies
Official Exam Guide Objectives
The objectives below are quoted from Anthropic's Claude Certified Architect – Foundations exam guide, v1.1. Read the exam guide summary for the full blueprint.
Task 4.5: Design efficient batch processing strategies
Knowledge of
- The Message Batches API: 50% cost savings, up to 24-hour processing window, no guaranteed latency SLA
- Batch processing is appropriate for non-blocking, latency-tolerant workloads (overnight reports, weekly audits, nightly test generation) and inappropriate for blocking workflows (pre-merge checks)
- The batch API does not support multi-turn tool calling within a single request (cannot execute tools mid-request and return results)
- custom_id fields for correlating batch request/response pairs
Skills in
- Matching API approach to workflow latency requirements: synchronous API for blocking pre-merge checks, batch API for overnight/weekly analysis
- Calculating batch submission frequency based on SLA constraints (e.g., 4-hour windows to guarantee 30-hour SLA with 24-hour batch processing)
- Handling batch failures: resubmitting only failed documents (identified by custom_id) with appropriate modifications (e.g., chunking documents that exceeded context limits)
- Using prompt refinement on a sample set before batch-processing large volumes to maximize first-pass success rates and reduce iterative resubmission costs
What You Need to Know
The Message Batches API buys throughput at a discount, subject to constraints that are not negotiable. The examinable skill is recognising which workloads fit inside those constraints and which cannot.
Message Batches API: The Facts
Five properties define what the API will and will not do, and none of them is tunable:
- 50% cost savings compared to synchronous API calls
- Up to 24-hour processing window — completion may take minutes, and may take the full day
- No guaranteed latency SLA — there is no timeframe you are entitled to rely on
- No multi-turn tool calling within a single batch request — a tool cannot be executed part-way through and its result fed back in to continue
custom_idfields for correlating request/response pairs — every request carries its own identifier, which is how a response is matched back to what produced it
The Matching Rule
This is the single most tested concept from this task statement, and one question decides it: is anything waiting for this result?
Synchronous API: anything where completion is being waited on. A pre-merge check in CI/CD, review feedback a developer is sitting in front of, any step that holds up work until it returns. The thing waiting need not be a person: a pipeline stage that cannot proceed until the result arrives is blocked just as a developer is.
Batch API: anything consumed on someone else's schedule. Overnight technical debt reports, weekly audit summaries, test generation that runs while nobody is working, bulk document extraction. A downstream job with a fixed cutoff hours away (a 06:00 ledger load, say) is not "waiting" in this sense: it is a deadline, and batch can meet it if the work goes in a full processing window ahead (see the SLA calculation below).
"Most batches finish in under an hour" is true and irrelevant to the decision. A blocking workflow cannot be designed around the typical case; what you are entitled to is up to 24 hours with no SLA.
| Workload | API | Why |
|---|---|---|
| Pre-merge CI check | Synchronous | Blocking: developers wait to merge |
| Inline PR comments on push | Synchronous | Blocks the review flow |
| Interactive support agent turn | Synchronous | A person is on the line |
| Multi-turn agent that runs your own tools | Synchronous | A batched request cannot run your tools mid-request |
| Nightly test generation | Batch | Results read the next morning |
| Weekly technical debt audit | Batch | Days of tolerance |
| Invoice backlog of 50,000 documents | Batch | Volume plus tolerance: the largest saving |
| Re-scoring last quarter's tickets | Batch | Analytical, nobody waiting |
Question 11 in the sample set puts this as a proposal to move everything onto batch and capture the saving across the board. The answer that scores keeps the blocking workflows synchronous and moves only the latency-tolerant ones — the saving is real, and it does not apply to work that blocks a person. It is dissected option by option under How This Is Tested.
// Synchronous — developer is waiting for this
const preMergeReview = await client.messages.create({
model: "claude-sonnet-5-5",
max_tokens: 4096,
messages: [{ role: "user", content: prDiffContent }]
});
// Batch — results consumed tomorrow morning
const batchRequest = await client.messages.batches.create({
requests: technicalDebtDocuments.map((doc, i) => ({
custom_id: `debt-report-${i}`,
params: {
model: "claude-sonnet-5-5",
max_tokens: 4096,
messages: [{ role: "user", content: doc }]
}
}))
});The saving does not apply to work that blocks a person, step 1: Pre-merge check — a developer is waiting
SLA Calculation
Scheduling batch work means treating the 24-hour window as spent before you begin. Two shapes of question use that rule.
A fixed deadline (one report due at a set time). The latest safe submission is the deadline minus 24 hours, minus anything that has to happen after the batch ends. A report due at 09:00 Monday with nothing to do after the batch can go in as late as 09:00 Sunday; submitting earlier buys nothing the ceiling does not already guarantee, and makes the inputs older.
A rolling SLA (work arrives continuously, and each item must be delivered within a set number of hours of arriving). This is what the guide's "submission frequency" means. The worst case is an item that arrives just after a submission: it waits a full gap for the next one, then up to 24 hours of processing, then whatever you do downstream.
gap between submissions + 24 h (worst-case processing) + downstream time ≤ SLAFor the guide's 30-hour SLA, the gap can be at most 6 hours with nothing downstream. The guide's example uses 4-hour windows, which leaves 2 hours for work after the batch ends (or margin). An item arriving one minute after a submission waits 4 hours, takes up to 24 to process and 2 more downstream: 30 hours exactly.
| SLA | Downstream | Longest gap | A schedule that holds |
|---|---|---|---|
| 48 h | 2 h | 22 h | Twice a day (every 12 h) |
| 36 h | 3 h | 9 h | Every 9 h, or every 8 h for a daily rhythm |
| 30 h | 2 h | 4 h | Every 4 h (6 a day): the guide's example |
| 30 h | none | 6 h | Every 6 h |
| 26 h | 1 h | 1 h | Hourly |
| 24 h or less | any | none | Impossible on batch: use the synchronous API |
Round the frequency up, never down: once a day against a 48-hour SLA is a 24-hour gap, and 24 + 24 + 2 = 50 hours breaks the promise.
Items may give you the SLA and ask for the submission cadence, or give you a cadence and ask whether the SLA holds; both are this one inequality.
Design against the 24-hour ceiling, not the common case, step 1: Report due — 30-hour SLA
Designing custom_id Values
A custom_id does more than satisfy the API. Good ones share four properties:
- Reconstructible from your own data (
doc-0042,pr-118-file-3,invoice-7f3a-chunk-2), so a resubmission set can be derived without a side table - Inside the permitted format: 1 to 64 characters, letters, digits, hyphens and underscores only, so a storage path or filename (with its slashes and dots) cannot be used as it stands
- Unique within the batch, because it is the only key a result carries back
- Derived afresh on a retry (
doc-0042-retry-1,doc-0042-chunk-0), so the retry run is distinguishable from the original and the parent document is still recoverable; leave room within the 64 characters for the suffix
Results come back in any order, so every result is matched to its request by custom_id, never by its position in the results file.
Batch Failure Handling
Not every document in a batch comes back successfully. The failure of one request does not affect the processing of the others, so failures can be dealt with one by one. The correct failure handling pattern has three steps:
1. Identify failures by custom_id. The identifier attached to each request is what makes a failure attributable — read the results and collect the identifiers of everything that did not succeed (errored, expired and canceled results).
2. Resubmit only failures with modifications. Resending everything pays a second time for the requests that already worked. Modify what failed, according to why it failed:
| Failure | What it tells you | Resubmission |
|---|---|---|
| Document ran past the context limit | Deterministic: the same request fails the same way | Split into pieces that fit, each with a derived id such as {parent}-chunk-{k}, then merge the chunk results by parent |
expired, or an internal server error | Transient: nothing about the request was wrong | Resubmit unchanged |
canceled | The batch was canceled before the request reached the model | Resubmit if the work is still wanted |
| Any other invalid request | The request body itself is wrong | Fix the request first (often a job for a person); it does not go back into the loop unchanged |
Where a request succeeded but the extraction was poor, the modification goes into the prompt instead: cutting back the extraction prompt where a document's structure was unusual enough to confuse it, or supplying few-shot examples drawn from the specific layout that failed. This is the same principle as validation retries in Task 4.4: an unchanged retry of a deterministic failure returns the same failure.
3. Refine prompts on a sample set BEFORE batch processing. The step that pays best happens before submission: prove the prompt against a representative sample of 5-10 documents spanning the formats and edge cases the batch contains, and most of the failures never occur.
In the code below, documentsById maps each original custom_id to its source document, and chunkIfNeeded returns that document as a list of pieces that fit the context window (a single piece if it already fits).
// results() streams a .jsonl file in any order, so iterate it and key on custom_id.
const failedIds: string[] = [];
for await (const entry of await client.messages.batches.results(batchId)) {
if (entry.result.type !== "succeeded") failedIds.push(entry.custom_id);
}
// Resubmit only the failures, one request per piece, each under a derived id
const retryRequests = failedIds.flatMap(id =>
chunkIfNeeded(documentsById[id]).map((piece, k) => ({
custom_id: `${id}-chunk-${k}`,
params: {
model: "claude-sonnet-5-5",
max_tokens: 4096,
messages: [{ role: "user", content: piece }]
}
}))
);The invariant both versions keep: the retry contains only the failed documents, each request is traceable to its parent through its id, and the successes are never touched. A real handler would first route each failure by the table above (transient ones resubmitted as they were, other invalid requests set aside for a fix) rather than chunking everything.
Results are not in request order — match by custom_id, step 1: Submitted in order: doc-001, doc-002, doc-003
Multi-Turn Tool Calling Limitation
A batch request can carry tool definitions and tool_choice, a pre-built multi-turn conversation written out in messages (earlier turns, including earlier tool results), and Anthropic's server tools, which run their own loop inside the batch (see the Current state callout in the Deep Dive). What it cannot carry is the client side of a tool loop. A single batch request will not let you:
- Execute one of your own tools part-way through and feed its result back to the model
- Process your tool's result and continue the conversation within the same batch item
- Run your agentic loop within a single batch request
Each batched request is one independent, non-interactive call. Anything requiring your tool to run part-way through belongs on the synchronous API, and this is tested directly: a scenario describing batch work that needs to call your own tool or service during processing is describing a workflow the batch API cannot express, whatever its latency tolerance.
Structured Extraction Inside a Batch
Large extraction runs are the typical batch workload, and the structured-output pattern from Task 4.3 carries over unchanged: each request's params can carry the extraction tool's definition and a tool_choice that forces it, exactly as a synchronous call would, and each succeeded result holds the message to read the tool input from. The only difference is timing: a request shape the API rejects is reported when the whole batch ends, not when you submit it, so dry-run one request synchronously first (see the Deep Dive).
Prompt Optimisation Before Batch Submission
The economics favour work done before submission rather than after:
- Sample set testing: pull 5-10 documents that between them cover the formats, document types and awkward cases the full batch contains
- Iterate on the sample synchronously: work the prompts, examples and schema against those until accuracy on the sample holds up; the synchronous API gives feedback in seconds
- Submit the full batch: the proven prompt carries a materially higher first-pass rate into the volume run
- Handle failures: send back only what failed, each with the modification its failure calls for
Choose the sample deliberately rather than conveniently: it exists to surface the failures the volume run would otherwise hit, so it has to contain the document types that cause them.
Sample-first matters more on batch than on synchronous calls because of wall-clock time, not price: every round of resubmission can take up to 24 hours, so three rounds can cost three days. The loop being optimised is the iteration loop, not the per-request price.
The arithmetic is stark on volume. Across 1,000 documents, a 90% first-pass rate leaves 100 to resubmit. A 60% rate leaves 400 — four times the resubmission volume, and the batch processing cost of those retries on top.
Resubmit only what failed, with a targeted fix, step 1: Sample set: 5-10 documents, prompt v1 to v3
Deep Dive
Cost, timing, and why "best-effort" is not a promise
The 50% discount is unconditional: "The Batches API offers significant cost savings. All usage is charged at 50% of the standard API prices." Timing is a range, not a target: "This approach is well-suited to tasks that do not require immediate responses, with most batches finishing in less than 1 hour," but "the system processes each batch as fast as possible... processing may be slowed down based on current demand and your request volume. In that case, you may see more requests expiring after 24 hours." Design for the 24-hour worst case, not the sub-1-hour common case. Because batches routinely run longer than 5 minutes, the docs also recommend the 1-hour prompt-cache TTL (instead of the default 5-minute one) "for better cache hit rates when processing batches with shared context."
Sourceplatform.claude.com › batch-processingfetched 2026-07-30
Hard size limits and the custom_id contract
A single Message Batch is capped at "100,000 Message requests or 256 MB in size, whichever is reached first" — exceeding the size cap returns a 413 request_too_large error. Every request needs a custom_id matching ^[a-zA-Z0-9_-]{1,64}$ (1-64 alphanumeric characters, hyphens, underscores). That ID exists for one reason: "Batch results can be returned in any order, and may not match the ordering of requests when the batch was created... To correctly match results with their corresponding requests, always use the custom_id field." Never assume position-based matching.
Sourceplatform.claude.com › batch-processingfetched 2026-07-30
Batch lifecycle: statuses, polling, and cancellation
A created batch "begins processing immediately" and "can take up to 24 hours to complete." Its processing_status is one of three values — in_progress, canceling, or ended — starting at in_progress and moving to ended "once all the requests in the batch have finished processing, and results are ready." The docs recommend "a polling loop that checks the batch status periodically until processing has ended." request_counts tallies every request by status; all requests "start as processing and move to one of the other statuses only once processing of the entire batch ends," and the counts always sum to the batch total. Canceling a batch moves it to canceling and then to a final ended state that "may contain partial results for requests that were processed before cancellation."
Sourcesplatform.claude.com › creating-message-batchesplatform.claude.com › batch-processingfetched 2026-07-30
Four result types — and which ones cost you nothing
Once a batch ends, every request resolves to exactly one of four result types: succeeded, errored, canceled, or expired. Only succeeded is billed. The other three explicitly are not: errored requests ("invalid requests and internal server errors") are not billed; canceled requests ("user canceled the batch before this request could be sent to the model") are not billed; expired requests ("batch reached its 24-hour expiration before this request could be sent to the model") are not billed. A stalled or oversubscribed batch does not silently cost you for work that never ran.
Sourceplatform.claude.com › batch-processingfetched 2026-07-30
Retrieving results: streaming .jsonl, and a 29-day clock from creation
Results live at a results_url that is "specified only once processing ends," pointing to a .jsonl file. "Results in the file are not guaranteed to be in the same order as requests" — the same custom_id rule applies here too. Because result files can be large, "it's recommended to stream results back rather than download them all at once." The retrieval window is generous but finite: "Batch results are available for 29 days after creation. After that, you may still view the Batch, but its results will no longer be available for download" — and critically, that clock runs from the batch's creation, not from when processing ended, so a batch that sat queued for most of a day still expires 29 days after created_at.
Sourceplatform.claude.com › batch-processingfetched 2026-07-30
What a batch request can and cannot contain
"Almost any request you can make to the Messages API can be included in a batch," including vision, "Tool use, including all server tools", system messages, "Multi-turn conversations", extended thinking, and most beta features — and because each request is processed independently, you can freely mix request types within one batch. Being able to define tools in a batched request is not the same as running them: the batch cannot execute your client-side tool and continue within the item, because that needs a new request. Four parameters are rejected with a validation error: stream: true ("Batch results come back as a single file, not a stream"), speed (fast mode), fallbacks (server-side fallback) and max_tokens: 0 (cache pre-warming). Validation itself is asynchronous — the API "returns validation errors when processing of the entire batch has ended," not at submission time — which is why the docs recommend you "dry run a single request shape with the Messages API" before batching thousands of them.
Sourceplatform.claude.com › batch-processingfetched 2026-11-19
Current state — the multi-turn tool-calling limitation, precisely
Sourceplatform.claude.com › batch-processingfetched 2026-11-19
Quick Reference
| Item | Value / rule |
|---|---|
| Cost discount | 50% of standard API prices, unconditionally |
| Typical processing time | Under 1 hour for most batches |
| Maximum processing window | 24 hours (hard); requests not processed by then expire |
| Latency guarantee | None — best-effort, slower under high demand |
| The deciding question | Is anything waiting on the result? Yes → synchronous; no → batch |
| Batch size limit | 100,000 requests OR 256 MB, whichever first |
| Oversized batch error | 413 request_too_large |
| custom_id format | ^[a-zA-Z0-9_-]{1,64}$, 1-64 characters, unique within the batch |
| Result matching rule | Always match by custom_id — results are NOT in request order |
| processing_status values | in_progress, canceling (only after a cancel), ended |
| request_counts fields | processing, succeeded, errored, canceled, expired |
| Four result types | succeeded, errored, canceled, expired |
| Billed result types | succeeded only — the other three are free |
| Results file | .jsonl at results_url, populated only once ended |
| Results retrieval window | 29 days from created_at (not ended_at) |
| Download recommendation | Stream results, don't bulk-download |
| Rejected batch params | stream: true, speed, fallbacks, max_tokens: 0 |
| Param validation timing | Asynchronous — errors surface only after the batch ends |
| Pre-submission check | Dry-run one request against the synchronous Messages API |
| Prompt caching tip | Use the 1-hour cache TTL for batches (they often exceed 5 minutes) |
| Server tools in a batch | Run their full agentic loop inside the batch worker |
| Client tool / turn continuation in a batch | NOT possible mid-request — pause_turn requires a new follow-up request |
| Blocking workflows (pre-merge checks) | Synchronous API |
| Latency-tolerant workflows (overnight reports) | Batch API |
| Fixed deadline | Latest submission = deadline − 24 h − downstream time |
| Rolling SLA | Gap between submissions + 24 h + downstream ≤ SLA; 30 h SLA → every 4 h in the guide's example (6 h at most with nothing downstream) |
| SLA of 24 h or less | Cannot be guaranteed on batch at any frequency → synchronous |
| Failure resubmission | Only the failed custom_ids: oversized → chunk with derived ids; transient or expired → unchanged; other invalid → fix first |
| Sample before volume | Representative sample, iterated synchronously; every batch round can cost up to 24 h |
Exam Traps
More wrong answers, and why each fails
| Tempting answer | Why it fails | Choose instead |
|---|---|---|
| Match results to requests by their line position in the results file | Results can come back in any order; this passes in small tests and misattributes in production | Key every result on custom_id |
Use each document's storage path or filename as its custom_id | Slashes and dots fall outside the permitted characters, and long paths exceed 64 | An id built from your own record key, such as doc-0042 |
Reuse the original custom_id on the retry | The two runs become indistinguishable when you read the results | A derived id: doc-0042-retry-1 or doc-0042-chunk-0 |
| Raise the token budget in the account-wide default to fix 50 failures | Right fix at the wrong scope: it changes every future job to solve a problem of fifty documents | Change only the resubmitted requests |
| Refine the prompt on the easy majority of the corpus | It scores well on the sample and fails on the formats left out of it | A sample spanning every format and awkward case |
| Pick the sample at random from a skewed corpus | Random draws reproduce the skew: five from a mostly clean set usually contain none of the hard cases | Choose the sample deliberately |
| Refine only on the hardest documents | Better than the easy majority, but a prompt tuned only on hard cases can regress on the common ones | Mix both |
| Iterate the sample itself through the batch API | Each round can take up to 24 hours | Iterate on the synchronous API; batch the volume |
How This Is Tested
| Stem signal | Answer | Wrong-answer pattern beside it |
|---|---|---|
| A manager wants both a blocking and an overnight workflow moved to batch for the 50% | Batch only the non-blocking one | Status polling; a timeout fallback to real time; keeping both synchronous over "ordering" |
| A 30-hour SLA with 24-hour batch processing: how often do you submit? | Every 4 hours: gap + 24 h + downstream ≤ 30 h | "30 hours ahead"; once a day; whatever the typical completion time allows |
| A report due at a fixed time: when is the latest safe submission? | The deadline minus 24 hours (minus any downstream step) | The typical sub-hour completion time; the SLA figure used as a lead time |
| A guarantee of 24 hours or less | The synchronous API | Batch submitted more often |
| 120 of 5,000 documents failed for exceeding the context limit | Resubmit only those, chunked, identified by custom_id | Rerun the whole batch; retry unchanged; drop them because errored requests are free |
| How do you correlate responses with requests? | custom_id | Position in the results file |
| A batched job must call your own tool and keep reasoning on the result | The synchronous API | Define the tool in the batch request; split into two batches with lookups in between |
| How do you keep resubmission costs down on a 50,000-document run? | Refine the prompt on a representative sample first | Submit and fix the failures afterwards |
Official sample question 11, option by option
The stem: "Currently, real-time Claude calls power two workflows: (1) a blocking pre-merge check that must complete before developers can merge, and (2) a technical debt report generated overnight for review the next morning. Your manager proposes switching both to the Message Batches API for its 50% cost savings. How should you evaluate this proposal?"
| Option | Verdict | The official explanation |
|---|---|---|
| A. "Use batch processing for the technical debt reports only; keep real-time calls for pre-merge checks." | Correct | Batch "has processing times up to 24 hours with no guaranteed latency SLA. This makes it unsuitable for blocking pre-merge checks where developers wait for results, but ideal for overnight batch jobs like technical debt reports." |
| B. "Switch both workflows to batch processing with status polling to check for completion." | Wrong | "relying on "often faster" completion isn't acceptable for blocking workflows." Polling does not change the window it is polling against. |
| C. "Keep real-time calls for both workflows to avoid batch result ordering issues." | Wrong | It "reflects a misconception—batch results can be correlated using custom_id fields." |
| D. "Switch both to batch processing with a timeout fallback to real-time if batches take too long." | Wrong | It "adds unnecessary complexity when the simpler solution is matching each API to its appropriate use case." The fallback pays for both paths and adds a failure mode. |
The rule the sample rewards generalises: match each workflow to the API its latency requirement demands, and do not build machinery to make the wrong choice survivable.
Practice Scenario
Your extraction of each day's 2,000 invoices moved to the Message Batches API and usually returns within 40 minutes. The invoices are final at 18:00, and the ledger load runs at 06:00 the next morning. Last Tuesday the batch took 19 hours, so the load ran without them and finance reconciled 2,000 rows by hand. What's the most effective first step?
Practice Questions
Exam simulator
Question 1 of 14
Scenario · Structured Data Extraction
Your insurer extracts claim forms in two places. During phone calls, adjusters upload a form and wait for the fields before they can continue the call. Overnight, the whole day's forms are re-extracted for the fraud-analytics warehouse. To cut cost, a manager proposes moving everything to the Message Batches API. What should you recommend?
Sources
- Claude Certified Architect Foundations Exam Guide — Task Statement 4.5 — Anthropic
- Message Batches API — Anthropic
- Building with Claude API (Skilljar) — Anthropic
- Creating Message Batches (API Reference) — Anthropic
- Define tools — Anthropic
- Models overview — Anthropic