Skip to content

Plan work around the batch window

Decide which workloads belong on the Message Batches API, compute a submission schedule that meets an SLA despite its processing window, and resubmit only the failed requests by custom_id.

Scenario

Scenario: Claude Code for Continuous Integration. Finance asks the platform team to cut the Claude bill. Someone notices the Message Batches API charges half price and proposes moving everything onto it: the nightly test-generation run, the weekly dependency audit, and the review that runs on every pull request before it can merge.

Two of those three are a good idea. The third would leave developers waiting on a pull request for an unknown number of hours.

Explanation

What the Batches API gives you, according to its docs:

  • Half the price: all batch usage is charged at 50% of standard API prices.
  • No promise on timing: most batches finish within an hour, but processing can take up to 24 hours. Requests not processed by then expire. Processing can slow down with demand and your volume.
  • Results in any order: each request carries a custom_id (1 to 64 letters, digits, hyphens or underscores), and you match results to requests by it, never by position.
  • Per-request outcomes: each result is succeeded, errored, canceled or expired. You aren't billed for the last three, and one failed request doesn't affect the others.
  • Fixed once sent: a submitted batch can't be changed. To change it, cancel it and submit a new one.

One design limit. The docs list tool use as supported in batches, including server tools such as web search, which run on Anthropic's side. Your own tools (client tools) are different: Claude stops with tool_use, and your code must run the tool and send back a tool_result in a new request. Inside a batch nobody runs your tool in between, so a request ends where Claude asks for one. The exam guide puts it as "no multi-turn tool calling within a single request". Give each request what it needs up front.

Decision rule: is someone waiting?

  • Blocking work (a pre-merge check, a user waiting on screen) goes to the synchronous Messages API.
  • Latency-tolerant work (nightly test generation, weekly audits, overnight reports) goes to batch.

Scheduling for an SLA. Plan for the worst case, not the typical hour. A document that arrives just after a submission waits a full interval, then up to 24 hours of processing, then your own post-processing:

interval + 24 h + post-processing ≤ SLA

Failures. Read each result's type and resubmit only the failed requests, found by custom_id. Expired and server-error requests can go again as they are; a request rejected as invalid must be changed first (for example, split a document too long for the context window). Before a large first run, test the prompt on a sample: the docs suggest a dry run of the request shape on the Messages API, and fixing the prompt on a few cases is cheaper than resubmitting thousands.

Worked example

A data team must deliver extracted fields from scanned claims within 48 hours of arrival. After a batch ends, validation and loading take up to 6 hours.

First plan: "Batches usually finish in an hour, so one batch a day is plenty." A claim arriving just after the daily submission waits 24 hours, may spend 24 in processing, then 6 in loading: 54 hours. The SLA is broken on a bad day.

Worked plan:

interval + 24 h (worst-case processing) + 6 h (loading) <= 48 h
interval <= 18 h

Submitting every 18 hours meets the SLA in the worst case; the team picks every 12 hours to leave margin for a slow load. Each request's custom_id is the claim's ID, so results are written to the right record whatever order they return in.