OpenAI Responses API Conversations
The OpenAI Responses API Conversations surface gives you the conversation-management side of Mastra Agents as a Responses API. It provides methods to create, retrieve, delete, and inspect thread-backed conversations in Mastra.
This API follows up on the OpenAI Responses API. Stored Responses calls return conversation_id, and in Mastra that value is the raw memory threadId. Use client.conversations when you want to work with that thread directly.
This API is currently experimental.
Relationship to OpenAI ResponsesRelationship to OpenAI Responses的直接链接
Use the OpenAI Responses API for generation and continuation:
const response = await client.responses.create({
agent_id: 'support-agent',
input: 'Start a support thread',
store: true,
})
console.log(response.conversation_id)
Use the Conversations API when you want to inspect or manage that stored thread:
const conversation = await client.conversations.retrieve(response.conversation_id!)
const items = await client.conversations.items.list(response.conversation_id!)
Usage exampleUsage example的直接链接
import { MastraClient } from '@mastra/client-js'
const client = new MastraClient({
baseUrl: 'http://localhost:4111',
})
const conversation = await client.conversations.create({
agent_id: 'support-agent',
})
console.log(conversation.id)
MethodsMethods的直接链接
LifecycleLifecycle的直接链接
create(params)createparams的直接链接
Creates a new conversation thread for the selected agent.
const conversation = await client.conversations.create({
agent_id: 'support-agent',
title: 'Billing support',
})
Returns: Promise<Conversation>.
retrieve(conversationId, requestContext?)retrieveconversationid-requestcontext的直接链接
Retrieves a conversation by its thread ID.
const conversation = await client.conversations.retrieve('thread_123')
console.log(conversation.thread)
Returns: Promise<Conversation>.
delete(conversationId, requestContext?)deleteconversationid-requestcontext的直接链接
Deletes a conversation by its thread ID.
const deleted = await client.conversations.delete('thread_123')
console.log(deleted.deleted)
Returns: Promise<ConversationDeleted>.
ItemsItems的直接链接
items.list(conversationId, requestContext?)itemslistconversationid-requestcontext的直接链接
Lists the stored items for a conversation.
const items = await client.conversations.items.list('thread_123')
console.log(items.data)
Returns: Promise<ConversationItemsPage>.
Response shapeResponse shape的直接链接
create() and retrieve() return a conversation object with:
id: The raw thread IDobject: Always'conversation'thread: The stored thread record
delete() returns:
id: The raw thread IDobject: Always'conversation.deleted'deleted: Alwaystrue
items.list() returns:
object: Always'list'data: Conversation items such asmessage,function_call, andfunction_call_outputfirst_id: The first item ID in the pagelast_id: The last item ID in the pagehas_more: Currently alwaysfalse.items.list()returns up to 1000 items in a single response.