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
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ.get("OPENAI_API_KEY"), # This is the default and can be omitted
)
page = client.chat.completions.messages.list(
completion_id="completion_id",
)
page = page.data[0]
print(page){
"data": [
{
"content": "content",
"refusal": "refusal",
"role": "assistant",
"annotations": [
{
"type": "url_citation",
"url_citation": {
"end_index": 0,
"start_index": 0,
"title": "title",
"url": "url"
}
}
],
"audio": {
"id": "id",
"data": "data",
"expires_at": 0,
"transcript": "transcript"
},
"function_call": {
"arguments": "arguments",
"name": "name"
},
"tool_calls": [
{
"id": "id",
"function": {
"arguments": "arguments",
"name": "name"
},
"type": "function"
}
],
"id": "id",
"content_parts": [
{
"text": "text",
"type": "text"
}
]
}
],
"first_id": "first_id",
"has_more": true,
"last_id": "last_id",
"object": "list"
}Returns Examples
{
"data": [
{
"content": "content",
"refusal": "refusal",
"role": "assistant",
"annotations": [
{
"type": "url_citation",
"url_citation": {
"end_index": 0,
"start_index": 0,
"title": "title",
"url": "url"
}
}
],
"audio": {
"id": "id",
"data": "data",
"expires_at": 0,
"transcript": "transcript"
},
"function_call": {
"arguments": "arguments",
"name": "name"
},
"tool_calls": [
{
"id": "id",
"function": {
"arguments": "arguments",
"name": "name"
},
"type": "function"
}
],
"id": "id",
"content_parts": [
{
"text": "text",
"type": "text"
}
]
}
],
"first_id": "first_id",
"has_more": true,
"last_id": "last_id",
"object": "list"
}