Learn R Programming

openaiRtools (version 0.2.2)

BatchClient: Batch Client

Description

The Batch API accepts a JSONL file of requests, processes them within a 24-hour window, and returns the results in an output file. Suitable for: bulk embeddings, offline evaluation, large-scale text processing, or any task that does not require immediate results.

Arguments

Workflow

  1. Create a JSONL file where each line is one API request (see format below)

  2. Upload the file: client$files$create(file, purpose = "batch")

  3. Create a batch: client$batch$create(input_file_id, endpoint)

  4. Poll status: client$batch$retrieve(batch_id)

  5. Download results: client$files$content(batch$output_file_id)

JSONL request format

Each line in the input file must be:


{"custom_id": "req-1", "method": "POST",
 "url": "/v1/chat/completions",
 "body": {"model": "gpt-4o-mini",
          "messages": [{"role": "user", "content": "Hello!"}]}}

Methods


Method new()

Usage

BatchClient$new(parent)


Method create()

Usage

BatchClient$create(
  input_file_id,
  endpoint,
  completion_window = "24h",
  metadata = NULL
)


Method list()

Usage

BatchClient$list(after = NULL, limit = NULL)


Method retrieve()

Usage

BatchClient$retrieve(batch_id)


Method cancel()

Usage

BatchClient$cancel(batch_id)


Method clone()

The objects of this class are cloneable with this method.

Usage

BatchClient$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Details

Client for the OpenAI Batch API. Process large volumes of API requests asynchronously at 50% lower cost than synchronous calls. Access via client$batch.