Skip to content
Primary navigation

Modify message

Deprecated
client.Beta.Threads.Messages.Update(ctx, threadID, messageID, body) (*Message, error)
POST/threads/{thread_id}/messages/{message_id}

Modifies a message.

ParametersExpand Collapse
threadID string
messageID string
body BetaThreadMessageUpdateParams
Metadata param.Field[Metadata]optional

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
type Message struct{…}

Represents a message within a thread.

ID string

The identifier, which can be referenced in API endpoints.

AssistantID string

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

Attachments []MessageAttachment

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

FileID stringoptional

The ID of the file to attach to the message.

Tools []MessageAttachmentToolUnionoptional

The tools to add this file to.

Accepts one of the following:
type CodeInterpreterTool struct{…}
Type CodeInterpreter

The type of tool being defined: code_interpreter

type MessageAttachmentToolAssistantToolsFileSearchTypeOnly struct{…}
Type FileSearch

The type of tool being defined: file_search

CompletedAt int64

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

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

Accepts one of the following:
type ImageFileContentBlock struct{…}

References an image File in the content of a message.

ImageFile ImageFile
FileID 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 ImageFileDetailoptional

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:
const ImageFileDetailAuto ImageFileDetail = "auto"
const ImageFileDetailLow ImageFileDetail = "low"
const ImageFileDetailHigh ImageFileDetail = "high"
Type ImageFile

Always image_file.

type ImageURLContentBlock struct{…}

References an image URL in the content of a message.

ImageURL ImageURL
URL string

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

formaturi
Detail ImageURLDetailoptional

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:
const ImageURLDetailAuto ImageURLDetail = "auto"
const ImageURLDetailLow ImageURLDetail = "low"
const ImageURLDetailHigh ImageURLDetail = "high"
Type ImageURL

The type of the content part.

type TextContentBlock struct{…}

The text content that is part of a message.

Text Text
Annotations []AnnotationUnion
Accepts one of the following:
type FileCitationAnnotation struct{…}

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.

EndIndex int64
minimum0
FileCitation FileCitationAnnotationFileCitation
FileID string

The ID of the specific File the citation is from.

StartIndex int64
minimum0
Text string

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

Type FileCitation

Always file_citation.

type FilePathAnnotation struct{…}

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

EndIndex int64
minimum0
FilePath FilePathAnnotationFilePath
FileID string

The ID of the file that was generated.

StartIndex int64
minimum0
Text string

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

Type FilePath

Always file_path.

Value string

The data that makes up the text.

Type Text

Always text.

type RefusalContentBlock struct{…}

The refusal content generated by the assistant.

Refusal string
Type Refusal

Always refusal.

CreatedAt int64

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

IncompleteAt int64

The Unix timestamp (in seconds) for when the message was marked as incomplete.

IncompleteDetails MessageIncompleteDetails

On an incomplete message, details about why the message is incomplete.

Reason string

The reason the message is incomplete.

Accepts one of the following:
const MessageIncompleteDetailsReasonContentFilter MessageIncompleteDetailsReason = "content_filter"
const MessageIncompleteDetailsReasonMaxTokens MessageIncompleteDetailsReason = "max_tokens"
const MessageIncompleteDetailsReasonRunCancelled MessageIncompleteDetailsReason = "run_cancelled"
const MessageIncompleteDetailsReasonRunExpired MessageIncompleteDetailsReason = "run_expired"
const MessageIncompleteDetailsReasonRunFailed MessageIncompleteDetailsReason = "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 ThreadMessage

The object type, which is always thread.message.

Role MessageRole

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

Accepts one of the following:
const MessageRoleUser MessageRole = "user"
const MessageRoleAssistant MessageRole = "assistant"
RunID 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 MessageStatus

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

Accepts one of the following:
const MessageStatusInProgress MessageStatus = "in_progress"
const MessageStatusIncomplete MessageStatus = "incomplete"
const MessageStatusCompleted MessageStatus = "completed"
ThreadID string

The thread ID that this message belongs to.

Modify message

package main

import (
  "context"
  "fmt"

  "github.com/openai/openai-go"
  "github.com/openai/openai-go/option"
)

func main() {
  client := openai.NewClient(
    option.WithAPIKey("My API Key"),
  )
  message, err := client.Beta.Threads.Messages.Update(
    context.TODO(),
    "thread_id",
    "message_id",
    openai.BetaThreadMessageUpdateParams{

    },
  )
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", message.ID)
}
{
  "id": "msg_abc123",
  "object": "thread.message",
  "created_at": 1699017614,
  "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": []
      }
    }
  ],
  "file_ids": [],
  "metadata": {
    "modified": "true",
    "user": "abc123"
  }
}
Returns Examples
{
  "id": "msg_abc123",
  "object": "thread.message",
  "created_at": 1699017614,
  "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": []
      }
    }
  ],
  "file_ids": [],
  "metadata": {
    "modified": "true",
    "user": "abc123"
  }
}