Batch API

Create, retrieve, cancel, and list async bulk jobs, and poll them to completion. The Batch API processes large request sets asynchronously at roughly half the cost: the input is a JSONL file uploaded via the Files API with purpose="batch", and output is fetched with file_content using batch.output_file_id. OpenAI only.

Parsed Objects

UniLM.BatchObjectType
BatchObject

A batch job from the Batch API: id, status, endpoint, input_file_id, output_file_id, error_file_id, and request_counts; raw holds the unparsed JSON response.

source

Result Types

Request Functions

UniLM.create_batchFunction
create_batch(input_file_id, endpoint; completion_window="24h", metadata=nothing, service=OPENAIServiceEndpoint)

Create a batch job. endpoint is e.g. "/v1/chat/completions", "/v1/responses", or "/v1/embeddings". input_file_id comes from upload_file(path, "batch").

Pass config::Union{Nothing,RequestConfig} to override the timeout budget for this call (a single bounded attempt; max_attempts does not apply).

source
UniLM.retrieve_batchFunction
retrieve_batch(id; service=OPENAIServiceEndpoint)

Pass config::Union{Nothing,RequestConfig} to override the timeout budget for this call (a single bounded attempt; max_attempts does not apply).

source
UniLM.cancel_batchFunction
cancel_batch(id; service=OPENAIServiceEndpoint)

Pass config::Union{Nothing,RequestConfig} to override the timeout budget for this call (a single bounded attempt; max_attempts does not apply).

source
UniLM.list_batchesFunction
list_batches(; limit=nothing, after=nothing, service=OPENAIServiceEndpoint)

Pass config::Union{Nothing,RequestConfig} to override the timeout budget for this call (a single bounded attempt; max_attempts does not apply).

source
UniLM.poll_batchFunction
poll_batch(id; interval=10.0, timeout=86400.0, service=OPENAIServiceEndpoint)

Poll a batch until terminal (completed/failed/cancelled/expired) or timeout.

Pass config::Union{Nothing,RequestConfig} to override the timeout budget for this call (a single bounded attempt; max_attempts does not apply).

source

Usage

# Upload a JSONL request file, then create a batch job
upload = upload_file("requests.jsonl", "batch")
batch = create_batch(upload.response.id, "/v1/chat/completions")

# Poll until terminal (completed / failed / cancelled / expired)
done = poll_batch(batch.response.id)
if done isa BatchSuccess && done.response.status == "completed"
    output = file_content(done.response.output_file_id)
    output isa FileContentSuccess && save_file_content(output, "results.jsonl")
end

# List jobs, or cancel one
list_batches(limit=10)
cancel_batch(batch.response.id)