Skip to content
Primary navigation

Get chat messages

MessageListPage chat().completions().messages().list(MessageListParamsparams = MessageListParams.none(), RequestOptionsrequestOptions = RequestOptions.none())
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
MessageListParams params
Optional<String> completionId
Optional<String> after

Identifier for the last message from the previous pagination request.

Optional<Long> limit

Number of messages to retrieve.

Optional<Order> order

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

ASC("asc")
DESC("desc")
ReturnsExpand Collapse
class ChatCompletionStoreMessage:

A chat completion message generated by the model.

String id

The identifier of the chat message.

Optional<List<ContentPart>> contentParts

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

Accepts one of the following:
class ChatCompletionContentPartText:

Learn about text inputs.

String text

The text content.

JsonValue; type "text"constant"text"constant

The type of the content part.

class ChatCompletionContentPartImage:

Learn about image inputs.

ImageUrl imageUrl
String url

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

formaturi
Optional<Detail> detail

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

Accepts one of the following:
AUTO("auto")
LOW("low")
HIGH("high")
JsonValue; type "image_url"constant"image_url"constant

The type of the content part.

Get chat messages

package com.openai.example;

import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.chat.completions.messages.MessageListPage;
import com.openai.models.chat.completions.messages.MessageListParams;

public final class Main {
    private Main() {}

    public static void main(String[] args) {
        OpenAIClient client = OpenAIOkHttpClient.fromEnv();

        MessageListPage page = client.chat().completions().messages().list("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
}