Skip to content
For the complete documentation index, see llms.txt. Markdown versions of documentation pages are available by appending .md to the page URL.
Primary navigation

Get chat messages

client.Chat.Completions.Messages.List(ctx, completionID, query) (*CursorPage[ChatCompletionStoreMessage], error)
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
completionID string
query ChatCompletionMessageListParams
Returns
type ChatCompletionStoreMessage struct{…}

A chat completion message generated by the model.

ID string

The identifier of the chat message.

ContentParts []ChatCompletionStoreMessageContentPartUnion
Optional

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

Get chat messages

package main

import (
  "context"
  "fmt"

  "github.com/openai/openai-go"
  "github.com/openai/openai-go/option"
)

func main() {
  client := openai.NewClient(
    option.WithAPIKey("My API Key"),
  )
  page, err := client.Chat.Completions.Messages.List(
    context.TODO(),
    "completion_id",
    openai.ChatCompletionMessageListParams{

    },
  )
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", page)
}
{
  "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
}