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.

GET /chat/completions/{completion_id}/messages

Path parameters

  • completion_id string Required

    The ID of the chat completion to retrieve messages from.

Query parameters

  • after string

    Identifier for the last message from the previous pagination request.

  • limit integer

    Number of messages to retrieve.

    Default value is 20.

  • order string

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

    Values are asc or desc. Default value is asc.

Responses

  • 200 application/json

    A list of messages

    Hide response attributes Show response attributes object
    • object string Required

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

      Value is list. Default value is list.

    • data array[object] Required

      An array of chat completion message objects.

      Hide data attributes Show data attributes object
      • content string | null Required

        The contents of the message.

      • refusal string | null Required

        The refusal message generated by the model.

      • tool_calls array[object]

        The tool calls generated by the model, such as function calls.

        Hide tool_calls attributes Show tool_calls attributes object
        • id string Required

          The ID of the tool call.

        • type string Required

          The type of the tool. Currently, only function is supported.

          Value is function.

        • function object Required

          The function that the model called.

          Hide function attributes Show function attributes object
          • name string Required

            The name of the function to call.

          • arguments string Required

            The arguments to call the function with, as generated by the model in JSON format. Note that the model does not always generate valid JSON, and may hallucinate parameters not defined by your function schema. Validate the arguments in your code before calling your function.

      • annotations array[object]

        Annotations for the message, when applicable, as when using the web search tool.

        A URL citation when using web search.

        Hide annotations attributes Show annotations attributes object
        • type string Required

          The type of the URL citation. Always url_citation.

          Value is url_citation.

        • url_citation object Required

          A URL citation when using web search.

          Hide url_citation attributes Show url_citation attributes object
          • end_index integer Required

            The index of the last character of the URL citation in the message.

          • start_index integer Required

            The index of the first character of the URL citation in the message.

          • url string Required

            The URL of the web resource.

          • title string Required

            The title of the web resource.

      • role string Required

        The role of the author of this message.

        Value is assistant.

      • function_call object Deprecated

        Deprecated and replaced by tool_calls. The name and arguments of a function that should be called, as generated by the model.

        Hide function_call attributes Show function_call attributes object Deprecated
        • arguments string Required

          The arguments to call the function with, as generated by the model in JSON format. Note that the model does not always generate valid JSON, and may hallucinate parameters not defined by your function schema. Validate the arguments in your code before calling your function.

        • name string Required

          The name of the function to call.

      • audio object | null

        If the audio output modality is requested, this object contains data about the audio response from the model. Learn more.

        Hide audio attributes Show audio attributes object | null
        • id string Required

          Unique identifier for this audio response.

        • expires_at integer Required

          The Unix timestamp (in seconds) for when this audio response will no longer be accessible on the server for use in multi-turn conversations.

        • data string Required

          Base64 encoded audio bytes generated by the model, in the format specified in the request.

        • transcript string Required

          Transcript of the audio generated by the model.

      • id string Required

        The identifier of the chat message.

    • first_id string Required

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

    • last_id string Required

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

    • has_more boolean Required

      Indicates whether there are more chat messages available.

GET /chat/completions/{completion_id}/messages
curl \
 --request GET 'https://api.openai.com/v1/chat/completions/{completion_id}/messages' \
 --header "Authorization: Bearer $ACCESS_TOKEN"
Response examples (200)
{
  "object": "list",
  "data": [
    {
      "content": "string",
      "refusal": "string",
      "tool_calls": [
        {
          "id": "string",
          "type": "function",
          "function": {
            "name": "string",
            "arguments": "string"
          }
        }
      ],
      "annotations": [
        {
          "type": "url_citation",
          "url_citation": {
            "end_index": 42,
            "start_index": 42,
            "url": "string",
            "title": "string"
          }
        }
      ],
      "role": "assistant",
      "function_call": {
        "arguments": "string",
        "name": "string"
      },
      "audio": {
        "id": "string",
        "expires_at": 42,
        "data": "string",
        "transcript": "string"
      },
      "id": "string"
    }
  ],
  "first_id": "string",
  "last_id": "string",
  "has_more": true
}