# 29.8 Realtime or batch (/building-ai-workers/model-selection-and-cost/realtime-or-batch)

---
type: Document
title: "29.8 Realtime or batch"
description: "What a batch costs and how its results are read, when to use realtime or a batch, and what the code does at 6:45 so the 7:10 report is never late."
status: stable
order: 329.08
ksor:
  owner: team:panaversity
  audience:
    - public
  approval:
    by: process:panaversity
    at: 2026-11-30T10:58:07Z
chapter: '29'
part: III
expert_status: manager
concepts: [ "29.8" ]
last_verified: '2026-11-30'

sources:
  - id: anthropic-pricing
    title: Pricing, Anthropic (verified 2026-11-30)
    resource: https://platform.claude.com/docs/en/about-claude/pricing
  - id: anthropic-batch-processing
    title: Batch processing (Anthropic, verified 2026-11-30)
    resource: https://platform.claude.com/docs/en/build-with-claude/batch-processing
generated:
  at: 2026-11-30T10:58:07Z
  by: esl-rewrite/1.2.0+ksor.1
trust_tier: unverified
build_id: sha256:d6ce3f28a2cf8e492a60bae1b426b7cc6466e35e83d70c3b9763db2c55009f4b
dirty: true
ksor_version: 0.0.60
---

**In everyday life.** Express mail costs more than standard mail. You pay for express only when someone is waiting. A shop that posts its paperwork at night uses standard mail, as long as it arrives before the office opens. If it might not, the shop keeps a courier ready for what is still on the way. In this section, express is a realtime request and standard mail is a batch. The office opening is the 7:10 run. The courier is the 6:45 rule.

**What you will learn.** You practice this in Lab 29, Task 3.

- What is a batch, and what does it cost?
- How do you read a batch's results?
- When do you use realtime, and when a batch?
- How does a two-request extraction run as a batch?
- What does the code do at 6:45?

**Why it matters.** Overnight work sent one request at a time pays full price for speed nobody needs. But a batch that ends after 7:10 misses the morning triage, and the triage reads no invoice that was not extracted.

**At work.** Tuesday, 11:00 a.m. You send the 16 extraction cases as one batch for [29.3](tiers.md)'s comparison. Then you plan the same move for the nightly extraction. Its binding constraint is the deadline. Every invoice's result must be ready before the 7:10 run ([29.4](the-binding-constraint.md)).

### What is a batch, and what does it cost?

**A batch is many Messages API requests sent together and answered later, at half the price.** Each request carries a **`custom_id`** that you choose. The service runs the requests when it has room. A batch costs 50% of the standard price, on input and output alike.[^anthropic-batch-processing] On Sonnet 5.5 that is $1 per million input tokens and $5 per million output tokens.[^anthropic-pricing] Section [24.10](../evaluating-ai-workers/how-todays-tools-realize-it.md) gave the size limit: 100,000 requests or 256 MB in one batch.

You pay with time instead. Most batches finish within an hour. Results come only when the whole batch has ended, or after 24 hours, when every request not yet processed **expires**. Results are kept for 29 days.[^anthropic-batch-processing] A batch's `processing_status` is `in_progress` until it is `ended`, and `canceling` while a cancel takes effect.[^anthropic-batch-processing]

Two more rules change how you build:[^anthropic-batch-processing]

- **Errors arrive last.** The API checks each request's parameters while the batch runs, and "returns validation errors when processing of the entire batch has ended". So send one request of the same shape on the Messages API first, and fix it before you send a thousand.
- **Some settings are not allowed.** A batch request takes no streaming, no fast mode `speed`, and no `fallbacks`.

### How do you read a batch's results?

**Match each result to its request by `custom_id`, then act on its result type.** The results file is JSON Lines, in any order. A `custom_id` is 1 to 64 letters, digits, hyphens or underscores, and it must be unique in the batch.[^anthropic-batch-processing] Each result has one of four types, and only one of them is billed:[^anthropic-batch-processing]

| Result type | What it means | Billed | What Brightline's code does |
| --- | --- | --- | --- |
| `succeeded` | The request ran | Yes | Send the answer through the three gates |
| `errored` | The request was invalid, or the server failed | No | An error that passes, such as an overload: run it in realtime. Any other: `needs_review`, never retried blindly |
| `canceled` | The batch was canceled before this request ran | No | Run it in realtime |
| `expired` | The 24 hours ran out first | No | Run it in realtime, because before 7:10 there is no time for a new batch |

Which errors pass, and how to retry them, is the subject of Chapter 30. Here the code needs one sorting only: passing, or not.

<!-- EDITOR: Chapter 30 is not on main yet. The pointer above stays as plain text with no link until its page for errors by class exists (spec, Boundaries). -->

### When do you use realtime, and when a batch?

**Realtime when someone waits, a batch when nobody does and the result is not needed within the hour.**

| Choose | When | At Brightline |
| --- | --- | --- |
| Realtime | A person, or a next step, is waiting for the answer | Ana's question in the portal |
| Batch | Nobody waits, and the result is needed hours later | The overnight extraction, the release suite ([24.6](../evaluating-ai-workers/metrics-you-can-defend.md)), the trials of 29.3 |

A batch changes the price and the timing, not the text the model reads. So it is checked by its deadline, not by the suite.

### How does a two-request extraction run as a batch?

**As two rounds, with one row per invoice.** A batch request is one call. The extraction's second request needs the model's `get_invoice` call from the first, and the tool result your code serves. So:

1. **Round 1, at 1:00 a.m.** Request 1 goes for every new invoice, with ids like `INV-8340-r1`.
2. **When round 1 has ended.** Your code runs `get_invoice` for each succeeded result, and sends round 2, request 2 for each, with ids like `INV-8340-r2`.

The portal keeps one row for each invoice: the batch id, the `custom_id`, the round, and the outcome. By 7:10 every row has exactly one outcome. It is accepted, `needs_review`, or run in realtime.

Caching still applies inside a batch, and the batch discount applies to its prices too.[^anthropic-pricing] But a hit inside a batch is "best-effort", typically between 30% and 98%.[^anthropic-batch-processing] The page recommends the one-hour cache, written by one request first. Round 2 waits for round 1 to end, so a five-minute entry is likely gone by then. Write the tools and rules once with `"ttl": "1h"`, with one request, then send round 1.

### What does the code do at 6:45?

**It reads each batch's status, cancels what has not ended, keeps what succeeded, and runs the rest in realtime.** The rule, in order:

1. Read each batch's `processing_status`.
2. A batch that has not ended is canceled. The code waits for it to reach `ended`. "Canceled batches end up with a status of `ended` and might contain partial results."[^anthropic-batch-processing] It keeps every succeeded result.
3. Each canceled or expired request runs in realtime. An invoice that finished round 1 sends only its request 2. An invoice that did not sends both. Neither batch request is billed.
4. An errored request whose error passes, such as an overload, also runs in realtime. Any other errored request goes to `needs_review`, with its error beside it for Ana.

The 25 minutes before 7:10 are for the realtime requests. Whether they are enough depends on how many requests are left on the day.

<!-- OPEN: recorded run. How many invoices arrive on a weekday, how long each batch round took, and how many requests ran in realtime after 6:45 come from recorded runs (spec, raised point 3f and appendix point 15). The batch line in 29.9 waits for the first 1:00 a.m. run, on Wednesday, May 12. -->

<!-- FIGURE 29.4: "1:00 a.m. to 7:10 a.m." A horizontal timeline from 1:00 a.m. (left) to 7:10 a.m. (right). At 1:00, a box "round 1 sent: request 1 for each new invoice, 1-hour cache written first". A bar runs right from it, labeled "round 1 in progress", and ends at a tick labeled "round 1 ended". From that tick, a box "round 2 sent: request 2 with each tool result", and a second bar labeled "round 2 in progress". At 6:45, a vertical dashed line labeled "6:45: read each batch's processing_status". From the line, a decision diamond "ended?" with two exits. Exit "yes": "keep succeeded results, send them through the three gates". Exit "no": "cancel, wait for ended, keep what succeeded". Below the diamond, three small boxes, each with an arrow to a box "realtime" on the right: "canceled", "expired" and "errored, passing (such as an overload)". A fourth small box "errored, any other" has an arrow down to a box "needs_review, for Ana". At 7:10, a solid vertical line labeled "7:10: the morning triage reads only what was extracted". Under the timeline: "One row per invoice: batch id, custom_id, round, outcome." -->

*Figure 29.4. Two rounds from 1:00 a.m. At 6:45 the code ends what has not ended. Nothing waits past 7:10.*

**The operating rule:** send work nobody waits for as a batch, and match every result by its `custom_id`. At 6:45, run whatever is left in realtime.

[^anthropic-batch-processing]: Batch processing, Anthropic, read November 30, 2026.
[^anthropic-pricing]: Pricing, Anthropic, read November 30, 2026.
