← Home · Tutorial 18 · Production engineering

The Batch API as a cost lever

Same model, half the price, if the answer can wait: how to decide what goes in a batch, and how to run one.

Last reviewed 26 November 2026 · Written with AI assistance and reviewed by me

Where this comes from: Anthropic's Batch processing guide and pricing page, both checked on 26 November 2026. The examples and numbers in the scenarios are my own, and every snippet that does not call the API was run to produce the output shown.
Who this is for: anyone paying for model calls that nobody is waiting on. You will learn how the Message Batches API halves the price, what you give up for it, how to decide which work can wait, and why a live retry loop doesn't fit a batch.

1Who is waiting for the answer?

The question that comes before choosing a model.

Most cost advice starts with "use a smaller model". There is an earlier question: who is waiting for this answer? If a person is watching a screen, the call has to be live. If the answer is read tomorrow morning, it can wait, and waiting is cheaper.

Anthropic's Message Batches API runs the same models at 50% of the normal price. The trade is time: you send a batch of requests and collect the results later.

2Live versus batch

What you gain and what you give up.

Live callBatch
PriceStandard50% of standard, input and output
When the answer arrivesSecondsMost batches within an hour; at most 24 hours
Order of answersOne answer per callAny order; match them by custom_id
SizeOne requestUp to 100,000 requests or 256 MB per batch
Good forAnything a person is waiting onOvernight extraction, summaries, evaluations, bulk tagging
The test: if nobody notices whether the answer comes in two seconds or two hours, it belongs in a batch.

3What it saves

A nightly job, priced live and in a batch.

Take an assistant for a small service business. Every night, one job reads the day's client chats and pulls out preferences: preferred times, products, things to avoid. Nobody is waiting for it. With Claude Haiku 5.5 and prompts under 100K tokens, the live price is $0.10 in and $0.50 out per million tokens, and the batch price is $0.05 and $0.25.

Python
# Claude Haiku 5.5, prompts up to 100K tokens, USD per million tokens (checked 26 Nov 2026)
LIVE  = {"in": 0.10, "out": 0.50}
BATCH = {"in": 0.05, "out": 0.25}

chats_per_night = 1500
tokens_in, tokens_out = 1200, 150          # per chat: transcript + instructions in, extracted facts out

def nightly_cost(price):
    return chats_per_night * (tokens_in * price["in"] + tokens_out * price["out"]) / 1_000_000

live, batch = nightly_cost(LIVE), nightly_cost(BATCH)
print(f"live:  ${live:.3f} a night, ${live * 30:.2f} a month")
print(f"batch: ${batch:.3f} a night, ${batch * 30:.2f} a month")
print(f"saved: {100 * (1 - batch / live):.0f}%")
Output (run to check)
live:  $0.292 a night, $8.77 a month
batch: $0.146 a night, $4.39 a month
saved: 50%

The amounts are small here because the model is small. The 50% holds at any scale, so the same choice matters more as volume or model size grows.

Check the price tier. Haiku 5.5 charges more for prompts over 100,000 tokens, in batch and live alike. Keep nightly prompts short and the saving stays at the lower rate.

4Submit, poll, collect, match

The four steps, and handling each result.

A batch, start to finish
Submitmany requests, each with a custom_id
→
Polluntil processing_status is "ended"
→
Collectresults in any order
→
Matchby custom_id, then handle each type

The shape below follows Anthropic's guide. It is not run here because it needs an API key, and the model id is a placeholder: take the current one from the docs.

Python: shape from the docs, not run here
import time, anthropic
client = anthropic.Anthropic()

batch = client.messages.batches.create(requests=[
    {"custom_id": "client-17-2026-11-26",            # 1 to 64 letters, digits, - or _
     "params": {"model": MODEL_ID_FROM_THE_DOCS, "max_tokens": 300,
                "messages": [{"role": "user", "content": prompt_for("client-17")}]}},
    # ... one entry per client
])

while client.messages.batches.retrieve(batch.id).processing_status != "ended":
    time.sleep(60)                                    # polling is safe to repeat

for result in client.messages.batches.results(batch.id):
    handle(result.custom_id, result.result)           # succeeded, errored, canceled or expired

Results come back as one line per request, and not in the order you sent them. Matching by position would attach one client's preferences to another. Here is the handling, with made-up results:

