Create message
Create a message.
Path ParametersExpandCollapse
Body ParametersJSONExpandCollapse
content:string orarray ofImageFileContentBlock {image_file,type } orImageURLContentBlock {image_url,type } orTextContentBlockParam {text,type }The text contents of the message.
The text contents of the message.
The text contents of the message.
ArrayOfContentParts =array ofImageFileContentBlock {image_file,type } orImageURLContentBlock {image_url,type } orTextContentBlockParam {text,type }An array of content parts with a defined type, each can be of typetext or images can be passed withimage_url orimage_file. Image types are only supported onVision-compatible models.
An array of content parts with a defined type, each can be of typetext or images can be passed withimage_url orimage_file. Image types are only supported onVision-compatible models.
ImageFileContentBlock =object {image_file,type}References an imageFile in the content of a message.
References an imageFile in the content of a message.
TheFile ID of the image in the message content. Setpurpose="vision" when uploading the File if you need to later display the file content.
detail:optional"auto" or"low" or"high"Specifies the detail level of the image if specified by the user.low uses fewer tokens, you can opt in to high resolution usinghigh.
Specifies the detail level of the image if specified by the user.low uses fewer tokens, you can opt in to high resolution usinghigh.
Alwaysimage_file.
ImageURLContentBlock =object {image_url,type}References an image URL in the content of a message.
References an image URL in the content of a message.
The external URL of the image, must be a supported image types: jpeg, jpg, png, gif, webp.
detail:optional"auto" or"low" or"high"Specifies the detail level of the image.low uses fewer tokens, you can opt in to high resolution usinghigh. Default value isauto
Specifies the detail level of the image.low uses fewer tokens, you can opt in to high resolution usinghigh. Default value isauto
The type of the content part.
TextContentBlockParam =object {text,type}The text content that is part of a message.
The text content that is part of a message.
Text content to be sent to the model
Alwaystext.
role:"user" or"assistant"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.
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.
attachments:optionalarray ofobject {file_id,tools}A list of files attached to the message, and the tools they should be added to.
A list of files attached to the message, and the tools they should be added to.
The ID of the file to attach to the message.
The tools to add this file to.
The tools to add this file to.
CodeInterpreterTool =object {type}
The type of tool being defined:code_interpreter
FileSearchTool =object {type}
The type of tool being defined:file_search
Set of 16 key-value pairs that can be attached to an object. This can beuseful for storing additional information about the object in a structuredformat, and querying for objects via API or the dashboard.
Keys are strings with a maximum length of 64 characters. Values are stringswith a maximum length of 512 characters.
ReturnsExpandCollapse
Message =object {id,assistant_id,attachments,11 more}Represents a message within athread.
Represents a message within athread.
The identifier, which can be referenced in API endpoints.
If applicable, the ID of theassistant that authored this message.
attachments:array ofobject {file_id,tools}A list of files attached to the message, and the tools they were added to.
A list of files attached to the message, and the tools they were added to.
The ID of the file to attach to the message.
The tools to add this file to.
The tools to add this file to.
CodeInterpreterTool =object {type}
The type of tool being defined:code_interpreter
FileSearchTool =object {type}
The type of tool being defined:file_search
The Unix timestamp (in seconds) for when the message was completed.
content:array ofImageFileContentBlock {image_file,type } orImageURLContentBlock {image_url,type } orTextContentBlock {text,type } orRefusalContentBlock {refusal,type }The content of the message in array of text and/or images.
The content of the message in array of text and/or images.
ImageFileContentBlock =object {image_file,type}References an imageFile in the content of a message.
References an imageFile in the content of a message.
TheFile ID of the image in the message content. Setpurpose="vision" when uploading the File if you need to later display the file content.
detail:optional"auto" or"low" or"high"Specifies the detail level of the image if specified by the user.low uses fewer tokens, you can opt in to high resolution usinghigh.
Specifies the detail level of the image if specified by the user.low uses fewer tokens, you can opt in to high resolution usinghigh.
Alwaysimage_file.
ImageURLContentBlock =object {image_url,type}References an image URL in the content of a message.
References an image URL in the content of a message.
The external URL of the image, must be a supported image types: jpeg, jpg, png, gif, webp.
detail:optional"auto" or"low" or"high"Specifies the detail level of the image.low uses fewer tokens, you can opt in to high resolution usinghigh. Default value isauto
Specifies the detail level of the image.low uses fewer tokens, you can opt in to high resolution usinghigh. Default value isauto
The type of the content part.
TextContentBlock =object {text,type}The text content that is part of a message.
The text content that is part of a message.
annotations:array ofFileCitationAnnotation {end_index,file_citation,start_index,2 more } orFilePathAnnotation {end_index,file_path,start_index,2 more }
FileCitationAnnotation =object {end_index,file_citation,start_index,2 more}A citation within the message that points to a specific quote from a specific File associated with the assistant or the message. Generated when the assistant uses the "file_search" tool to search files.
A citation within the message that points to a specific quote from a specific File associated with the assistant or the message. Generated when the assistant uses the "file_search" tool to search files.
file_citation:object {file_id}
The ID of the specific File the citation is from.
The text in the message content that needs to be replaced.
Alwaysfile_citation.
FilePathAnnotation =object {end_index,file_path,start_index,2 more}A URL for the file that's generated when the assistant used thecode_interpreter tool to generate a file.
A URL for the file that's generated when the assistant used thecode_interpreter tool to generate a file.
file_path:object {file_id}
The ID of the file that was generated.
The text in the message content that needs to be replaced.
Alwaysfile_path.
The data that makes up the text.
Alwaystext.
RefusalContentBlock =object {refusal,type}The refusal content generated by the assistant.
The refusal content generated by the assistant.
Alwaysrefusal.
The Unix timestamp (in seconds) for when the message was created.
The Unix timestamp (in seconds) for when the message was marked as incomplete.
incomplete_details:object {reason}On an incomplete message, details about why the message is incomplete.
On an incomplete message, details about why the message is incomplete.
reason:"content_filter" or"max_tokens" or"run_cancelled" or2 moreThe reason the message is incomplete.
The reason the message is incomplete.
Set of 16 key-value pairs that can be attached to an object. This can beuseful for storing additional information about the object in a structuredformat, and querying for objects via API or the dashboard.
Keys are strings with a maximum length of 64 characters. Values are stringswith a maximum length of 512 characters.
The object type, which is alwaysthread.message.
role:"user" or"assistant"The entity that produced the message. One ofuser orassistant.
The entity that produced the message. One ofuser orassistant.
The ID of therun associated with the creation of this message. Value isnull when messages are created manually using the create message or create thread endpoints.
status:"in_progress" or"incomplete" or"completed"The status of the message, which can be eitherin_progress,incomplete, orcompleted.
The status of the message, which can be eitherin_progress,incomplete, orcompleted.
Thethread ID that this message belongs to.
Create message
curl https://api.openai.com/v1/threads/thread_abc123/messages \ -H "Content-Type: application/json" \ -H "Authorization: Bearer$OPENAI_API_KEY" \ -H "OpenAI-Beta: assistants=v2" \ -d '{ "role": "user", "content": "How does AI work? Explain it in simple terms." }'{ "id":"msg_abc123", "object":"thread.message", "created_at":1713226573, "assistant_id":null, "thread_id":"thread_abc123", "run_id":null, "role":"user", "content": [ { "type":"text", "text": { "value":"How does AI work? Explain it in simple terms.", "annotations": [] } } ], "attachments": [], "metadata": {}}Returns Examples
{ "id":"msg_abc123", "object":"thread.message", "created_at":1713226573, "assistant_id":null, "thread_id":"thread_abc123", "run_id":null, "role":"user", "content": [ { "type":"text", "text": { "value":"How does AI work? Explain it in simple terms.", "annotations": [] } } ], "attachments": [], "metadata": {}}