Where msg_id would be the ID of the last message sent by the User to the thread. Logically this should give me all of the messages that the assistant posted to the thread in response to that user message.
However, in practice this query always seems to return 0 results, whereas when omitting it and just fetching all of the messages in the thread, everything works as expected.
after is an object ID that defines your place in the list.
What does it mean that it’s an “Object ID” - sounds like something related to MongoDB? I am currently passing in the message ID as just a string , e.g. after: "msg_abc123" - like it is in the Message object. Is that incorrect?
The after query parameter is indeed used for pagination. It is an ID that defines your place in the list. When you make a list request and receive a number of objects, the ID of the last object can be used as the after parameter in your next request to fetch the next page of the list.
The term “object ID” here is not related to MongoDB but is a general term used to refer to the unique identifier of an object in a list. In the context of the OpenAI API, an object could be a message, a thread, a run, etc., each with its own unique ID.
In your case, you are passing the message ID as a string, which is the correct format. However, the issue might be with the specific message ID you are using. The after parameter should be the ID of the last object in the previous list you fetched. If you are using the ID of the last message sent by the user, but there are no assistant messages after that user message, then the query would indeed return 0 results.
Here is the relevant extract from the documentation:
after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list.