Skip to content
Primary navigation

Get chat messages

$ openai chat:completions:messages list
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.

ParametersExpand Collapse
--completion-id: string

The ID of the chat completion to retrieve messages from.

--after: optional string

Identifier for the last message from the previous pagination request.

--limit: optional number

Number of messages to retrieve.

--order: optional "asc" or "desc"

Sort order for messages by timestamp. Use asc for ascending order or desc for descending order. Defaults to asc.

ReturnsExpand Collapse
ChatCompletionMessageList: object { data, first_id, has_more, 2 more }

An object representing a list of chat completion messages.

data: array of ChatCompletionStoreMessage { id, content_parts }

An array of chat completion message objects.

id: string

The identifier of the chat message.

content_parts: optional array of ChatCompletionContentPartText { text, type } or ChatCompletionContentPartImage { image_url, type }

If a content parts array was provided, this is an array of text and image_url parts. Otherwise, null.

chat_completion_content_part_text: object { text, type }

Learn about text inputs.

text: string

The text content.

type: "text"

The type of the content part.

chat_completion_content_part_image: object { image_url, type }

Learn about image inputs.

image_url: object { url, detail }
url: string

Either a URL of the image or the base64 encoded image data.

detail: optional "auto" or "low" or "high"

Specifies the detail level of the image. Learn more in the Vision guide.

"auto"
"low"
"high"
type: "image_url"

The type of the content part.

first_id: string

The identifier of the first chat message in the data array.

has_more: boolean

Indicates whether there are more chat messages available.

last_id: string

The identifier of the last chat message in the data array.

object: "list"

The type of this object. It is always set to “list”.

Get chat messages

openai chat:completions:messages list \
  --api-key 'My API Key' \
  --completion-id completion_id
{
  "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
}