## Get chat messages

`chat.completions.messages.list(completion_id, **kwargs) -> CursorPage<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: String`

- `after: String`

  Identifier for the last message from the previous pagination request.

- `limit: Integer`

  Number of messages to retrieve.

- `order: :asc | :desc`

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

  - `:asc`

  - `:desc`

### Returns

- `class ChatCompletionStoreMessage`

  A chat completion message generated by the model.

  - `id: String`

    The identifier of the chat message.

  - `content_parts: Array[ChatCompletionContentPartText | ChatCompletionContentPartImage]`

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

    - `class ChatCompletionContentPartText`

      Learn about [text inputs](https://platform.openai.com/docs/guides/text-generation).

      - `text: String`

        The text content.

      - `type: :text`

        The type of the content part.

        - `:text`

    - `class ChatCompletionContentPartImage`

      Learn about [image inputs](https://platform.openai.com/docs/guides/vision).

      - `image_url: { url, detail}`

        - `url: String`

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

        - `detail: :auto | :low | :high`

          Specifies the detail level of the image. Learn more in the [Vision guide](https://platform.openai.com/docs/guides/vision#low-or-high-fidelity-image-understanding).

          - `:auto`

          - `:low`

          - `:high`

      - `type: :image_url`

        The type of the content part.

        - `:image_url`

### Example

```ruby
require "openai"

openai = OpenAI::Client.new(api_key: "My API Key")

page = openai.chat.completions.messages.list("completion_id")

puts(page)
```

#### Response

```json
{
  "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"
}
```
