Anthropic Message Batches API¶
These APIs call Anthropic's native Message Batches endpoint. They do not use
the OpenAI-compatible Provider.
executionkit.batches.AnthropicBatchClient ¶
AnthropicBatchClient(api_key: str, *, base_url: str = DEFAULT_ANTHROPIC_BASE_URL, timeout: float = DEFAULT_HTTP_TIMEOUT_SECONDS)
Minimal stdlib client for the Anthropic Message Batches API.
Exposes exactly the three calls the fan-out helpers need: create a batch,
poll it, and fetch its results file. All transport goes through
:meth:_http_raw — the single seam tests replace to run without a
network.
Source code in executionkit/batches.py
create_batch
async
¶
POST /v1/messages/batches with the given request entries.
Source code in executionkit/batches.py
fetch_results
async
¶
Fetch and parse the JSONL results file of an ended batch.
Source code in executionkit/batches.py
get_batch
async
¶
GET /v1/messages/batches/{id} — the polling call.
Source code in executionkit/batches.py
executionkit.batches.consensus_batch
async
¶
consensus_batch(client: AnthropicBatchClient, model: str, prompt: str, *, num_samples: int = 5, strategy: VotingStrategy | str = 'majority', temperature: float = DEFAULT_BATCH_TEMPERATURE, max_tokens: int = DEFAULT_MAX_TOKENS, poll_interval: float = DEFAULT_POLL_INTERVAL_SECONDS, timeout: float = DEFAULT_BATCH_TIMEOUT_SECONDS) -> PatternResult[str]
Consensus over num_samples identical prompts via one message batch.
The batch-transport twin of :func:executionkit.consensus: same prompt
replication, same voting (:func:executionkit.engine.voting.tally_votes),
same result shape — but the samples travel as a single Message Batches
submission instead of num_samples concurrent live calls.
Anthropic-Batches-specific: unlike the provider-agnostic headline patterns
(:func:executionkit.consensus, :func:executionkit.map_reduce, and
friends — all of which accept any LLMProvider-conforming object), this
function only talks to Anthropic's Message Batches API and requires an
:class:AnthropicBatchClient and Anthropic API key — it is not usable
with an arbitrary OpenAI-compatible endpoint.
Returns:
| Name | Type | Description |
|---|---|---|
A |
PatternResult[str]
|
class: |
PatternResult[str]
|
|
Raises:
| Type | Description |
|---|---|
ConsensusFailedError
|
When |
ProviderError
|
On transport failure, poll timeout, or any non-succeeded batch entry. |
ValueError
|
If |
Source code in executionkit/batches.py
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 | |
executionkit.batches.map_batch
async
¶
map_batch(client: AnthropicBatchClient, model: str, prompts: Sequence[str], *, max_tokens: int = DEFAULT_MAX_TOKENS, temperature: float | None = None, poll_interval: float = DEFAULT_POLL_INTERVAL_SECONDS, timeout: float = DEFAULT_BATCH_TIMEOUT_SECONDS) -> PatternResult[tuple[str, ...]]
Map every prompt to a completion via one message batch (fan-out only).
The "map" half of a map-reduce: one request per prompt, submitted as a
single batch, with responses returned in prompt order regardless of the
order the provider finished them. Callers reduce however they like —
including with :func:executionkit.engine.voting.tally_votes for a
consensus-style reduce over non-identical prompts.
Anthropic-Batches-specific: like :func:consensus_batch, this function
only talks to Anthropic's Message Batches API — unlike the
provider-agnostic headline patterns (:func:executionkit.map_reduce and
friends), it is not usable with other OpenAI-compatible endpoints.
Returns:
| Name | Type | Description |
|---|---|---|
A |
PatternResult[tuple[str, ...]]
|
class: |
PatternResult[tuple[str, ...]]
|
index-aligned with |
|
PatternResult[tuple[str, ...]]
|
quality measure for a map). |
Raises:
| Type | Description |
|---|---|
ProviderError
|
On transport failure, poll timeout, or any non-succeeded batch entry (strict all-or-nothing). |
ValueError
|
If |
Source code in executionkit/batches.py
Read Anthropic Message Batches for configuration, polling behavior, and failure handling.