Path parameters
-
The ID of the thread to create a message for.
Body 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.
Values are
user
orassistant
. content string | array[object] Required
One of: The text contents of the message.
An array of content parts with a defined type, each can be of type
text
or images can be passed withimage_url
orimage_file
. Image types are only supported on Vision-compatible models.At least
1
element.-
attachments array[object] | null
A list of files attached to the message, and the tools they should be added to.
-
metadata object | null
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. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long.
POST
/threads/{thread_id}/messages
curl \
-X POST https://api.openai.com/v1/threads/{thread_id}/messages \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{"role":"user","content":"string","attachments":[{"file_id":"string","tools":[{"type":"code_interpreter"}]}],"metadata":{}}'
Request example
{
"role": "user",
"content": "string",
"attachments": [
{
"file_id": "string",
"tools": [
{
"type": "code_interpreter"
}
]
}
],
"metadata": {}
}
Response examples (200)
{
"id": "string",
"object": "thread.message",
"created_at": 42,
"thread_id": "string",
"status": "in_progress",
"incomplete_details": {
"reason": "content_filter"
},
"completed_at": 42,
"incomplete_at": 42,
"role": "user",
"content": [
{
"type": "image_file",
"image_file": {
"file_id": "string",
"detail": "auto"
}
}
],
"assistant_id": "string",
"run_id": "string",
"attachments": [
{
"file_id": "string",
"tools": [
{
"type": "code_interpreter"
}
]
}
],
"metadata": {}
}