List messages
Returns a list of messages for a given thread.
Path parameters
thread_id
string
Required
The ID of the thread the messages belong to.
Query parameters
limit
integer
Defaults: 20
A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20.order
string
Defaults: desc
Sort order by the
created_at
timestamp of the objects.asc
for ascending order anddesc
for descending order.after
string
A cursor for use in pagination.
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.before
string
A cursor for use in pagination.
before
is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, starting with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list.run_id
string
Filter messages by the run ID that generated them.
Response
A list of message objects.
1 curl https://api.openai.com/v1/threads/thread_abc123/messages \2 -H "Content-Type: application/json" \3 -H "Authorization: Bearer $OPENAI_API_KEY" \4 -H "OpenAI-Beta: assistants=v2"
1 {2 "object": "list",3 "data": [4 {5 "id": "msg_abc123",6 "object": "thread.message",7 "created_at": 1699016383,8 "assistant_id": null,9 "thread_id": "thread_abc123",10 "run_id": null,11 "role": "user",12 "content": [13 {14 "type": "text",15 "text": {16 "value": "How does AI work? Explain it in simple terms.",17 "annotations": []18 }19 }20 ],21 "attachments": [],22 "metadata": {}23 },24 {25 "id": "msg_abc456",26 "object": "thread.message",27 "created_at": 1699016383,28 "assistant_id": null,29 "thread_id": "thread_abc123",30 "run_id": null,31 "role": "user",32 "content": [33 {34 "type": "text",35 "text": {36 "value": "Hello, what is AI?",37 "annotations": []38 }39 }40 ],41 "attachments": [],42 "metadata": {}43 }44 ],45 "first_id": "msg_abc123",46 "last_id": "msg_abc456",47 "has_more": false48 }