Every request gets its own outcome
A batch holds up to 100,000 requests, and some of them will go wrong.
One request in a batch of 100,000 is invalid. What happens to the batch?
| Result | What happened | Billed |
|---|---|---|
succeeded | the model created a message | yes |
errored | the request was invalid, or hit a server error, and no message was created | no |
canceled | the customer canceled the batch before this request was sent to the model | no |
expired | the batch hit its 24-hour limit before this request was sent to the model | no |
Anthropic's docs list these four result types. One request failing doesn't affect the others in its batch.
So the unit of failure is the request. Billing follows the outcome, so the service must know exactly which requests produced a message, once each.
Partial results count too:
- A canceled Anthropic batch ends, and may still hold results for the requests processed before the cancel.
- When an OpenAI batch expires, its unfinished requests are cancelled, and the responses to the finished ones still go in the output file.
Results come back in any order, matched by custom_id
| Sent in this order | Results come back in any order |
|---|---|
| doc-001, doc-002, doc-003 | doc-003, doc-001, doc-002 |
The customer joins the two on custom_id.
Results can come back in any order, not the order the requests went in. So each request carries a custom_id: 1 to 64 characters, only letters, digits, hyphens and underscores.
That key lets the customer match each result to its request. Inside the service, the same key makes writes safe to repeat, as the failure handling section shows.
The editor holds the order you sent four requests in, and a results file that came back in another order, each line with its custom_id and result type. Write in_sent_order(sent, results): each request's result type, in the order you sent them. Then write billed(results): how many of them you pay for.
- 1
Write
in_sent_order(sent, results): each request's result type, in the order the requests were sent. - 2
Write
billed(results): how many requests are billed.
Run your code to check it. Output shows here.