Get chat messages
chat.completions.messages.list(strcompletion_id, MessageListParams**kwargs) -> SyncCursorPage[ChatCompletionStoreMessage]
GET/chat/completions/{completion_id}/messages
Get the messages in a stored chat completion. Only Chat Completions that
have been created with the store parameter set to true will be
returned.
Parameters
completion_id: str
after: Optional[str]
Identifier for the last message from the previous pagination request.
limit: Optional[int]
Number of messages to retrieve.
Returns
Get chat messages
from openai import OpenAI
client = OpenAI()
completions = client.chat.completions.list()
first_id = completions[0].id
first_completion = client.chat.completions.retrieve(completion_id=first_id)
messages = client.chat.completions.messages.list(completion_id=first_id)
print(messages)
{
"object": "list",
"data": [
{
"id": "chatcmpl-AyPNinnUqUDYo9SAdA52NobMflmj2-0",
"role": "user",
"content": "write a haiku about ai",
"name": null,
"content_parts": null
}
],
"first_id": "chatcmpl-AyPNinnUqUDYo9SAdA52NobMflmj2-0",
"last_id": "chatcmpl-AyPNinnUqUDYo9SAdA52NobMflmj2-0",
"has_more": false
}
Returns Examples
{
"object": "list",
"data": [
{
"id": "chatcmpl-AyPNinnUqUDYo9SAdA52NobMflmj2-0",
"role": "user",
"content": "write a haiku about ai",
"name": null,
"content_parts": null
}
],
"first_id": "chatcmpl-AyPNinnUqUDYo9SAdA52NobMflmj2-0",
"last_id": "chatcmpl-AyPNinnUqUDYo9SAdA52NobMflmj2-0",
"has_more": false
}