Class AnthropicBatchChatModel
- All Implemented Interfaces:
BatchChatModel
BatchChatModel for the Anthropic
Message Batches API, which processes
multiple chat requests asynchronously at 50% of the standard per-token price.
Each submitted ChatRequest is mapped to a request identical to the one
AnthropicChatModel would send, so per-request parameters (model, tools, thinking, caching, etc.) behave
the same in a batch as in a single call. Requests are submitted inline; the returned BatchResponse carries
the batch id and its current BatchState. Results are fetched by retrieve(String) once the batch has
ended, preserving submission order.
- See Also:
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuilder()voidCancels a chat batch operation that is currently pending or running.list(@Nullable BatchPagination pagination) Lists chat batch jobs with optional pagination.Retrieves the current state and results of a chat batch operation.submit(BatchRequest<ChatRequest> request) Creates a batch of chat requests and submits them for asynchronous processing.
-
Constructor Details
-
AnthropicBatchChatModel
-
-
Method Details
-
submit
Creates a batch of chat requests and submits them for asynchronous processing.The returned
BatchResponserepresents the status of the batch operation.All requests are submitted inline in a single HTTP request, so Anthropic's limits of 100,000 requests and 256 MB per batch apply. Exceeding either is rejected by the API.
- Specified by:
submitin interfaceBatchChatModel- Parameters:
request- the list of chat requests to process in the batch- Returns:
- a
BatchResponserepresenting the initial state of the batch operation
-
retrieve
Retrieves the current state and results of a chat batch operation.The response indicates whether the batch is still processing, completed successfully, or failed. Clients should poll this method at intervals until the batch completes.
Once the batch has ended, all of its results are downloaded and held in memory. For very large batches (Anthropic allows up to 100,000 requests per batch) this can require a correspondingly large heap.
- Specified by:
retrievein interfaceBatchChatModel- Parameters:
batchId- the batch identifier obtained fromBatchChatModel.submit(BatchRequest)- Returns:
- a
BatchResponserepresenting the current state of the chat batch operation
-
cancel
Description copied from interface:BatchChatModelCancels a chat batch operation that is currently pending or running.- Specified by:
cancelin interfaceBatchChatModel- Parameters:
batchId- the batch identifier to cancel
-
list
Description copied from interface:BatchChatModelLists chat batch jobs with optional pagination.- Specified by:
listin interfaceBatchChatModel- Parameters:
pagination- the maximum number of batch jobs to return and token for retrieving a specific page; if null, uses server default- Returns:
- a
BatchPagecontaining chat batch responses and pagination information
-
builder
- Returns:
- a new
AnthropicBatchChatModel.BuilderforAnthropicBatchChatModel.
-