~/academy $ claude learn batch-processing
Batch processing at half price
How to use the Claude Message Batches API to process large jobs asynchronously at a 50 percent discount, with limits and Python code checked today. 7 min
$ Read
What the Batches API is for
The Message Batches API takes many ordinary Messages requests at once and processes them in the background. You pay 50 percent less on both input and output. Checked 18 November 2026: Opus 5.5 is $2 input and $10 output per million tokens in a batch, Sonnet 5.5 $1 and $5, Haiku 5.5 $0.05 and $0.25 (for prompts up to 100,000 tokens).
Most batches finish in under an hour. Results are ready when every request is done or after 24 hours, whichever comes first, and any request not processed within 24 hours expires. Results stay downloadable for 29 days.
A batch can hold up to 100,000 requests or 256 MB, whichever comes first. Almost anything works inside one: vision, tools including server tools, system prompts, multi-turn conversations and thinking. Not allowed: stream: true, fast mode (speed), server-side fallbacks and max_tokens of 0.
Lesson notes: Batch processing at half price
Everything in this lesson as text, for revision or to read without the interactive steps. By the end you will be able to: You submit a batch, poll it, collect results by custom ID and know when a batch is the right tool.
Step 1 of 6 · Read
What the Batches API is for
The Message Batches API takes many ordinary Messages requests at once and processes them in the background. You pay 50 percent less on both input and output. Checked 18 November 2026: Opus 5.5 is $2 input and $10 output per million tokens in a batch, Sonnet 5.5 $1 and $5, Haiku 5.5 $0.05 and $0.25 (for prompts up to 100,000 tokens).
Most batches finish in under an hour. Results are ready when every request is done or after 24 hours, whichever comes first, and any request not processed within 24 hours expires. Results stay downloadable for 29 days.
A batch can hold up to 100,000 requests or 256 MB, whichever comes first. Almost anything works inside one: vision, tools including server tools, system prompts, multi-turn conversations and thinking. Not allowed:
stream: true, fast mode (speed), server-sidefallbacksandmax_tokensof 0.Step 2 of 6 · Read
Create a batch
Each request has a
custom_id(1 to 64 letters, numbers, hyphens or underscores) and the sameparamsyou would send tomessages.create. The API checks each request's params only after the batch has run, so send one example through the normal Messages API first to catch mistakes.Tag 3,000 reviews overnight import anthropic from anthropic.types.message_create_params import MessageCreateParamsNonStreaming from anthropic.types.messages.batch_create_params import Request client = anthropic.Anthropic() batch = client.messages.batches.create( requests=[ Request( custom_id=f"review-{review['id']}", params=MessageCreateParamsNonStreaming( model="claude-haiku-5-5", max_tokens=256, system="Label the review as positive, neutral or negative. Reply with the label only.", messages=[{"role": "user", "content": review["text"]}], ), ) for review in reviews ] ) print(batch.id, batch.processing_status) # starts as in_progressStep 3 of 6 · Read
Poll, then collect
processing_statusmoves fromin_progresstoended. You can watch it in the Console or poll withretrieve. Then stream the results file. Results can come back in any order, so always match them to your data bycustom_id, never by position.Each result is
succeeded,errored,canceledorexpired. You are not billed for errored, cancelled or expired requests. Aninvalid_request_errormeans fix the request before resending; other errors can be retried as they are.Wait and read results import time while client.messages.batches.retrieve(batch.id).processing_status != "ended": time.sleep(60) labels = {} for result in client.messages.batches.results(batch.id): if result.result.type == "succeeded": msg = result.result.message labels[result.custom_id] = next(b.text for b in msg.content if b.type == "text") else: print("Needs attention:", result.custom_id, result.result.type)Step 4 of 6 · Sort
Batch it or call it live?
Decide which jobs suit the Batches API.
- Tagging 40,000 product reviews overnight
- Replying to a customer in a chat window
- Re-scoring last month's support transcripts for an evaluation
- A fraud check before a payment is accepted
- Writing descriptions for 5,000 catalogue items due next week
- A coding assistant that streams its answer
Show the answers
- Tagging 40,000 product reviews overnight: Batch it. Large, nobody waiting, and half the price.
- Replying to a customer in a chat window: Call it live. Someone is waiting, and batches can take up to 24 hours.
- Re-scoring last month's support transcripts for an evaluation: Batch it. Large-scale evaluations are a listed batch use case.
- A fraud check before a payment is accepted: Call it live. It blocks a live transaction, so it cannot wait.
- Writing descriptions for 5,000 catalogue items due next week: Batch it. Plenty of time and lots of identical-shaped requests.
- A coding assistant that streams its answer: Call it live. Streaming is not allowed inside a batch.
Step 5 of 6 · Quiz
Check your understanding
Which of these will a batch request reject?
- A request that uses the web search tool
- A request with `stream: true`
- A request with an image
- A multi-turn conversation
Show the answer
A request with `stream: true` Batch results come back as a single file, not a stream, so streaming is a validation error.
Step 6 of 6 · Quiz
Check your understanding
Every request in your batch shares a 30,000-token system prompt. How should you cache it?
- Do not bother, caching never works with batches.
- Use the default 5-minute cache.
- Use the 1-hour cache, `{"type": "ephemeral", "ttl": "1h"}`, and treat hits as a bonus.
Show the answer
Use the 1-hour cache, `{"type": "ephemeral", "ttl": "1h"}`, and treat hits as a bonus. The docs suggest the 1-hour duration for batches with shared context. Hits are best effort because requests run concurrently and in any order.