Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Openai Openai node Beta Threads Messages

From Leeroopedia
Revision as of 13:35, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Openai_Openai_node_Beta_Threads_Messages.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains SDK, Assistants, Threads, Beta
Last Updated 2026-02-15 12:00 GMT

Overview

The Beta Threads Messages resource class provides deprecated methods to create, retrieve, update, list, and delete messages within assistant threads.

Description

The Messages class extends APIResource and is marked @deprecated in favor of the Responses API. It provides five CRUD methods -- create, retrieve, update, list, and delete -- that map to the /threads/{threadID}/messages REST endpoints. Each method automatically injects the OpenAI-Beta: assistants=v2 header.

The file defines the Message interface, which represents a message within a thread. Messages have properties including id, role (user or assistant), content (an array of MessageContent items), status (in_progress, incomplete, completed), attachments, metadata, and various timestamp fields. Message content is a union type of ImageFileContentBlock, ImageURLContentBlock, TextContentBlock, and RefusalContentBlock.

The file also defines annotation types (FileCitationAnnotation, FilePathAnnotation, and their delta counterparts) for file citations generated by the file_search tool and file paths generated by the code_interpreter tool. Delta types (MessageDelta, MessageDeltaEvent, MessageContentDelta) are provided for streaming support. Image handling types (ImageFile, ImageURL, and their delta counterparts) support both uploaded file references and external URL references with configurable detail levels (auto, low, high).

Usage

Use this resource to manage messages within assistant threads. Access it via client.beta.threads.messages. This API is deprecated in favor of the Responses API.

Code Reference

Source Location

Signature

/** @deprecated The Assistants API is deprecated in favor of the Responses API */
export class Messages extends APIResource {
  create(threadID: string, body: MessageCreateParams, options?: RequestOptions): APIPromise<Message>;

  retrieve(messageID: string, params: MessageRetrieveParams, options?: RequestOptions): APIPromise<Message>;

  update(messageID: string, params: MessageUpdateParams, options?: RequestOptions): APIPromise<Message>;

  list(
    threadID: string,
    query?: MessageListParams | null | undefined,
    options?: RequestOptions,
  ): PagePromise<MessagesPage, Message>;

  delete(messageID: string, params: MessageDeleteParams, options?: RequestOptions): APIPromise<MessageDeleted>;
}

Import

import OpenAI from 'openai';
// Access via client.beta.threads.messages

I/O Contract

Inputs

Name Type Required Description
threadID string Yes The thread ID containing the messages
content Array<MessageContentPartParam> Yes (create) The text or multipart content of the message
role 'assistant' Yes (create) The role of the entity creating the message
attachments null No Files attached to the message with associated tools
metadata null No Up to 16 key-value pairs for structured metadata
thread_id string Yes (retrieve/update/delete) The thread ID (in params for retrieve, update, delete)
before string No (list) Cursor for pagination
order 'desc' No (list) Sort order by created_at timestamp
run_id string No (list) Filter messages by run ID

Outputs

Name Type Description
Message Message A thread message with id, role, content, status, attachments, and metadata
MessagesPage CursorPage<Message> Paginated list of message objects
MessageDeleted MessageDeleted Confirmation with id, deleted boolean, and object type
MessageDeltaEvent MessageDeltaEvent Streaming delta event containing changed fields

Usage Examples

Basic Usage

import OpenAI from 'openai';

const client = new OpenAI();

// Create a message in a thread
const message = await client.beta.threads.messages.create('thread_abc123', {
  role: 'user',
  content: 'How do I solve this equation: 3x + 11 = 14?',
});

// List messages in a thread
const messages = await client.beta.threads.messages.list('thread_abc123', {
  order: 'asc',
});

// Retrieve a specific message
const retrieved = await client.beta.threads.messages.retrieve('msg_abc123', {
  thread_id: 'thread_abc123',
});

// Update message metadata
const updated = await client.beta.threads.messages.update('msg_abc123', {
  thread_id: 'thread_abc123',
  metadata: { reviewed: 'true' },
});

// Delete a message
const deleted = await client.beta.threads.messages.delete('msg_abc123', {
  thread_id: 'thread_abc123',
});

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment