OpenAI Responses API Conversations
The OpenAI Responses API Conversations surface 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 ResponsesDirect link to Relationship 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 exampleDirect link to Usage 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)
MethodsDirect link to Methods
LifecycleDirect link to Lifecycle
create(params)Direct link to 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?)Direct link to 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?)Direct link to deleteconversationid-requestcontext
Deletes a conversation by its thread ID.
const deleted = await client.conversations.delete('thread_123')
console.log(deleted.deleted)
Returns: Promise<ConversationDeleted>.
ItemsDirect link to Items
items.list(conversationId, requestContext?)Direct link to 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 shapeDirect link to Response 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: Whether more items exist beyond the current page