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 Conversation Items Resource

From Leeroopedia
Knowledge Sources
Domains SDK, Conversations
Last Updated 2026-02-15 12:00 GMT

Overview

The Items class is the Conversation Items resource in the openai-node SDK, providing methods to create, retrieve, list, and delete items within a conversation.

Description

The Items class extends APIResource and wraps the /conversations/{conversationID}/items REST endpoints. It is accessed via client.conversations.items and provides CRUD operations for managing individual items within a conversation context. A conversation item can represent many different types including messages, function tool calls, function tool call outputs, file search calls, web search calls, image generation calls, computer tool calls, reasoning items, code interpreter calls, shell calls, MCP tool calls, and more.

The create method allows adding up to 20 items at a time to a conversation, accepting an array of ResponseInputItem objects and an optional include query parameter. The retrieve method fetches a single item by ID given the conversation ID. The list method paginates items within a conversation using a ConversationCursorPage, supporting include, order, and pagination parameters. The delete method removes an item from a conversation and returns the updated Conversation object.

The ConversationItem type is a union of over 20 different item types from the Responses API, including Message, ResponseFunctionToolCallItem, ResponseFileSearchToolCall, ResponseReasoningItem, ResponseCodeInterpreterToolCall, McpCall, and many others. The ConversationItemList type wraps a list response with data, first_id, last_id, has_more, and object fields.

Usage

Use this resource when you need to manage individual items within a conversation, such as adding new messages, retrieving specific tool call results, listing all items in a conversation history, or removing items.

Code Reference

Source Location

Signature

export class Items extends APIResource {
  create(
    conversationID: string,
    params: ItemCreateParams,
    options?: RequestOptions,
  ): APIPromise<ConversationItemList>;

  retrieve(
    itemID: string,
    params: ItemRetrieveParams,
    options?: RequestOptions,
  ): APIPromise<ConversationItem>;

  list(
    conversationID: string,
    query?: ItemListParams | null,
    options?: RequestOptions,
  ): PagePromise<ConversationItemsPage, ConversationItem>;

  delete(
    itemID: string,
    params: ItemDeleteParams,
    options?: RequestOptions,
  ): APIPromise<Conversation>;
}

Import

import OpenAI from 'openai';
// Access via client.conversations.items

I/O Contract

Inputs

Name Type Required Description
conversationID (create/list) string Yes The ID of the conversation to add items to or list items from
items (create) Array<ResponseInputItem> Yes The items to add (up to 20 at a time)
include (create/retrieve/list) Array<ResponseIncludable> No Additional fields to include in the response (e.g., web_search sources, code outputs, logprobs)
itemID (retrieve/delete) string Yes The ID of the item to retrieve or delete
conversation_id (retrieve/delete) string Yes The ID of the conversation containing the item
order (list) 'desc' No Sort order for items (default 'desc')

Outputs

Name Type Description
ConversationItemList ConversationItemList List response with data (array of ConversationItem), first_id, last_id, has_more, object
ConversationItem ConversationItem Union type representing any conversation item (Message, tool calls, reasoning items, etc.)
ConversationItemsPage ConversationCursorPage<ConversationItem> Paginated cursor page of conversation items
Conversation Conversation The updated conversation object (returned by delete)

Usage Examples

import OpenAI from 'openai';

const client = new OpenAI();

const conversationId = 'conv_abc123';

// Create items in a conversation
const result = await client.conversations.items.create(conversationId, {
  items: [
    { type: 'message', role: 'user', content: [{ type: 'input_text', text: 'Hello!' }] },
  ],
});
console.log(result.data);

// List all items in a conversation
for await (const item of client.conversations.items.list(conversationId, { order: 'asc' })) {
  console.log(item.type, item.id);
}

// Retrieve a specific item
const item = await client.conversations.items.retrieve('item_xyz789', {
  conversation_id: conversationId,
});
console.log(item);

// Delete an item from a conversation
const updated = await client.conversations.items.delete('item_xyz789', {
  conversation_id: conversationId,
});

Related Pages

Page Connections

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