TsgcHTTP_API_OpenAIEvents › OnHTTPAPISSE

OnHTTPAPISSE Event

Fires for each Server-Sent Events chunk received during a streaming OpenAI call

Syntax

property OnHTTPAPISSE: TsgcHTTPAPISSEEvent;
// TsgcHTTPAPISSEEvent = procedure(Sender: TObject; const aEvent, aData: string; var Cancel: Boolean) of object

Default Value

Remarks

Invoked for every Server-Sent Events (SSE) frame while a streaming endpoint is active, including the Chat Completions stream (/v1/chat/completions with stream=true) and the Responses stream (/v1/responses with stream=true). aEvent holds the SSE event name (for example message, response.output_text.delta) and aData carries the JSON payload delivered for that frame. Parse the incremental chunk to update the UI in real time, and set Cancel := True to abort the stream and close the underlying HTTP connection. The terminal [DONE] sentinel is reported here too, allowing you to finalize buffered text.

Example

procedure TForm1.oAPIHTTPAPISSE(Sender: TObject; const aEvent, aData: string;
  var Cancel: Boolean);
begin
  Memo1.Lines.Add('[' + aEvent + '] ' + aData);
  if Pos('[DONE]', aData) > 0 then
    Cancel := True;
end;

Back to Events