This is a thin wrapper around Anthropic's
/v1/messages/batches endpoint. It accepts a list of request
objects (each with custom_id and params) and returns the
resulting Message Batch object.
Usage
anthropic_create_batch(
requests,
api_key = Sys.getenv("ANTHROPIC_API_KEY"),
anthropic_version = "2023-06-01"
)Arguments
- requests
List of request objects, each of the form
list(custom_id = <chr>, params = <list>). You can obtain this list from the output ofbuild_anthropic_batch_requestsviasplit/Map, or userun_anthropic_batch_pipeline.- api_key
Optional Anthropic API key. Defaults to
Sys.getenv("ANTHROPIC_API_KEY").- anthropic_version
Anthropic API version string passed as the
anthropic-versionHTTP header. Defaults to"2023-06-01".
Value
A list representing the Message Batch object returned by Anthropic.
Important fields include id, processing_status,
request_counts, and (after completion) results_url.
Details
Typically you will not call this directly; instead, use
run_anthropic_batch_pipeline which builds requests from a
tibble of pairs, creates the batch, polls for completion, and downloads
the results.
See also
llm_submit_pairs_batch(), llm_download_batch_results()
Other batch backends:
anthropic_download_batch_results(),
anthropic_get_batch(),
anthropic_poll_batch_until_complete(),
build_anthropic_batch_requests(),
build_gemini_batch_requests(),
build_openai_batch_requests(),
gemini_create_batch(),
gemini_download_batch_results(),
gemini_get_batch(),
gemini_poll_batch_until_complete(),
llm_download_batch_results(),
llm_resume_multi_batches(),
llm_submit_pairs_batch(),
llm_submit_pairs_multi_batch(),
openai_create_batch(),
openai_download_batch_errors(),
openai_download_batch_output(),
openai_get_batch(),
openai_poll_batch_until_complete(),
openai_upload_batch_file(),
run_anthropic_batch_pipeline(),
run_gemini_batch_pipeline(),
run_openai_batch_pipeline(),
write_openai_batch_file()
Examples
if (FALSE) { # \dontrun{
# Requires ANTHROPIC_API_KEY and network access.
library(pairwiseLLM)
data("example_writing_samples", package = "pairwiseLLM")
pairs <- example_writing_samples |>
make_pairs() |>
sample_pairs(n_pairs = 2, seed = 123) |>
randomize_pair_order(seed = 456)
td <- trait_description("overall_quality")
tmpl <- set_prompt_template()
req_tbl <- build_anthropic_batch_requests(
pairs = pairs,
model = "claude-sonnet-4-5",
trait_name = td$name,
trait_description = td$description,
prompt_template = tmpl
)
requests <- lapply(seq_len(nrow(req_tbl)), function(i) {
list(
custom_id = req_tbl$custom_id[i],
params = req_tbl$params[[i]]
)
})
batch <- anthropic_create_batch(requests = requests)
batch$id
batch$processing_status
} # }