ConversationsResource class
Resource for conversations operations.
The Conversations API provides server-side conversation state management for the Responses API. This allows creating, storing, and retrieving conversation items without the 30-day TTL.
Example
// Create a conversation
final conversation = await client.conversations.create(
ConversationCreateRequest(
items: [MessageItem.userText('Hello!')],
metadata: {'user_id': 'user_123'},
),
);
// Use with Responses API
final response = await client.responses.create(
CreateResponseRequest(
model: 'gpt-4o',
input: ResponseInput.text('Continue our conversation'),
),
);
// Add items to the conversation
await client.conversations.items.create(
conversation.id,
ItemsCreateRequest(items: [
MessageItem.userText('What is the weather?'),
]),
);
// List conversation items
final items = await client.conversations.items.list(conversation.id);
// Clean up
await client.conversations.delete(conversation.id);
- Inheritance
-
- Object
- ResourceBase
- ConversationsResource
Constructors
- ConversationsResource({required OpenAIConfig config, required Client httpClient, required InterceptorChain interceptorChain, required RequestBuilder requestBuilder, void ensureNotClosed()?})
- Creates a ConversationsResource.
Properties
- config → OpenAIConfig
-
Client configuration.
finalinherited
- ensureNotClosed → void Function()?
-
Callback to check if the client has been closed.
finalinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
- httpClient → Client
-
HTTP client for making requests.
finalinherited
- interceptorChain → InterceptorChain
-
Interceptor chain for request/response processing.
finalinherited
- items → ConversationItemsResource
-
Access to conversation items operations.
no setter
- requestBuilder → RequestBuilder
-
Request builder for constructing HTTP requests.
finalinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- streamClientFactory → Client Function()?
-
Factory for creating dedicated HTTP clients for streaming requests.
finalinherited
Methods
-
create(
ConversationCreateRequest request, {Future< void> ? abortTrigger}) → Future<Conversation> - Creates a new conversation.
-
delete(
String conversationId, {Future< void> ? abortTrigger}) → Future<ConversationDeletedResource> - Deletes a conversation.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
retrieve(
String conversationId, {Future< void> ? abortTrigger}) → Future<Conversation> - Retrieves a conversation by ID.
-
toString(
) → String -
A string representation of this object.
inherited
-
update(
String conversationId, ConversationUpdateRequest request, {Future< void> ? abortTrigger}) → Future<Conversation> - Updates a conversation.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited