Skip to content

Create message

Deprecated
POST/threads/{thread_id}/messages

Create a message.

Path ParametersExpand Collapse
thread_id: string
Body ParametersJSONExpand Collapse
content: string or array of ImageFileContentBlock { image_file, type } or ImageURLContentBlock { image_url, type } or TextContentBlockParam { text, type }

The text contents of the message.

Accepts one of the following:
TextContent = string

The text contents of the message.

ArrayOfContentParts = array of ImageFileContentBlock { image_file, type } or ImageURLContentBlock { image_url, type } or TextContentBlockParam { text, type }

An array of content parts with a defined type, each can be of type text or images can be passed with image_url or image_file. Image types are only supported on Vision-compatible models.

Accepts one of the following:
ImageFileContentBlock = object { image_file, type }

References an image File in the content of a message.

image_file: ImageFile { file_id, detail }
file_id: string

The File ID of the image in the message content. Set purpose="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 using high.

Accepts one of the following:
"auto"
"low"
"high"
type: "image_file"

Always image_file.

ImageURLContentBlock = object { image_url, type }

References an image URL in the content of a message.

image_url: ImageURL { url, detail }
url: string

The external URL of the image, must be a supported image types: jpeg, jpg, png, gif, webp.

formaturi
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 using high. Default value is auto

Accepts one of the following:
"auto"
"low"
"high"
type: "image_url"

The type of the content part.

TextContentBlockParam = object { text, type }

The text content that is part of a message.

text: string

Text content to be sent to the model

type: "text"

Always text.

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.
Accepts one of the following:
"user"
"assistant"
attachments: optional array of object { file_id, tools }

A list of files attached to the message, and the tools they should be added to.

file_id: optional string

The ID of the file to attach to the message.

tools: optional array of CodeInterpreterTool { type } or object { type }

The tools to add this file to.

Accepts one of the following:
CodeInterpreterTool = object { type }
type: "code_interpreter"

The type of tool being defined: code_interpreter

FileSearchTool = object { type }
type: "file_search"

The type of tool being defined: file_search

metadata: optional 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.

ReturnsExpand Collapse
Message = object { id, assistant_id, attachments, 11 more }

Represents a message within a thread.

id: string

The identifier, which can be referenced in API endpoints.

assistant_id: string

If applicable, the ID of the assistant that authored this message.

attachments: array of object { file_id, tools }

A list of files attached to the message, and the tools they were added to.

file_id: optional string

The ID of the file to attach to the message.

tools: optional array of CodeInterpreterTool { type } or object { type }

The tools to add this file to.

Accepts one of the following:
CodeInterpreterTool = object { type }
type: "code_interpreter"

The type of tool being defined: code_interpreter

FileSearchTool = object { type }
type: "file_search"

The type of tool being defined: file_search

completed_at: number

The Unix timestamp (in seconds) for when the message was completed.

content: array of ImageFileContentBlock { image_file, type } or ImageURLContentBlock { image_url, type } or TextContentBlock { text, type } or RefusalContentBlock { refusal, type }

The content of the message in array of text and/or images.

Accepts one of the following:
ImageFileContentBlock = object { image_file, type }

References an image File in the content of a message.

image_file: ImageFile { file_id, detail }
file_id: string

The File ID of the image in the message content. Set purpose="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 using high.

Accepts one of the following:
"auto"
"low"
"high"
type: "image_file"

Always image_file.

ImageURLContentBlock = object { image_url, type }

References an image URL in the content of a message.

image_url: ImageURL { url, detail }
url: string

The external URL of the image, must be a supported image types: jpeg, jpg, png, gif, webp.

formaturi
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 using high. Default value is auto

Accepts one of the following:
"auto"
"low"
"high"
type: "image_url"

The type of the content part.

TextContentBlock = object { text, type }

The text content that is part of a message.

text: Text { annotations, value }
annotations: array of FileCitationAnnotation { end_index, file_citation, start_index, 2 more } or FilePathAnnotation { end_index, file_path, start_index, 2 more }
Accepts one of the following:
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.

end_index: number
minimum0
file_citation: object { file_id }
file_id: string

The ID of the specific File the citation is from.

start_index: number
minimum0
text: string

The text in the message content that needs to be replaced.

type: "file_citation"

Always file_citation.

FilePathAnnotation = object { end_index, file_path, start_index, 2 more }

A URL for the file that's generated when the assistant used the code_interpreter tool to generate a file.

end_index: number
minimum0
file_path: object { file_id }
file_id: string

The ID of the file that was generated.

start_index: number
minimum0
text: string

The text in the message content that needs to be replaced.

type: "file_path"

Always file_path.

value: string

The data that makes up the text.

type: "text"

Always text.

RefusalContentBlock = object { refusal, type }

The refusal content generated by the assistant.

refusal: string
type: "refusal"

Always refusal.

created_at: number

The Unix timestamp (in seconds) for when the message was created.

incomplete_at: number

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.

reason: "content_filter" or "max_tokens" or "run_cancelled" or 2 more

The reason the message is incomplete.

Accepts one of the following:
"content_filter"
"max_tokens"
"run_cancelled"
"run_expired"
"run_failed"
metadata: 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.

object: "thread.message"

The object type, which is always thread.message.

role: "user" or "assistant"

The entity that produced the message. One of user or assistant.

Accepts one of the following:
"user"
"assistant"
run_id: string

The 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.

status: "in_progress" or "incomplete" or "completed"

The status of the message, which can be either in_progress, incomplete, or completed.

Accepts one of the following:
"in_progress"
"incomplete"
"completed"
thread_id: string

The thread ID that this message belongs to.

Create message

curl https://api.openai.com/v1/threads/$THREAD_ID/messages \
    -H 'Content-Type: application/json' \
    -H 'OpenAI-Beta: assistants=v2' \
    -H "Authorization: Bearer $OPENAI_API_KEY" \
    -d '{
          "content": "string",
          "role": "user"
        }'
{
  "id": "id",
  "assistant_id": "assistant_id",
  "attachments": [
    {
      "file_id": "file_id",
      "tools": [
        {
          "type": "code_interpreter"
        }
      ]
    }
  ],
  "completed_at": 0,
  "content": [
    {
      "image_file": {
        "file_id": "file_id",
        "detail": "auto"
      },
      "type": "image_file"
    }
  ],
  "created_at": 0,
  "incomplete_at": 0,
  "incomplete_details": {
    "reason": "content_filter"
  },
  "metadata": {
    "foo": "string"
  },
  "object": "thread.message",
  "role": "user",
  "run_id": "run_id",
  "status": "in_progress",
  "thread_id": "thread_id"
}
Returns Examples
{
  "id": "id",
  "assistant_id": "assistant_id",
  "attachments": [
    {
      "file_id": "file_id",
      "tools": [
        {
          "type": "code_interpreter"
        }
      ]
    }
  ],
  "completed_at": 0,
  "content": [
    {
      "image_file": {
        "file_id": "file_id",
        "detail": "auto"
      },
      "type": "image_file"
    }
  ],
  "created_at": 0,
  "incomplete_at": 0,
  "incomplete_details": {
    "reason": "content_filter"
  },
  "metadata": {
    "foo": "string"
  },
  "object": "thread.message",
  "role": "user",
  "run_id": "run_id",
  "status": "in_progress",
  "thread_id": "thread_id"
}