Class ThreadsEndpoint
Create threads that assistants can interact with.
https://platform.openai.com/docs/api-reference/threads
public sealed class ThreadsEndpoint : OpenAIBaseEndpoint
- Inheritance
-
ThreadsEndpoint
- Inherited Members
Constructors
ThreadsEndpoint(OpenAIClient)
public ThreadsEndpoint(OpenAIClient client)
Parameters
clientOpenAIClient
Properties
Root
The root endpoint address.
protected override string Root { get; }
Property Value
Methods
CancelRunAsync(string, string, CancellationToken)
Cancels a run that is InProgress.
public Task<bool> CancelRunAsync(string threadId, string runId, CancellationToken cancellationToken = default)
Parameters
threadIdstringThe id of the thread to which this run belongs.
runIdstringThe id of the run to cancel.
cancellationTokenCancellationTokenOptional, CancellationToken.
Returns
CreateMessageAsync(string, Message, CancellationToken)
Create a message.
public Task<MessageResponse> CreateMessageAsync(string threadId, Message message, CancellationToken cancellationToken = default)
Parameters
threadIdstringThe id of the thread to create a message for.
messageMessagecancellationTokenCancellationTokenOptional, CancellationToken.
Returns
CreateRunAsync(string, CreateRunRequest, Func<IServerSentEvent, Task>, CancellationToken)
Create a run.
public Task<RunResponse> CreateRunAsync(string threadId, CreateRunRequest request = null, Func<IServerSentEvent, Task> streamEventHandler = null, CancellationToken cancellationToken = default)
Parameters
threadIdstringThe id of the thread to run.
requestCreateRunRequeststreamEventHandlerFunc<IServerSentEvent, Task>Optional, Func<T, TResult> stream callback handler.
cancellationTokenCancellationTokenOptional, CancellationToken.
Returns
CreateRunAsync(string, CreateRunRequest, Func<string, IServerSentEvent, Task>, CancellationToken)
Create a run.
public Task<RunResponse> CreateRunAsync(string threadId, CreateRunRequest request = null, Func<string, IServerSentEvent, Task> streamEventHandler = null, CancellationToken cancellationToken = default)
Parameters
threadIdstringThe id of the thread to run.
requestCreateRunRequeststreamEventHandlerFunc<string, IServerSentEvent, Task>Optional, Func<T1, T2, TResult> stream callback handler.
cancellationTokenCancellationTokenOptional, CancellationToken.
Returns
CreateRunAsync<T>(string, CreateRunRequest, Func<IServerSentEvent, Task>, CancellationToken)
Create a run.
public Task<RunResponse> CreateRunAsync<T>(string threadId, CreateRunRequest request = null, Func<IServerSentEvent, Task> streamEventHandler = null, CancellationToken cancellationToken = default)
Parameters
threadIdstringThe id of the thread to run.
requestCreateRunRequeststreamEventHandlerFunc<IServerSentEvent, Task>Optional, Func<T, TResult> stream callback handler.
cancellationTokenCancellationTokenOptional, CancellationToken.
Returns
Type Parameters
TJsonSchema to use for structured outputs.
CreateThreadAndRunAsync(CreateThreadAndRunRequest, Func<IServerSentEvent, Task>, CancellationToken)
Create a thread and run it in one request.
public Task<RunResponse> CreateThreadAndRunAsync(CreateThreadAndRunRequest request = null, Func<IServerSentEvent, Task> streamEventHandler = null, CancellationToken cancellationToken = default)
Parameters
requestCreateThreadAndRunRequeststreamEventHandlerFunc<IServerSentEvent, Task>Optional, Func<T, TResult> stream callback handler.
cancellationTokenCancellationTokenOptional, CancellationToken.
Returns
CreateThreadAndRunAsync(CreateThreadAndRunRequest, Func<string, IServerSentEvent, Task>, CancellationToken)
Create a thread and run it in one request.
public Task<RunResponse> CreateThreadAndRunAsync(CreateThreadAndRunRequest request = null, Func<string, IServerSentEvent, Task> streamEventHandler = null, CancellationToken cancellationToken = default)
Parameters
requestCreateThreadAndRunRequeststreamEventHandlerFunc<string, IServerSentEvent, Task>Optional, Func<T1, T2, TResult> stream callback handler.
cancellationTokenCancellationTokenOptional, CancellationToken.
Returns
CreateThreadAndRunAsync<T>(CreateThreadAndRunRequest, Func<IServerSentEvent, Task>, CancellationToken)
Create a thread and run it in one request.
public Task<RunResponse> CreateThreadAndRunAsync<T>(CreateThreadAndRunRequest request = null, Func<IServerSentEvent, Task> streamEventHandler = null, CancellationToken cancellationToken = default)
Parameters
requestCreateThreadAndRunRequeststreamEventHandlerFunc<IServerSentEvent, Task>Optional, Func<T, TResult> stream callback handler.
cancellationTokenCancellationTokenOptional, CancellationToken.
Returns
Type Parameters
TJsonSchema to use for structured outputs.
CreateThreadAsync(CreateThreadRequest, CancellationToken)
Create a thread.
public Task<ThreadResponse> CreateThreadAsync(CreateThreadRequest request = null, CancellationToken cancellationToken = default)
Parameters
requestCreateThreadRequestcancellationTokenCancellationTokenOptional, CancellationToken.
Returns
DeleteThreadAsync(string, CancellationToken)
Delete a thread.
public Task<bool> DeleteThreadAsync(string threadId, CancellationToken cancellationToken = default)
Parameters
threadIdstringThe id of the ThreadResponse to delete.
cancellationTokenCancellationTokenOptional, CancellationToken.
Returns
ListMessagesAsync(string, ListQuery, string, CancellationToken)
Returns a list of messages for a given thread.
public Task<ListResponse<MessageResponse>> ListMessagesAsync(string threadId, ListQuery query = null, string runId = null, CancellationToken cancellationToken = default)
Parameters
threadIdstringThe id of the thread the messages belong to.
queryListQueryrunIdstringOptional, filter messages by the run ID that generated them.
cancellationTokenCancellationTokenOptional, CancellationToken.
Returns
ListRunStepsAsync(string, string, ListQuery, CancellationToken)
Returns a list of run steps belonging to a run.
public Task<ListResponse<RunStepResponse>> ListRunStepsAsync(string threadId, string runId, ListQuery query = null, CancellationToken cancellationToken = default)
Parameters
threadIdstringThe id of the thread to which the run and run step belongs.
runIdstringThe id of the run to which the run step belongs.
queryListQueryOptional, ListQuery.
cancellationTokenCancellationTokenOptional, CancellationToken.
Returns
ListRunsAsync(string, ListQuery, CancellationToken)
Returns a list of runs belonging to a thread.
public Task<ListResponse<RunResponse>> ListRunsAsync(string threadId, ListQuery query = null, CancellationToken cancellationToken = default)
Parameters
threadIdstringThe id of the thread the run belongs to.
queryListQuerycancellationTokenCancellationTokenOptional, CancellationToken.
Returns
ModifyMessageAsync(MessageResponse, IReadOnlyDictionary<string, string>, CancellationToken)
Modifies a message.
public Task<MessageResponse> ModifyMessageAsync(MessageResponse message, IReadOnlyDictionary<string, string> metadata, CancellationToken cancellationToken = default)
Parameters
messageMessageResponseMessageResponse to modify.
metadataIReadOnlyDictionary<string, string>Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maximum of 512 characters long.
cancellationTokenCancellationTokenOptional, CancellationToken.
Returns
Remarks
Only the Metadata can be modified.
ModifyMessageAsync(string, string, IReadOnlyDictionary<string, string>, CancellationToken)
Modifies a message.
public Task<MessageResponse> ModifyMessageAsync(string threadId, string messageId, IReadOnlyDictionary<string, string> metadata, CancellationToken cancellationToken = default)
Parameters
threadIdstringThe id of the thread to which this message belongs.
messageIdstringThe id of the message to modify.
metadataIReadOnlyDictionary<string, string>Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maximum of 512 characters long.
cancellationTokenCancellationTokenOptional, CancellationToken.
Returns
Remarks
Only the Metadata can be modified.
ModifyRunAsync(string, string, IReadOnlyDictionary<string, string>, CancellationToken)
Modifies a run.
public Task<RunResponse> ModifyRunAsync(string threadId, string runId, IReadOnlyDictionary<string, string> metadata, CancellationToken cancellationToken = default)
Parameters
threadIdstringThe id of the thread that was run.
runIdstringThe id of the RunResponse to modify.
metadataIReadOnlyDictionary<string, string>Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maximum of 512 characters long.
cancellationTokenCancellationTokenOptional, CancellationToken.
Returns
Remarks
Only the Metadata can be modified.
ModifyThreadAsync(string, IReadOnlyDictionary<string, string>, CancellationToken)
Modifies a thread.
public Task<ThreadResponse> ModifyThreadAsync(string threadId, IReadOnlyDictionary<string, string> metadata, CancellationToken cancellationToken = default)
Parameters
threadIdstringThe id of the ThreadResponse to modify.
metadataIReadOnlyDictionary<string, string>Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maximum of 512 characters long.
cancellationTokenCancellationTokenOptional, CancellationToken.
Returns
Remarks
Only the Metadata can be modified.
RetrieveMessageAsync(string, string, CancellationToken)
Retrieve a message.
public Task<MessageResponse> RetrieveMessageAsync(string threadId, string messageId, CancellationToken cancellationToken = default)
Parameters
threadIdstringThe id of the thread to which this message belongs.
messageIdstringThe id of the message to retrieve.
cancellationTokenCancellationTokenOptional, CancellationToken.
Returns
RetrieveRunAsync(string, string, CancellationToken)
Retrieves a run.
public Task<RunResponse> RetrieveRunAsync(string threadId, string runId, CancellationToken cancellationToken = default)
Parameters
threadIdstringThe id of the thread that was run.
runIdstringThe id of the run to retrieve.
cancellationTokenCancellationTokenOptional, CancellationToken.
Returns
RetrieveRunStepAsync(string, string, string, CancellationToken)
Retrieves a run step.
public Task<RunStepResponse> RetrieveRunStepAsync(string threadId, string runId, string stepId, CancellationToken cancellationToken = default)
Parameters
threadIdstringThe id of the thread to which the run and run step belongs.
runIdstringThe id of the run to which the run step belongs.
stepIdstringThe id of the run step to retrieve.
cancellationTokenCancellationTokenOptional, CancellationToken.
Returns
RetrieveThreadAsync(string, CancellationToken)
Retrieves a thread.
public Task<ThreadResponse> RetrieveThreadAsync(string threadId, CancellationToken cancellationToken = default)
Parameters
threadIdstringThe id of the ThreadResponse to retrieve.
cancellationTokenCancellationTokenOptional, CancellationToken.
Returns
SubmitToolOutputsAsync(string, string, SubmitToolOutputsRequest, Func<IServerSentEvent, Task>, CancellationToken)
When a run has the status: "requires_action" and required_action.type is submit_tool_outputs, this endpoint can be used to submit the outputs from the tool calls once they're all completed. All outputs must be submitted in a single request.
public Task<RunResponse> SubmitToolOutputsAsync(string threadId, string runId, SubmitToolOutputsRequest request, Func<IServerSentEvent, Task> streamEventHandler = null, CancellationToken cancellationToken = default)
Parameters
threadIdstringThe id of the thread to which this run belongs.
runIdstringThe id of the run that requires the tool output submission.
requestSubmitToolOutputsRequeststreamEventHandlerFunc<IServerSentEvent, Task>Optional, Func<T, TResult> stream callback handler.
cancellationTokenCancellationTokenOptional, CancellationToken.
Returns
SubmitToolOutputsAsync(string, string, SubmitToolOutputsRequest, Func<string, IServerSentEvent, Task>, CancellationToken)
When a run has the status: "requires_action" and required_action.type is submit_tool_outputs, this endpoint can be used to submit the outputs from the tool calls once they're all completed. All outputs must be submitted in a single request.
public Task<RunResponse> SubmitToolOutputsAsync(string threadId, string runId, SubmitToolOutputsRequest request, Func<string, IServerSentEvent, Task> streamEventHandler = null, CancellationToken cancellationToken = default)
Parameters
threadIdstringThe id of the thread to which this run belongs.
runIdstringThe id of the run that requires the tool output submission.
requestSubmitToolOutputsRequeststreamEventHandlerFunc<string, IServerSentEvent, Task>Optional, Func<T1, T2, TResult> stream callback handler.
cancellationTokenCancellationTokenOptional, CancellationToken.