Learn R Programming

openaiRtools (version 0.2.2)

create_run: Create a Run (Convenience Function)

Description

Shortcut that creates an OpenAI client from the OPENAI_API_KEY environment variable and creates a run on a thread. Poll the run with retrieve_run() until status is "completed".

Usage

create_run(thread_id, assistant_id, ...)

Value

A run object with $id and $status.

Arguments

thread_id

Character. Required. The thread ID.

assistant_id

Character. Required. The assistant ID to run.

...

Additional parameters passed to RunsClient$create(), such as instructions, model, tools, stream, callback.

Examples

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

run <- create_run(
  thread_id    = "thread_abc123",
  assistant_id = "asst_abc123"
)
cat("Run ID:", run$id, "Status:", run$status)

# Poll until done
repeat {
  run <- retrieve_run("thread_abc123", run$id)
  if (run$status %in% c("completed", "failed", "cancelled")) break
  Sys.sleep(2)
}
}

Run the code above in your browser using DataLab