Skip to main content

messages

Creates, updates, deletes, gets or lists a messages resource.

Overview

Namemessages
TypeResource
Idopenai.assistants.messages

Fields

The following fields are returned by SELECT queries:

NameDatatypeDescription
idstringThe identifier, which can be referenced in API endpoints.
assistant_idstringIf applicable, the ID of the assistant that authored this message.
run_idstringThe ID of the run associated with the creation of this message. Value is null when messages are created manually using the create message or create thread endpoints.
thread_idstringThe thread ID that this message belongs to.
attachmentsarrayA list of files attached to the message, and the tools they were added to.
completed_atinteger (unixtime)The Unix timestamp (in seconds) for when the message was completed.
contentarrayThe content of the message in array of text and/or images.
created_atinteger (unixtime)The Unix timestamp (in seconds) for when the message was created.
incomplete_atinteger (unixtime)The Unix timestamp (in seconds) for when the message was marked as incomplete.
incomplete_detailsobjectOn an incomplete message, details about why the message is incomplete.
metadataobjectSet 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. (x-oaiTypeLabel: map)
objectstringThe object type, which is always thread.message. (thread.message)
rolestringThe entity that produced the message. One of user or assistant. (user, assistant)
statusstringThe status of the message, which can be either in_progress, incomplete, or completed. (in_progress, incomplete, completed)

Methods

The following methods are available for this resource:

NameAccessible byRequired ParamsOptional ParamsDescription
getselectthread_id, message_idopenai-organization, openai-project
listselectthread_idlimit, order, after, before, run_id, openai-organization, openai-project
createinsertthread_id, role, contentopenai-organization, openai-project
updateupdatethread_id, message_idopenai-organization, openai-project
deletedeletethread_id, message_idopenai-organization, openai-project

Parameters

Parameters can be passed in the WHERE clause of a query. Check the Methods section to see which parameters are required or optional for each operation.

NameDatatypeDescription
message_idstringThe ID of the message to delete.
thread_idstringThe ID of the thread to which this message belongs.
afterstringA 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.
beforestringA 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.
limitintegerA limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. Automatically applied from a SQL LIMIT clause - SELECT ... LIMIT 10 sends limit=10 on the wire. Setting it explicitly in a WHERE clause is not required.
openai-organizationstringOptionally scope the request to a specific organization (overrides the default associated with the API key). Addressable in SQL as openai_organization.
openai-projectstringOptionally scope the request to a specific project (overrides the default associated with the API key). Addressable in SQL as openai_project.
orderstringSort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order.
run_idstringFilter messages by the run ID that generated them.

SELECT examples

OK

SELECT
id,
assistant_id,
run_id,
thread_id,
attachments,
completed_at,
content,
created_at,
incomplete_at,
incomplete_details,
metadata,
object,
role,
status
FROM openai.assistants.messages
WHERE thread_id = '{{ thread_id }}' -- required
AND message_id = '{{ message_id }}' -- required
AND "openai-organization" = '{{ openai-organization }}'
AND "openai-project" = '{{ openai-project }}'
;

INSERT examples

No description available.

INSERT INTO openai.assistants.messages (
role,
content,
attachments,
metadata,
thread_id,
"openai-organization",
"openai-project"
)
SELECT
'{{ role }}' /* required */,
'{{ content }}' /* required */,
'{{ attachments }}',
'{{ metadata }}',
'{{ thread_id }}',
'{{ openai-organization }}',
'{{ openai-project }}'
RETURNING
id,
assistant_id,
run_id,
thread_id,
attachments,
completed_at,
content,
created_at,
incomplete_at,
incomplete_details,
metadata,
object,
role,
status
;

UPDATE examples

No description available.

UPDATE openai.assistants.messages
SET
metadata = '{{ metadata }}'
WHERE
thread_id = '{{ thread_id }}' --required
AND message_id = '{{ message_id }}' --required
AND "openai-organization" = '{{ openai-organization}}'
AND "openai-project" = '{{ openai-project}}'
RETURNING
id,
assistant_id,
run_id,
thread_id,
attachments,
completed_at,
content,
created_at,
incomplete_at,
incomplete_details,
metadata,
object,
role,
status;

DELETE examples

No description available.

DELETE FROM openai.assistants.messages
WHERE thread_id = '{{ thread_id }}' --required
AND message_id = '{{ message_id }}' --required
AND "openai-organization" = '{{ openai-organization }}'
AND "openai-project" = '{{ openai-project }}'
;