foundry_batch_requests: Write JSONL requests for the Batch API

View source: R/batches.R

foundry_batch_requestsR Documentation

Write JSONL requests for the Batch API

Description

Convert a data frame of prompts into a JSON Lines file that can be uploaded with foundry_file_upload(..., purpose = "batch") and submitted with foundry_batch_create().

Usage

foundry_batch_requests(
  data,
  input,
  path,
  model,
  endpoint = "/v1/responses",
  custom_id = NULL,
  body = list(),
  schema = NULL,
  schema_name = "ExtractedData",
  strict = TRUE,
  instructions = NULL,
  body_columns = NULL,
  overwrite = FALSE
)

Arguments

data

Data frame containing input rows.

input

Character. Name of the column containing prompt/input text.

path

Character. Path to write the JSONL file.

model

Character. Model deployment name to include in each request.

endpoint

Character. Batch endpoint path. Defaults to "/v1/responses".

custom_id

Character. Optional column name for custom IDs. If omitted, IDs are generated as row-1, row-2, and so on.

body

List. Additional request body fields added to each request.

schema

List. Optional JSON Schema for structured Responses API output.

schema_name

Character. Name for schema when supplied.

strict

Logical. Whether structured output should be strict.

instructions

Character. Optional instructions for Responses API requests.

body_columns

Character vector. Optional column names whose per-row values should be added to each request body.

overwrite

Logical. Whether to overwrite an existing file.

Value

A tibble with the JSONL path, request count, and endpoint.

Examples

local({
  jobs <- data.frame(text = c("Summarize this.", "Extract entities."))
  path <- tempfile(fileext = ".jsonl")
  on.exit(unlink(path))
  foundry_batch_requests(
    jobs, input = "text", path = path, model = "gpt-5-nano"
  )
})

foundryR documentation built on Sept. 25, 2026, 1:10 a.m.