TsgcHTTP_API_OpenAIMethods › CreateRun

CreateRun Method

Starts a new Run of an Assistant against an existing Thread

Syntax

function CreateRun(const aThreadId: string; const aRun: TsgcOpenAIClass_Request_Run): TsgcOpenAIClass_Run;

Parameters

NameTypeDescription
aThreadIdconst stringThe identifier of the Thread to execute.
aRunconst TsgcOpenAIClass_Request_RunRun configuration: target Assistant id, optional model/instructions overrides, tools, tool choice, streaming and truncation options.

Return Value

The newly created Run object including its id and initial status (usually queued) (TsgcOpenAIClass_Run)

Remarks

Calls POST /v1/threads/{thread_id}/runs to execute the target Assistant against the Thread. The Run progresses through states such as queued, in_progress, requires_action and completed; poll RetrieveRun or use streaming to observe progress. When status is requires_action, call SubmitToolOutputsToRun with the function results.

Example

var oRequest: TsgcOpenAIClass_Request_Run;
    oRun: TsgcOpenAIClass_Run;
begin
  oRequest := TsgcOpenAIClass_Request_Run.Create;
  try
    oRequest.AssistantId := 'asst_abc123';
    oRun := oAPI.CreateRun('thread_abc123', oRequest);
    ShowMessage('Run ' + oRun.Id + ' - ' + oRun.Status);
  finally
    oRequest.Free;
  end;
end;

Back to Methods