Anthropic Message Batches API - Process large volumes of messages asynchronously with 50% cost reduction.
Functions
cancel
fn (batch_id: Str): MessageBatch
fn (batch_id: Str, opts: Map): MessageBatch
POST /v1/messages/batches/{batch_id}/cancel - Cancel a message batch.
Cancels a batch that is still processing.
Example
batch ::anthropic::batches/cancel("batch_abc123")
create
fn (request: CreateBatchRequest): MessageBatch
fn (request: CreateBatchRequest, opts: Map): MessageBatch
POST /v1/messages/batches - Create a message batch.
Process up to 100,000 message requests asynchronously with 50% cost reduction.
Example
batch ::anthropic::batches/create(CreateBatchRequest({
requests: [
{
custom_id: "req-1",
params: {
model: "claude-3-haiku-20240307",
max_tokens: 100,
messages: [{role: "user", content: "Hello!"}]
}
}
]
}))
batch.id // => "msgbatch_abc123"
get
fn (batch_id: Str): MessageBatch
fn (batch_id: Str, opts: Map): MessageBatch
GET /v1/messages/batches/{batch_id} - Retrieve a message batch.
Returns details about a specific batch.
Example
batch ::anthropic::batches/get("batch_abc123")
batch.processing_status // => "ended"
list
fn (): BatchesListResponse
fn (opts: Map): BatchesListResponse
fn (limit: Int): BatchesListResponse
fn (limit: Int, opts: Map): BatchesListResponse
GET /v1/messages/batches - List message batches.
Returns a paginated list of your message batches. Optionally pass a limit
to control page size.
Example
// List all batches
batches ::anthropic::batches/list()
assert(is-vec(batches.data))
map(batches.data, %.processing_status)
// List with a limit
batches ::anthropic::batches/list(5)
assert(lte(length(batches.data), 5))
results
fn (batch_id: Str): Any
fn (batch_id: Str, opts: Map): Any
GET /v1/messages/batches/{batch_id}/results - Get batch results.
Returns the results of a completed batch as JSONL.
Example
results ::anthropic::batches/results("batch_abc123")
Types
BatchIndividualRequest
BatchIndividualRequest type {
custom_id: Str,
params: Any
}
BatchRequestCounts
BatchRequestCounts type {
processing: Int,
succeeded: Int,
errored: Int,
canceled: Int,
expired: Int
}
BatchesListResponse
BatchesListResponse type {
data: Vec<MessageBatch>,
has_more: Bool,
first_id: Str?,
last_id: Str?
}
CreateBatchRequest
CreateBatchRequest type {
requests: Vec<BatchIndividualRequest>
}
MessageBatch
MessageBatch type {
id: Str,
type: Str,
processing_status: Str,
request_counts: BatchRequestCounts,
ended_at: Str?,
created_at: Str,
expires_at: Str,
archived_at: Str?,
cancel_initiated_at: Str?,
results_url: Str?
}