TsgcHTTP_API_OpenAI › Methods › ListMessages
Lists messages stored in a Thread with optional Run filtering and pagination
function ListMessages(const aThreadId: string; const aLimit: Integer = 20; aOrder: string = ''; aAfter: string = ''; aBefore: string = ''; aRunId: string = ''): TsgcOpenAIClass_Response_List_Messages;
| Name | Type | Description |
|---|---|---|
aThreadId | const string | The identifier of the Thread whose messages should be listed. |
aLimit | const Integer | Maximum number of messages to return (1-100, defaults to 20). |
aOrder | string | Sort order by created_at: asc or desc. |
aAfter | string | Cursor for forward pagination; pass the last message id from the previous page. |
aBefore | string | Cursor for backward pagination; pass the first message id from the previous page. |
aRunId | string | Optional Run identifier; when set only messages produced by that Run are returned. |
Paginated list of Message objects together with pagination cursors (TsgcOpenAIClass_Response_List_Messages)
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.
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;