The Message Batches API, Realtime vs. Batch & Third-Party Vendors
CoreApply extended thinking, prompt caching, batch processing, and vendor choice · Difficulty 2/5
Explanation
The Message Batches API
For large, latency-tolerant workloads, submit many requests as a single asynchronous batch. Anthropic processes the batch within a 24-hour window at a substantial per-token discount (roughly half the standard rate). This is the correct choice for overnight bulk jobs where cost matters more than immediacy -- not a matter of running the same synchronous calls faster in parallel.
The Exact Mechanics and Limits
A single batch call accepts up to 100,000 requests or 256 MB, whichever limit is hit first. Submitting the batch returns a batch_id immediately -- the batch itself has not been processed yet, only accepted. Your application then polls using that ID until the batch reports completion, at which point you download the results.
batch = client.messages.batches.create(requests=[
{"custom_id": "ticket-001", "params": {"model": "claude-sonnet-4-5", "max_tokens": 256,
"messages": [{"role": "user", "content": ticket_1}]}},
{"custom_id": "ticket-002", "params": {"model": "claude-sonnet-4-5", "max_tokens": 256,
"messages": [{"role": "user", "content": ticket_2}]}},
# ... up to 100,000 requests, or 256 MB total, whichever comes first
])
print(batch.id) # poll client.messages.batches.retrieve(batch.id) until processing endsThe order results come back in has no relationship to the order you submitted them. That's not a bug you're working around -- it's how the API is documented to behave. Because of that, every request in the batch needs its own custom_id, since that's the one dependable way to tie a given result back to the request that generated it:
results_by_id = {}
for result in client.messages.batches.results(batch.id):
results_by_id[result.custom_id] = result # never assume result order == submission orderAny code that pairs results with the original request list purely by index, assuming the two lists line up, will silently mismatch inputs and outputs the instant the API returns results in a different order than submitted -- which it's entitled to do on any given batch.
Realtime vs. Batch -- The Decision
| Need | Use |
|---|---|
| Interactive, user is waiting | Messages API (realtime), often streaming |
| High volume, results tolerable within 24h, cost-sensitive | Message Batches API |
The decision follows directly from the requirement-extraction questions (latency sensitivity, volume, cost ceiling): a requirement that names an overnight or next-day turnaround and calls out cost as the primary concern is describing a batch workload, full stop.
Third-Party Vendors
The same Claude models are available through Amazon Bedrock and Google Vertex AI, in addition to Anthropic's direct API. The message format is largely consistent across all three; what differs is authentication, endpoint/region, and model-ID naming. Choose a vendor for reasons like existing cloud footprint, data-residency requirements, and procurement constraints -- not because the underlying model behaves differently.
Common exam traps
- "Batch is just parallel realtime calls." It is a distinct asynchronous API with its own 24-hour SLA and a real per-token discount -- firing many synchronous requests concurrently is not the same thing and does not capture the discount.
- Assuming batch results preserve submission order -- they don't. A
custom_idon each request is required to match results back to inputs; positional zipping breaks silently. - Forgetting the batch is capped by whichever limit is hit first -- 100,000 requests or 256 MB -- not just a flat request count.
- Assuming vendor choice changes model behavior -- Bedrock and Vertex AI host the same Claude models; the differences are integration mechanics (auth, region, model-ID naming), not model quality.
- Picking realtime for a workload whose actual requirement (cost-sensitive, next-morning turnaround, high volume) squarely describes batch.
Key Takeaways
- The Message Batches API processes many requests asynchronously within 24 hours at a substantial per-token discount
- A batch accepts up to 100,000 requests or 256 MB per call, whichever limit is hit first; submitting returns a batch_id you poll for completion
- The order batch results arrive in has no fixed relationship to submission order -- rely on the custom_id field on each request to tie results back to their inputs
- Batch is a distinct asynchronous API, not parallelized synchronous calls -- parallel realtime calls don't capture the discount
- Interactive, user-waiting work uses the realtime Messages API; high-volume/cost-sensitive/24h-tolerant work uses the Batches API
- Amazon Bedrock and Google Vertex AI host the same Claude models as the direct API; differences are auth, endpoint/region, and model-ID naming
- Vendor choice is driven by cloud footprint, data residency, and procurement -- not by model behavior differences
Glossary Terms
The recurring architectural tension where an integration decision that improves accuracy (e.g., reranking, retrieving more chunks) typically adds latency and cost, and vice versa. The architect's job is not to eliminate the tradeoff but to make it explicit and justify the chosen configuration against whichever constraint the stated requirement names as dominant. Prompt caching a stable repeated context is the rare exception that improves cost and latency with no accuracy loss.
An asynchronous Claude API for processing multiple requests in a batch with 50% cost savings versus synchronous requests. Processing takes up to 24 hours with no guaranteed latency SLA. Does not support iterative tool use, streaming, or prompt caching. Best for scheduled, non-blocking analysis.
The availability of Claude models through Amazon Bedrock and Google Vertex AI in addition to Anthropic's direct API, with a largely consistent message format across all three. Differences are limited to authentication, endpoint/region, and model-ID naming -- not model behavior. Vendor choice is driven by existing cloud footprint, data-residency requirements, and procurement constraints.
Related Concepts
Extended Thinking and Prompt Caching
Extended thinking produces internal reasoning before the answer; thinking tokens are billed as output tokens
From Business Requirements to Functional & Infrastructure Requirements
Business requirements translate into functional requirements (what the system does) and infrastructure requirements (latency, throughput, residency, availability, budget)