Download Gemini Batch results to a JSONL file
Source:R/gemini_batch_api.R
gemini_download_batch_results.RdFor inline batch requests, Gemini returns results under
response$inlinedResponses$inlinedResponses. In the v1beta REST API
this often comes back as a data frame with one row per request and a
"response" column, where each "response" is itself a data frame
of GenerateContentResponse objects.
Usage
gemini_download_batch_results(
batch,
requests_tbl,
output_path,
api_key = Sys.getenv("GEMINI_API_KEY"),
api_version = "v1beta"
)Arguments
- batch
Either a parsed batch object (as returned by
gemini_get_batch()) or a character batch name such as"batches/123...".- requests_tbl
Tibble/data frame with a
custom_idcolumn in the same order as the submitted requests.- output_path
Path to the JSONL file to create.
- api_key
Optional Gemini API key (used only when
batchis a name).- api_version
API version (default
"v1beta").
Details
This helper writes those results to a local .jsonl file where each
line is a JSON object of the form:
{"custom_id": "<GEM_ID1_vs_ID2>",
"result": {
"type": "succeeded",
"response": { ... GenerateContentResponse ... }
}}
or, when an error occurred:
{"custom_id": "<GEM_ID1_vs_ID2>",
"result": {
"type": "errored",
"error": { ... }
}}
Retrieval retries
Batch metadata and result-file GET requests retry HTTP 408, 429, all 5xx
responses, and transport failures, with at most three total HTTP attempts
per GET. Valid Retry-After seconds or HTTP dates take precedence; otherwise
retries use exponential backoff starting at 0.5 seconds plus up to 0.25
seconds of jitter, capped at 30 seconds. Other HTTP errors fail immediately.
Exhaustion raises the original error with the additional class
pairwiseLLM_batch_retry_exhausted. These retries retrieve the same batch;
they do not resubmit comparisons or create scientific failed-attempt rows.
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_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
# This example requires a Gemini API key and network access.
# It assumes you have already created and run a Gemini batch job.
if (FALSE) { # \dontrun{
# Name of an existing Gemini batch
batch_name <- "batches/123456"
# Requests table used to create the batch (must include custom_id)
requests_tbl <- tibble::tibble(
custom_id = c("GEM_S01_vs_S02", "GEM_S03_vs_S04")
)
# Download inline batch results to a local JSONL file
out_file <- tempfile(fileext = ".jsonl")
gemini_download_batch_results(
batch = batch_name,
requests_tbl = requests_tbl,
output_path = out_file
)
# Inspect the downloaded JSONL
readLines(out_file, warn = FALSE)
} # }