Message Batches API
Batch processing allows submitting multiple requests together for asynchronous processing instead of processing requests one at a time with immediate responses.
Definition · At a glance · How it works
Definition
Batch processing allows you to submit multiple requests together for asynchronous processing, instead of processing requests one at a time with immediate responses. Batches are scoped to a Workspace in the Claude Console. The Message Batches API supports nearly all features available in the Messages API, including most beta features. Because each request in the batch is processed independently, different types of requests can be mixed within a single batch.
At a glance
The processing_status field of a batch starts as in_progress, then updates to ended once all the requests in the batch have finished processing and results are ready.
How it works
A Message Batch is limited to either 100,000 Message requests or 256 MB in size, whichever is reached first. Batches might take up to 24 hours for processing, but many complete sooner. Actual processing time depends on the size of the batch, current demand, and request volume.
Batches expire if processing does not complete within 24 hours. When a batch is first created, the response has a processing status of in_progress. The state of a batch can be monitored by visiting the Console or using the retrieval endpoint.
To access the results of a Message Batch, make a request to the results_url field in the response. Once batch processing has ended, each Messages request in the batch has a result. There are 4 result types.
Each request has a result field indicating whether it succeeded, errored, was canceled, or expired. The results are in .jsonl format, where each line is a valid JSON object representing the result of a single request in the Message Batch. Batch results use the API version of the request that created the batch.
Batch results are available for 29 days after creation. After that, the batch can still be viewed, but its results are no longer available for download. Rate limits apply to both Batches API HTTP requests and the number of requests within a batch waiting to be processed.
Usage of the Batches API does not affect rate limits in the Messages API. A small number of parameters (stream, speed, fallbacks, and max_tokens: 0) are not supported in batch requests. Once a batch has been submitted, it cannot be modified.
Canceled batches end up with a status of ended and may contain partial results for requests that were processed before cancellation. The failure of one request in a batch does not affect the processing of other requests.
Example
In the documented example, 2 separate requests are batched together for asynchronous processing. In that example, each request has a unique custom_id and contains the standard parameters used for a Messages API call. When a batch is first created, the response has a processing status of in_progress.
Sources
This page is written from the official sources below. Open them to check the original text.
- Official documentationhttps://platform.claude.com/docs/en/build-with-claude/batch-processingFetched
Verified ·
This page is written by AI from the official sources above and checked automatically. This site has not tested it. Found a mistake? Tell us.
