Skip to contents

This helper repeatedly calls gemini_get_batch until the batch's metadata$state enters a terminal state or a time limit is reached. For the REST API, states have the form "BATCH_STATE_*".

Usage

gemini_poll_batch_until_complete(
  batch_name,
  interval_seconds = 60,
  timeout_seconds = 86400,
  api_key = Sys.getenv("GEMINI_API_KEY"),
  api_version = "v1beta",
  verbose = TRUE
)

Arguments

batch_name

Character scalar giving the batch name.

interval_seconds

Polling interval in seconds. Defaults to 60.

timeout_seconds

Maximum total waiting time in seconds. Defaults to 24 hours (86400 seconds).

api_key

Optional Gemini API key. Defaults to Sys.getenv("GEMINI_API_KEY").

api_version

API version string for the path; defaults to "v1beta".

verbose

Logical; if TRUE, prints progress messages.

Value

The final Batch job object as returned by gemini_get_batch.

Polling limits

HTTP retries occur within a logical status poll. Elapsed time includes retry waits, but timeout_seconds is checked between status requests; an in-flight GET and its retries can finish after that limit. Existing terminal-status and timeout return behavior is preserved.

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.

Examples

# Offline: polling parameters and batch name are plain R objects
batch_name <- "batches/123456"

# Online: poll until the batch reaches a terminal state (requires network)
if (FALSE) { # \dontrun{
final_batch <- gemini_poll_batch_until_complete(
  batch_name       = batch_name,
  interval_seconds = 10,
  timeout_seconds  = 600,
  verbose          = TRUE
)
final_batch$metadata$state
} # }