Python
# what comes back from a batch: one line per request, in ANY order
results = [
    {"custom_id": "client-31-2026-11-26", "type": "succeeded", "text": "prefers morning slots"},
    {"custom_id": "client-17-2026-11-26", "type": "errored",   "error": "invalid_request_error"},
    {"custom_id": "client-22-2026-11-26", "type": "expired"},
]
sent = ["client-17-2026-11-26", "client-22-2026-11-26", "client-31-2026-11-26"]

by_id = {r["custom_id"]: r for r in results}       # match by custom_id, never by position
fix_first, retry_tonight = [], []
for cid in sent:
    r = by_id[cid]
    if r["type"] == "succeeded":
        print(cid, "-> save:", r["text"])
    elif r["type"] == "errored" and r["error"] == "invalid_request_error":
        fix_first.append(cid)                      # the request itself is wrong: fix before resending
    else:
        retry_tonight.append(cid)                  # server error or expired: resend in the next batch
print("fix first:", fix_first)
print("retry tonight:", retry_tonight)
Output (run to check)
client-31-2026-11-26 -> save: prefers morning slots
fix first: ['client-17-2026-11-26']
retry tonight: ['client-22-2026-11-26']

Errored, canceled and expired requests are not billed. An error caused by the request itself needs fixing before you resend it. A server error or an expired request can simply go into the next batch. Results stay available for 29 days.

5Who can't wait

A plain rule for what stays live.

Some answers can't wait for tonight. A client who books for this afternoon and mentions an allergy this morning needs that fact on file before the appointment. A clear rule handles it: anyone with a booking in the next 24 hours gets a live call, and everyone else waits for the batch.

Python
from datetime import datetime, timedelta

now = datetime(2026, 11, 26, 9, 0)
clients = [{"id": "client-17", "next_booking": datetime(2026, 11, 26, 15, 0)},   # this afternoon
           {"id": "client-22", "next_booking": datetime(2026, 12, 4, 11, 0)},    # next week
           {"id": "client-31", "next_booking": None}]                             # nothing booked

def route(client):
    soon = client["next_booking"] and client["next_booking"] - now <= timedelta(hours=24)
    return "live call now" if soon else "tonight's batch"

for c in clients:
    print(c["id"], "->", route(c))
Output (run to check)
client-17 -> live call now
client-22 -> tonight's batch
client-31 -> tonight's batch

The rule is plain code, so it is cheap to run, gives the same answer every time, and is easy to test. You pay the live price only where waiting would cost more than the saving.

6Retry loops don't fit a batch

Move the checking into your own code.

Some extraction libraries fix their own mistakes in a loop: they call the model, validate the answer, and call it again with the error until the output passes. That works live. In a batch, every round trip is another batch, so one retry can mean another night.

Where the checking goes
Live loopmodel, check, model again
→
Batchone answer per request
→
Your code checks itpass: save it; fail: reject, retry next night

So the checking moves into your own code, which runs on each result as it is collected. A useful check for preferences: every extracted fact must quote the client word for word, and the quote must come from the client's own messages, not the assistant's. The reason for that second part is covered in Securing AI agents.

7When not to batch

Waiting users, deadlines, streaming.

  • Anything a person is waiting on stays live. A chat reply that takes an hour is a broken product.
  • Short deadlines stay live. A batch can take up to 24 hours, and requests still unprocessed then expire.
  • Streaming is not supported inside a batch, so anything that shows text as it is written stays live.
  • Test the request shape live first. Batch requests are validated after you submit them, so a malformed request surfaces later as an error, not straight away.

8Check yourself

Short questions, a try-it and one line to remember.

What question decides whether a call can be batched?

Who is waiting for the answer. If nobody notices a delay of hours, it can be batched.

How much cheaper is a batch?

50% of the standard price, on both input and output tokens.

Why match results by custom_id and not by position?

Results can arrive in any order, so position would attach answers to the wrong requests.

Which batch results are not billed?

Errored, canceled and expired requests.

Why doesn't a live retry loop fit a batch?

Each retry would need another batch, which can mean another day. Checking moves into your own code instead.

Try it: in the cost snippet, set tokens_in to 101000 and use the over-100K rates ($0.25 in, $1.25 out for batch). See how much the nightly cost jumps. Then add a fourth client to the routing snippet with a booking exactly 24 hours away and check which path it takes.
One line to remember: "The cheapest call is often the same model, asked to wait."
Sources: Anthropic Batch processing and pricing (Claude Haiku 5.5 rates, checked 26 November 2026). Prices and limits change, so check the current docs. Independent notes, not affiliated with or endorsed by any company or course named here. Examples and wording are my own.