Learn R Programming

openaiRtools (version 0.2.2)

retrieve_batch: Retrieve a Batch Job (Convenience Function)

Description

Shortcut that creates an OpenAI client from the OPENAI_API_KEY environment variable and retrieves a specific batch. Use this to poll status and get the output_file_id when the batch is complete.

Usage

retrieve_batch(batch_id)

Value

A batch object with $status, $request_counts

($total, $completed, $failed), and $output_file_id (when done).

Arguments

batch_id

Character. Required. The batch ID (e.g. "batch_abc123").

Examples

Run this code
if (FALSE) {
Sys.setenv(OPENAI_API_KEY = "sk-xxxxxx")

batch <- retrieve_batch("batch_abc123")
cat("Status:", batch$status)
if (batch$status == "completed") {
  raw <- retrieve_file_content(batch$output_file_id)
  cat(rawToChar(raw))
}
}

Run the code above in your browser using DataLab