class

Anthropic::Messages::BatchAPI

Inherits Reference < Object

Constants

ENDPOINT = "/v1/messages/batches"

Constructors

new(client : Client)
Source

Instance methods

cancel(batch_id : String, request_options : RequestOptions | Nil = nil) : MessageBatch

Cancel a batch that is in progress.

Source
create(request : CreateMessageBatchRequest, request_options : RequestOptions | Nil = nil) : MessageBatch

Create a new message batch for asynchronous processing.

Source
create(requests : Array(CreateMessageBatchRequest::BatchRequest), request_options : RequestOptions | Nil = nil) : MessageBatch

Create a batch from an array of batch requests.

Source
delete(batch_id : String, request_options : RequestOptions | Nil = nil) : MessageBatchDeleted

Delete a message batch. Sends DELETE /v1/messages/batches/{batch_id} and returns a typed MessageBatchDeleted response.

Source
list(params : ListParams = ListParams.new, request_options : RequestOptions | Nil = nil) : Page(MessageBatch)

List all message batches with pagination.

Source
list_all(limit : Int32 | Nil = nil, request_options : RequestOptions | Nil = nil) : AutoPaginator(MessageBatch)

Auto-paginating iterator for listing all message batches. Returns an AutoPaginator that fetches pages lazily as you iterate.

Example:

client.batches.list_all(limit: 20).each do |batch|
  puts batch.id
end
Source
results(batch_id : String, request_options : RequestOptions | Nil = nil, &block : MessageBatchResult -> ) : Nil

Get results for a completed batch. Streams NDJSON results line-by-line for memory efficiency.

The actual API returns a streaming NDJSON response at GET /v1/messages/batches/{batch_id}/results. This method first retrieves the batch to find the results_url, then streams the NDJSON response and parses it line-by-line.

Results are yielded one at a time, allowing processing of very large batches without loading the entire response into memory.

Raises:

  • BatchResultsNotReadyError if the batch has not completed (results_url is nil)
  • URLAuthorityMismatchError if the results_url authority differs from the client's base_url
Source
retrieve(batch_id : String, request_options : RequestOptions | Nil = nil) : MessageBatch

Retrieve a specific batch by ID.

Source