Claude API · Caching, batches and tokens
Wait for a batch and read results
Poll until processing ends, then stream the results. Results arrive in any order, so match them by custom_id.
import time
while client.messages.batches.retrieve(batch.id).processing_status != "ended":
time.sleep(60)
for entry in client.messages.batches.results(batch.id):
if entry.result.type == "succeeded":
print(entry.custom_id, entry.result.message.content[0].text)
Official Claude API documentation
More caching, batches and tokens commands
All caching, batches and tokens commands · Claude API cheatsheet