#Messages in Assistants API
1 messages · Page 1 of 1 (latest)
Hi @reef stone. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
To retrieve the Assistant's response to a message sent via the Assistants API in a thread, you can use the openai.beta.threads.messages.list method. This method returns all messages in the thread. You can then filter the messages to get the Assistant's responses.
Here is an example of how you can do this in Node.js:
const messages = await openai.beta.threads.messages.list(thread.id);
const assistantMessages = messages.data.filter(msg => msg.role === 'assistant');
In this code, thread.id is the ID of the thread where you sent the message. The filter function is used to get only the messages where the role is 'assistant', which are the responses from the Assistant.
You can also order the messages by the "create_at" timestamp to properly order the thread when grabbing the assistant response. Here is how you can do it in Python:
messages = client.beta.threads.messages.list(
thread_id=thread.id,
# Orders it by ascending order, so the latest response is at the top
order='asc'
)