Your nightly eval suite does not need an answer in two seconds. So why are you paying the two-second price?
If a job can wait an hour, the Claude Message Batches API charges 50 percent of the standard price for it. Most teams know this exists. Fewer have moved their evals, backfills and bulk classification jobs over, usually because of a handful of small traps. This post covers the setup, the traps, and working Python.
Every number below comes from the official batch processing docs and prompt caching docs, checked on the day of writing.
The analogy: courier vs. freight
A normal Messages API call is a courier. One parcel, door to door, right now. You pay for the speed.
A batch is freight. You load a container with thousands of parcels, hand it over, and pick everything up later. Each parcel costs less because the carrier can schedule the trip when it suits them.
Nobody ships a warehouse by courier. But that is what a for loop over 20,000 eval prompts does.
The facts that matter
From the docs:
- Price: "All usage is charged at 50 percent of the standard API prices." For example, the batch price listed for Claude Sonnet 5.5 is $1 per million input tokens and $5 per million output tokens.
- Speed: most batches finish in less than 1 hour. The hard limit is 24 hours. After that, unprocessed requests expire.
- Size: one batch holds up to 100,000 requests or 256 MB, whichever comes first.
- Results: available for 29 days after the batch was created.
- Models: all active models support it.
- Features: vision, tool use, system messages, multi-turn conversations and extended thinking all work.
And you are not billed for requests that errored, were canceled, or expired.
Step 1: build the batch
Each request needs a custom_id and a params object. The params are the same as a normal Messages call.
import anthropic from anthropic.types.message_create_params import MessageCreateParamsNonStreaming from anthropic.types.messages.batch_create_params import Request client = anthropic.Anthropic() RUBRIC = open("rubric.md").read() # long, shared by every request def make_request(case_id: str, answer: str) -> Request: return Request( custom_id=case_id, params=MessageCreateParamsNonStreaming( model="claude-sonnet-5-5", max_tokens=512, system=[ { "type": "text", "text": RUBRIC, "cache_control": {"type": "ephemeral", "ttl": "1h"}, } ], messages=[ {"role": "user", "content": f"Grade this answer:\n\n{answer}"} ], ), ) cases = load_cases() # your own function: returns [(case_id, answer), ...] batch = client.messages.batches.create( requests=[make_request(cid, ans) for cid, ans in cases] ) print(batch.id, batch.processing_status) # msgbatch_..., in_progress The custom_id must be 1 to 64 characters, using only letters, digits, hyphens and underscores. It must be unique inside the batch. Use something you can join on later, like eval-2026-12-06-case-0412.
Step 2: wait
A batch starts as in_progress and becomes ended when every request is done.
import time while True: batch = client.messages.batches.retrieve(batch.id) if batch.processing_status == "ended": break time.sleep(60) print(batch.request_counts) # processing, succeeded, errored, canceled, expired In CI you do not need to hold a runner open for this. Save the batch id, exit, and let a later job collect the results. They stay available for 29 days.
Step 3: read results by id, not by position
Results come back as a JSONL file. The SDK streams it for you, so you never load the whole thing in memory.
retry_ids, grades = [], {} for result in client.messages.batches.results(batch.id): outcome = result.result match outcome.type: case "succeeded": grades[result.custom_id] = outcome.message.content[0].text case "errored": if outcome.error.error.type == "invalid_request_error": print(f"fix the request body: {result.custom_id}") else: retry_ids.append(result.custom_id) # server error: safe to resend case "expired": retry_ids.append(result.custom_id) That error split comes from the docs: an invalid_request_error means the request body must be fixed before resending, while other errors can be retried directly.
The five traps
1. Results are not in order
The docs are blunt: "Batch results can be returned in any order, and might not match the ordering of requests when the batch was created." If you zip() results with your input list, your eval scores will be attached to the wrong cases, and nothing will crash to warn you. Always join on custom_id.
2. Validation happens late
The API validates each request's params asynchronously and reports validation errors only after the whole batch has ended. One typo in a field name can mean an hour of waiting followed by 20,000 errors.
The fix the docs recommend: send one request of the same shape through the normal Messages API first. If it passes, submit the batch.
probe = make_request(*cases[0]) client.messages.create(**probe["params"]) # fails fast if the shape is wrong 3. Some parameters are rejected
These return a validation error inside a batch:
-
stream: true, because results come back as a file -
speed(fast mode), because it tunes synchronous latency -
fallbacks(server-side fallback) -
max_tokens: 0(cache pre-warming). Every batched request needsmax_tokensof at least 1.
If your shared request builder sets stream=True for the interactive path, strip it for the batch path.
4. The 5-minute cache is too short for batches
Prompt caching and batching stack. The caching docs say the cache multipliers "stack with other pricing modifiers such as the Batch API discount". For an eval suite where every request shares one long rubric, that is the best deal on the price list.
But the default cache lifetime is 5 minutes, and a batch can take longer than that. The batch docs suggest the 1-hour cache duration for batches with shared context. That is why the code above uses:
"cache_control": {"type": "ephemeral", "ttl": "1h"} Know the cost before you flip it on. A 5-minute cache write costs 1.25 times the base input price. A 1-hour write costs 2 times. Cache reads cost 0.1 times the base input price, and 0.05 times on Claude Opus 5.5 and Claude Sonnet 5.5. So the 1-hour cache pays off only when the shared prefix is read many times, which is exactly the eval case.
Also set expectations. Batch requests run concurrently, so cache hits are "best-effort". The docs report hit rates "ranging from 30 percent to 98 percent, depending on their traffic patterns". To land near the top of that range:
- put identical
cache_controlblocks in every request - keep the shared content at the start and byte-for-byte the same
- put the part that changes (the answer being graded) last
Then check usage.cache_read_input_tokens on a few results to see what you actually got.
5. A batch can end with holes in it
ended does not mean "all succeeded". Under heavy demand, processing can slow down and more requests may expire at the 24-hour mark. Your pipeline needs a retry step. The retry_ids list from Step 3 is the input for a second, smaller batch.
Two smaller notes from the docs while you are here. Batches may go slightly over your workspace spend limit because of concurrent processing. And if the upload is over 256 MB you can get a 413 request_too_large error, so split very large datasets into several batches.
When not to batch
Freight is the wrong choice when someone is waiting at the door.
- User-facing requests. "Most finish in under an hour" is not a latency guarantee.
- Agent loops. Each step depends on the last one, so there is nothing to send in parallel.
- Tight deadlines. If a result is useless after 30 minutes, the 24-hour worst case is a real risk.
Good fits are the opposite: nightly evals, LLM-as-judge grading, bulk classification, embeddings prep, summarizing a document backlog, and synthetic data generation.
A simple migration plan
- Find every loop in your codebase that calls the Messages API and where no human is waiting for the result.
- Wrap the request builder so it returns
paramsinstead of calling the API. - Probe one request through the normal API.
- Submit the batch, store the batch id, exit.
- Collect by
custom_id, retry the errored and expired ones, and comparerequest_countsto your input size.
Takeaways
- Batch pricing is 50 percent of standard. Most batches finish in under 1 hour, with a 24-hour limit.
- Limits: 100,000 requests or 256 MB per batch. Results last 29 days.
- Always match results by
custom_id. Order is not guaranteed. - Test one request with the normal API first, because batch validation errors arrive only at the end.
- Use
"ttl": "1h"caching for shared prefixes, and measure your real hit rate. -
endedis notsucceeded. Build the retry step on day one.
Sources: Batch processing and Prompt caching in the Claude API docs.