Skip to content
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.

ParametersExpand Collapse
completionID string
query ChatCompletionMessageListParams
After param.Field[string]Optional

Identifier for the last message from the previous pagination request.

Limit param.Field[int64]Optional

Number of messages to retrieve.

Order param.Field[ChatCompletionMessageListParamsOrder]Optional

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

const ChatCompletionMessageListParamsOrderAsc ChatCompletionMessageListParamsOrder = "asc"
const ChatCompletionMessageListParamsOrderDesc ChatCompletionMessageListParamsOrder = "desc"
ReturnsExpand Collapse
type ChatCompletionStoreMessage struct{…}

A chat completion message generated by the model.

ID string

The identifier of the chat message.

ContentParts []ChatCompletionStoreMessageContentPartUnionOptional

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

One of the following:
type ChatCompletionContentPartText struct{…}

Learn about text inputs.

Text string

The text content.

Type Text

The type of the content part.

type ChatCompletionContentPartImage struct{…}

Learn about image inputs.

ImageURL ChatCompletionContentPartImageImageURL
URL string

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

formaturi
Detail stringOptional

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

One of the following:
const ChatCompletionContentPartImageImageURLDetailAuto ChatCompletionContentPartImageImageURLDetail = "auto"
const ChatCompletionContentPartImageImageURLDetailLow ChatCompletionContentPartImageImageURLDetail = "low"
const ChatCompletionContentPartImageImageURLDetailHigh ChatCompletionContentPartImageImageURLDetail = "high"
Type ImageURL

The type of the content part.

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
}