Learn R Programming

openaiRtools (version 0.2.2)

create_batch: Create a Batch Job (Convenience Function)

Description

Shortcut that creates an OpenAI client from the OPENAI_API_KEY environment variable and calls client$batch$create().

Usage

create_batch(input_file_id, endpoint, ...)

Value

A batch object with $id and $status.

Arguments

input_file_id

Character. Required. File ID of the uploaded JSONL batch input file (uploaded with purpose = "batch").

endpoint

Character. Required. API endpoint for each request. One of "/v1/chat/completions", "/v1/embeddings", "/v1/completions".

...

Additional parameters passed to BatchClient$create(), such as completion_window (default "24h") and metadata.

Examples

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

batch <- create_batch(
  input_file_id = "file-abc123",
  endpoint      = "/v1/chat/completions"
)
cat("Batch ID:", batch$id)
}

Run the code above in your browser using DataLab