TsgcHTTP_API_OpenAIMethods › ListMessages

ListMessages Method

Lists messages stored in a Thread with optional Run filtering and pagination

Syntax

function ListMessages(const aThreadId: string; const aLimit: Integer = 20; aOrder: string = ''; aAfter: string = ''; aBefore: string = ''; aRunId: string = ''): TsgcOpenAIClass_Response_List_Messages;

Parameters

NameTypeDescription
aThreadIdconst stringThe identifier of the Thread whose messages should be listed.
aLimitconst IntegerMaximum number of messages to return (1-100, defaults to 20).
aOrderstringSort order by created_at: asc or desc.
aAfterstringCursor for forward pagination; pass the last message id from the previous page.
aBeforestringCursor for backward pagination; pass the first message id from the previous page.
aRunIdstringOptional Run identifier; when set only messages produced by that Run are returned.

Return Value

Paginated list of Message objects together with pagination cursors (TsgcOpenAIClass_Response_List_Messages)

Remarks

Calls GET /v1/threads/{thread_id}/messages to enumerate messages in a Thread. Typical usage after a Run completes is to fetch the newest messages in descending order to display the Assistant reply. Use aRunId to obtain only the messages generated by a specific Run.

Example

var oList: TsgcOpenAIClass_Response_List_Messages;
    i: Integer;
begin
  oList := oAPI.ListMessages('thread_abc123', 20, 'desc');
  for i := 0 to oList.Data.Count - 1 do
    Memo1.Lines.Add(oList.Data[i].Role + ': ' + oList.Data[i].ContentAsText);
end;

Back to Methods