Study FAQ
How do I reconcile and retry Claude Message Batches safely?
Also asked as 2
- How do I match Claude batch results to requests when the output is out of order?
- What should I do with succeeded, errored, canceled, and expired Claude batch records?
Answer
Give each Messages request a stable custom_id unique within its batch. Record the mapping to the input and source version, submit the validated records, and poll the batch ID until processing_status is ended. Retrieve the JSONL results and join each record on custom_id, because output order can differ from input order.
Review every result type before writing downstream.
succeededsupplies a Messages response. Check its stop reason, shape, and meaning before committing the result.erroredrequires checking the error. Fix an invalid request before resubmitting it, and use a bounded retry for eligible transient failures.canceledandexpiredrequire an explicit requeue decision. A canceled batch can still contain records that completed before cancellation.
Check for missing or unexpected IDs and store each record’s final disposition. Preserve the application’s separate idempotency key and check the target’s outcome before retrying a write. Message Batches suit independent high-volume work with flexible latency. Use a synchronous workflow when a consumer needs an immediate response. Current limits and eligibility depend on the Claude API configuration.
Full explanation
Structured Outputs, Validation, Retry, and Batch Patterns
Study guide · CCAR-F
Read the full explanation