TsgcHTTP_API_OpenAIMethods › CreateResponse

CreateResponse Method

Creates a new model response using the OpenAI Responses API

Syntax

function CreateResponse(const aRequest: TsgcOpenAIClass_Request_Response) : TsgcOpenAIClass_Response_Response;

Parameters

NameTypeDescription
aRequestconst TsgcOpenAIClass_Request_ResponseRequest payload containing the model, input, optional tools, reasoning options and other Responses API parameters.

Return Value

Parsed response object exposing the generated output items, final status, usage and the unique id used to retrieve or cancel it later. (TsgcOpenAIClass_Response_Response)

Remarks

Issues a POST to /v1/responses, the unified endpoint introduced by OpenAI for agentic and reasoning workloads. Responses accept text, images, audio and file inputs, run built-in tools (web search, file search, code interpreter, computer use) and can be chained by supplying a PreviousResponseId. Enable aRequest.Stream to receive incremental deltas through OnHTTPAPISSE; the returned object still reflects the final aggregated state once the stream completes.

Example

oRequest := TsgcOpenAIClass_Request_Response.Create;
try
  oRequest.Model := 'gpt-5';
  oRequest.Input := 'Summarize the plot of Hamlet in two sentences.';
  oResponse := oAPI.CreateResponse(oRequest);
  ShowMessage(oResponse.OutputText);
finally
  oRequest.Free;
end;

Back to Methods