Class AssistantsAPIv2
The Assistants API allows you to build AI assistants within your own applications.
An Assistant has instructions and can leverage models, tools, and files to respond to user queries.
The Assistants API currently supports three types of tools: Code Interpreter, File Search, and Function calling.
Inheritance
object
AssistantsAPIv2
Assembly: .dll
Syntax
public sealed class AssistantsAPIv2
Constructors
AssistantsAPIv2(AssistantOptions, RunRequest, string, string)
Declaration
public AssistantsAPIv2(AssistantOptions options, RunRequest defaultRunOptions = null, string overrideThreadId = null, string overrideAssistantId = null)
Parameters
Fields
MIN_INTERNAL_OPERATION_MILLIS
The minimum interval between operations in milliseconds.
Declaration
public const int MIN_INTERNAL_OPERATION_MILLIS = 1000
Field Value
MIN_INTERVAL_REQUEST_MILLIS
The minimum interval between requests in milliseconds.
Declaration
public const int MIN_INTERVAL_REQUEST_MILLIS = 2000
Field Value
Properties
Assistant
Current assistant object used by this tool.
Declaration
public Assistant Assistant { get; set; }
Property Value
AssistantFetchCount
Gets or sets the assistant fetch count.
Declaration
public int AssistantFetchCount { get; set; }
Property Value
AssistantId
Gets or sets the current assistant ID.
Declaration
public string AssistantId { get; set; }
Property Value
AssistantStatus
Gets the current stage of the Assistants API.
Declaration
public AssistantStatus AssistantStatus { get; }
Property Value
Client
Gets the OpenAiClient instance used by this tool.
Declaration
public OpenAI Client { get; }
Property Value
DefaultRunRequest
Gets or sets the default run request options for this tool.
Declaration
public RunRequest DefaultRunRequest { get; set; }
Property Value
Description
Gets or sets the description of this assistant.
Declaration
public string Description { get; set; }
Property Value
EventHandler
Gets or sets the event handler for assistant-related events.
Declaration
public AssistantEventHandler EventHandler { get; set; }
Property Value
EventStreamHandler
Gets or sets the event stream handler for assistant-related events.
Declaration
public IAssistantEventStreamHandler EventStreamHandler { get; set; }
Property Value
If not null, it forces this AssistantsAPI to use a specific tool on every request.
Declaration
public ToolChoice ForcedTool { get; set; }
Property Value
Id
Local unique identifier for this AssistantsAPI.
This has nothing to do with OpenAI api.
Declaration
public string Id { get; set; }
Property Value
Instructions
Gets or sets the instructions for this assistant.
Declaration
public string Instructions { get; set; }
Property Value
IsBusy
Indicates whether the AssistantsAPI is busy.
Declaration
public bool IsBusy { get; }
Property Value
IsInitialized
Indicates whether the AssistantsAPI instance is initialized.
Declaration
public bool IsInitialized { get; }
Property Value
LastAssistantMessage
Last assistant message received from the AssistantsAPI.
Declaration
public ThreadMessage LastAssistantMessage { get; }
Property Value
LastRequest
Last request object sent to the AssistantsAPI.
Declaration
public ThreadMessageRequest LastRequest { get; }
Property Value
Last tool message received from the AssistantsAPI.
Declaration
public ThreadMessage LastToolMessage { get; }
Property Value
LastUserMessage
Last user message sent to the AssistantsAPI.
Declaration
public ThreadMessage LastUserMessage { get; }
Property Value
LogRunStatusChange
Indicates whether to log run status changes.
Declaration
public bool LogRunStatusChange { get; set; }
Property Value
MaxRequestLength
Gets or sets the maximum request length.
Declaration
public int MaxRequestLength { get; set; }
Property Value
Gets or sets the metadata associated with this assistant.
Declaration
public Dictionary<string, string> Metadata { get; set; }
Property Value
Type |
Description |
Dictionary<string, string> |
|
MinTokenRequirementPerRequest
Gets or sets the minimum token requirement per request.
Declaration
public int MinTokenRequirementPerRequest { get; set; }
Property Value
Model
Gets or sets the GPT model used by this assistant.
Declaration
public Model Model { get; set; }
Property Value
Name
Gets or sets the name of this assistant.
Declaration
public string Name { get; set; }
Property Value
RequiredActions
Gets the required actions.
Declaration
public Dictionary<string, RequiredActionStack> RequiredActions { get; }
Property Value
RequiresAction
Indicates whether the AssistantsAPI requires action.
Declaration
public bool RequiresAction { get; }
Property Value
Gets or sets the response format for this assistant.
Declaration
public TextFormat? ResponseFormat { get; set; }
Property Value
Run
Current run object used by this tool.
Declaration
public Run Run { get; set; }
Property Value
RunId
Declaration
public string RunId { get; }
Property Value
RunStatus
Gets the current run status of the Assistants API.
Declaration
public RunStatus RunStatus { get; }
Property Value
RunStep
Current run step object used by this tool.
Declaration
public RunStep RunStep { get; set; }
Property Value
SaveThreadMessages
Indicates whether to save thread messages.
Declaration
public bool SaveThreadMessages { get; set; }
Property Value
SavedMessages
Declaration
public PrefsDictionary<string, ThreadMessage> SavedMessages { get; }
Property Value
Sender
Gets or sets the sender name.
Declaration
public string Sender { get; set; }
Property Value
Stream
Indicates if the tool is set to stream (not supported yet).
Declaration
public bool Stream { get; set; }
Property Value
Temperature
Gets or sets the temperature setting for this assistant's responses.
Declaration
public float Temperature { get; set; }
Property Value
Thread
Current thread object used by this tool.
Declaration
public Thread Thread { get; set; }
Property Value
ThreadId
Gets or sets the current thread ID.
Declaration
public string ThreadId { get; set; }
Property Value
Give the tools like code_interpreter and file_search access to files.
Files are uploaded using the File upload endpoint
and must have the purpose set to assistants to be used with this API.
Declaration
public ToolResources ToolResources { get; set; }
Property Value
Give the Assistant access to up to 128 tools.
You can give it access to OpenAI-hosted tools like code_interpreter and file_search,
or call a third-party tools via a function calling.
Declaration
public List<ToolCall> Tools { get; set; }
Property Value
TopP
Gets or sets the top-p setting for this assistant's responses.
Declaration
public float TopP { get; set; }
Property Value
Methods
CancelRunAsync()
Cancels the current run operation.
Declaration
public UniTask CancelRunAsync()
Returns
Type |
Description |
UniTask |
A UniTask representing the asynchronous operation.
|
DeleteThreadAsync(string)
Delete the thread with the threadId.
Declaration
public UniTask<bool> DeleteThreadAsync(string threadId)
Parameters
Type |
Name |
Description |
string |
threadId |
|
Returns
Type |
Description |
UniTask<bool> |
|
GetThreadIds()
Get all thread ids from the OpenAI API server.
Declaration
public List<string> GetThreadIds()
Returns
Type |
Description |
List<string> |
|
InitializeAsync(Action)
Initializes the AssistantsAPI instance asynchronously.
Declaration
public UniTask InitializeAsync(Action onInitialized = null)
Parameters
Type |
Name |
Description |
Action |
onInitialized |
|
Returns
Type |
Description |
UniTask |
A UniTask representing the asynchronous operation.
|
RequestAsync(AudioClip, RunRequest)
Declaration
public UniTask<AssistantResult> RequestAsync(AudioClip audioPrompt, RunRequest customRunRequest = null)
Parameters
Type |
Name |
Description |
AudioClip |
audioPrompt |
|
RunRequest |
customRunRequest |
|
Returns
RequestAsync(ThreadMessageRequest, RunRequest)
Declaration
public UniTask<AssistantResult> RequestAsync(ThreadMessageRequest messageRequest, RunRequest customRunRequest = null)
Parameters
Returns
RequestAsync(TranscriptionRequest, RunRequest)
Declaration
public UniTask<AssistantResult> RequestAsync(TranscriptionRequest transcriptionRequest, RunRequest customRunRequest = null)
Parameters
Returns
RequestAsync(UniAudioFile, RunRequest)
Declaration
public UniTask<AssistantResult> RequestAsync(UniAudioFile audioPrompt, RunRequest customRunRequest = null)
Parameters
Type |
Name |
Description |
UniAudioFile |
audioPrompt |
|
RunRequest |
customRunRequest |
|
Returns
RequestAsync(string, RunRequest)
Requests a response from the assistant asynchronously.
Declaration
public UniTask<AssistantResult> RequestAsync(string textPrompt, RunRequest customRunRequest = null)
Parameters
Type |
Name |
Description |
string |
textPrompt |
The text prompt to send to the assistant.
|
RunRequest |
customRunRequest |
Optional custom run request options.
|
Returns
Type |
Description |
UniTask<AssistantResult> |
A task representing the result of the request.
|
RequestAsync(string, RunRequest, params UniImageFile[])
Declaration
public UniTask<AssistantResult> RequestAsync(string textPrompt, RunRequest customRunRequest, params UniImageFile[] imageFiles)
Parameters
Type |
Name |
Description |
string |
textPrompt |
|
RunRequest |
customRunRequest |
|
UniImageFile[] |
imageFiles |
|
Returns
RequestAsync(string, RunRequest, params string[])
Declaration
public UniTask<AssistantResult> RequestAsync(string textPrompt, RunRequest customRunRequest, params string[] imageUrls)
Parameters
Type |
Name |
Description |
string |
textPrompt |
|
RunRequest |
customRunRequest |
|
string[] |
imageUrls |
|
Returns
SetCodeInterpreterEnabledAsync(bool)
Declaration
public UniTask<bool> SetCodeInterpreterEnabledAsync(bool enabled)
Parameters
Type |
Name |
Description |
bool |
enabled |
|
Returns
Type |
Description |
UniTask<bool> |
Returns true if the tool is enabled successfully.
|
SetCurrentThreadAsync(string)
Switch to the existing thread with threadId.
The thread with the threadId must exist.
Declaration
public UniTask<Thread> SetCurrentThreadAsync(string threadId)
Parameters
Type |
Name |
Description |
string |
threadId |
|
Returns
Type |
Description |
UniTask<Thread> |
|
SetFileSearchEnabledAsync(bool)
Declaration
public UniTask<bool> SetFileSearchEnabledAsync(bool enabled)
Parameters
Type |
Name |
Description |
bool |
enabled |
|
Returns
Type |
Description |
UniTask<bool> |
Returns true if the tool is enabled successfully.
|
StartNewThreadAsync(bool)
Create a new thread and set it as the current thread.
If deleteCurrent is true, the current thread will be deleted before creating a new one.
Declaration
public UniTask StartNewThreadAsync(bool deleteCurrent = false)
Parameters
Type |
Name |
Description |
bool |
deleteCurrent |
|
Returns
Declaration
public UniTask<AssistantResult> SubmitToolOutput(string toolCallId, string outputToSubmit)
Parameters
Type |
Name |
Description |
string |
toolCallId |
|
string |
outputToSubmit |
|
Returns
UpdateAssistantAsync(AssistantRequest)
Declaration
public UniTask<Assistant> UpdateAssistantAsync(AssistantRequest request)
Parameters
Returns