This helper takes the output of build_openai_batch_requests
(or a compatible table) and writes one JSON object per line, in the
format expected by the OpenAI batch API.
Arguments
- batch_tbl
A data frame or tibble, typically the result of
build_openai_batch_requests.- path
File path where the JSONL file should be written.
Details
The input can either:
Already contain a character column
jsonl(one JSON string per row), in which case that column is used directly, orContain the columns
custom_id,method,url, andbody, in which case the JSON strings are constructed automatically.
See also
llm_submit_pairs_batch(), llm_download_batch_results()
Other batch backends:
anthropic_create_batch(),
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()
Examples
# Construct a minimal batch request tibble
requests <- tibble::tibble(
custom_id = c("req1", "req2"),
method = "POST",
url = "/v1/chat/completions",
body = list(
list(
model = "gpt-4o-mini",
messages = list(
list(role = "user", content = "Hello")
)
),
list(
model = "gpt-4o-mini",
messages = list(
list(role = "user", content = "Goodbye")
)
)
)
)
# Write to a temporary JSONL file
path <- tempfile(fileext = ".jsonl")
write_openai_batch_file(requests, path)
# Inspect the file contents
readLines(path)
#> [1] "{\"custom_id\":\"req1\",\"method\":\"POST\",\"url\":\"/v1/chat/completions\",\"body\":{\"model\":\"gpt-4o-mini\",\"messages\":[{\"role\":\"user\",\"content\":\"Hello\"}]}}"
#> [2] "{\"custom_id\":\"req2\",\"method\":\"POST\",\"url\":\"/v1/chat/completions\",\"body\":{\"model\":\"gpt-4o-mini\",\"messages\":[{\"role\":\"user\",\"content\":\"Goodbye\"}]}}"