NAME

OpenAPI::Client::OpenAI::Path::threads-thread_id-messages - Documentation for the /threads/{thread_id}/messages path.

OPERATIONS

GET /threads/{thread_id}/messages

listMessages

$client->list_messages({
    body => { ... },
});

Returns a list of messages for a given thread.

Path/query parameters

  • thread_id (in path, required, string) - The ID of the thread the messages belong to.

  • limit (in query, optional, integer) - A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20.

    Default: 20

  • order (in query, optional, string) - Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order.

    Allowed values: asc, desc

    Default: desc

  • after (in query, optional, string) - A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list.

  • before (in query, optional, string) - A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, starting with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list.

  • run_id (in query, optional, string) - Filter messages by the run ID that generated them.

Responses

200 - OK

Content-Type: application/json

Example:

{
   "data" : [
      "{\n  \"id\": \"msg_abc123\",\n  \"object\": \"thread.message\",\n  \"created_at\": 1698983503,\n  \"thread_id\": \"thread_abc123\",\n  \"role\": \"assistant\",\n  \"content\": [\n    {\n      \"type\": \"text\",\n      \"text\": {\n        \"value\": \"Hi! How can I help you today?\",\n        \"annotations\": []\n      }\n    }\n  ],\n  \"assistant_id\": \"asst_abc123\",\n  \"run_id\": \"run_abc123\",\n  \"attachments\": [],\n  \"metadata\": {}\n}\n"
   ],
   "first_id" : "msg_abc123",
   "has_more" : false,
   "last_id" : "msg_abc123",
   "object" : "list"
}

POST /threads/{thread_id}/messages

createMessage

$client->create_message({
    body => { ... },
});

Create a message.

Path/query parameters

  • thread_id (in path, required, string) - The ID of the thread to create a message for.

Responses

200 - OK

Content-Type: application/json

Example:

{
   "assistant_id" : "asst_abc123",
   "attachments" : [],
   "content" : [
      {
         "text" : {
            "annotations" : [],
            "value" : "Hi! How can I help you today?"
         },
         "type" : "text"
      }
   ],
   "created_at" : 1698983503,
   "id" : "msg_abc123",
   "metadata" : {},
   "object" : "thread.message",
   "role" : "assistant",
   "run_id" : "run_abc123",
   "thread_id" : "thread_abc123"
}

SCHEMAS

CreateMessageRequest

Properties:

  • attachments (anyOf)

  • content (oneOf, required)

  • metadata (Metadata)

    See "Metadata" below for shape.

  • role (string, required) - The role of the entity that is creating the message. Allowed values include: - user : Indicates the message is sent by an actual user and should be used in most cases to represent user-generated messages. - assistant : Indicates the message is generated by the assistant. Use this value to insert messages from the assistant into the conversation.

    Allowed values: user, assistant

ListMessagesResponse

Properties:

  • data (array of MessageObject, required)

  • first_id (string, required)

  • has_more (boolean, required)

  • last_id (string, required)

  • object (string, required)

MessageObject

Properties:

  • assistant_id (anyOf, required)

  • attachments (anyOf, required)

  • completed_at (anyOf, required)

  • content (array of object, required) - The content of the message in array of text and/or images.

  • created_at (integer, required) - The Unix timestamp (in seconds) for when the message was created.

  • id (string, required) - The identifier, which can be referenced in API endpoints.

  • incomplete_at (anyOf, required)

  • incomplete_details (anyOf, required)

  • metadata (Metadata, required)

    See "Metadata" below for shape.

  • object (string, required) - The object type, which is always thread.message .

    Allowed values: thread.message

  • role (string, required) - The entity that produced the message. One of user or assistant .

    Allowed values: user, assistant

  • run_id (anyOf, required)

  • status (string, required) - The status of the message, which can be either in_progress , incomplete , or completed .

    Allowed values: in_progress, incomplete, completed

  • thread_id (string, required) - The thread ID that this message belongs to.

Metadata

Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format, and querying for objects via API or the dashboard.

Keys are strings with a maximum length of 64 characters. Values are strings with a maximum length of 512 characters.

SEE ALSO

OpenAPI::Client::OpenAI::Path

COPYRIGHT AND LICENSE

Copyright (C) 2023-2026 by Nelson Ferraz

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.14.0 or, at your option, any later version of Perl 5 you may have available.