AssistantsClient class
Warning
This API is now deprecated.
The Azure OpenAI Assistants client library for JavaScript beta will be retired on January 14th, 2025. Please migrate to the stable OpenAI SDK for JavaScript using the migration guide before that date.
Client handling assistant-related operations.
Constructors
Assistants |
Initializes an instance of AssistantsClient for use with the non-Azure OpenAI endpoint. |
Assistants |
Initializes an instance of AssistantsClient for use with an OpenAI resource. |
Assistants |
Initializes an instance of AssistantsClient for use with an Azure OpenAI resource. |
Properties
pipeline | The pipeline used by this client to make requests |
Methods
cancel |
Cancels a run of an in progress thread. |
create |
Creates a new assistant. |
create |
Attaches a previously uploaded file to an assistant for use by tools that can read files. |
create |
Creates a new message on a specified thread. |
create |
Creates a new run for an assistant thread. |
create |
Creates a new thread. Threads contain messages and can be run by assistants. |
create |
Creates a new assistant thread and immediately starts a run using that new thread. |
delete |
Deletes an assistant. |
delete |
Unlinks a previously attached file from an assistant, rendering it unavailable for use by tools that can read files. |
delete |
Delete a previously uploaded file. |
delete |
Deletes an existing thread. |
get |
Retrieves an existing assistant. |
get |
Retrieves a file attached to an assistant. |
get |
Returns information about a specific file. Does not retrieve file content. |
get |
Gets an existing message from an existing thread. |
get |
Gets information about a file attachment to a message within a thread. |
get |
Gets an existing run from an existing thread. |
get |
Gets a single run step from a thread run. |
get |
Gets information about an existing thread. |
list |
Gets a list of files attached to a specific assistant, as used by tools that can read files. |
list |
Gets a list of assistants that were previously created. |
list |
Gets a list of previously uploaded files. |
list |
Gets a list of previously uploaded files associated with a message from a thread. |
list |
Gets a list of messages that exist on a thread. |
list |
Gets a list of runs for a specified thread. |
list |
Gets a list of run steps from a thread run. |
submit |
Submits outputs from tools as requested by tool calls in a run. Runs that need submitted tool outputs will have a status of 'requires_action' with a required_action.type of 'submit_tool_outputs'. |
update |
Modifies an existing assistant. |
update |
Modifies an existing message on an existing thread. |
update |
Modifies an existing thread run. |
update |
Modifies an existing thread. |
upload |
Uploads a file for use by other operations. |
Constructor Details
AssistantsClient(KeyCredential, AssistantsClientOptions)
Initializes an instance of AssistantsClient for use with the non-Azure OpenAI endpoint.
new AssistantsClient(openAiApiKey: KeyCredential, options?: AssistantsClientOptions)
Parameters
- openAiApiKey
- KeyCredential
The API key to use when connecting to the non-Azure OpenAI endpoint.
- options
- AssistantsClientOptions
The options for configuring the client.
Remarks
AssistantsClient objects initialized with this constructor can only be used with the non-Azure OpenAI inference endpoint. To use AssistantsClient with an Azure OpenAI resource, use a constructor that accepts a resource URI and Azure authentication credential instead.
AssistantsClient(string, KeyCredential, AssistantsClientOptions)
Initializes an instance of AssistantsClient for use with an OpenAI resource.
new AssistantsClient(endpoint: string, credential: KeyCredential, options?: AssistantsClientOptions)
Parameters
- endpoint
-
string
The URI for an Azure OpenAI resource, including protocol and hostname. For example: https://my-resource.openai.azure.com.
- credential
- KeyCredential
A key credential used to authenticate to an Azure OpenAI resource.
- options
- AssistantsClientOptions
The options for configuring the client.
Remarks
This constructor initializes an AssistantsClient object that can only be used with Azure OpenAI resources. To use AssistantsClient with a non-Azure OpenAI inference endpoint, use a constructor that accepts a non-Azure OpenAI API key instead.
AssistantsClient(string, TokenCredential, AssistantsClientOptions)
Initializes an instance of AssistantsClient for use with an Azure OpenAI resource.
new AssistantsClient(endpoint: string, credential: TokenCredential, options?: AssistantsClientOptions)
Parameters
- endpoint
-
string
The URI for an Azure OpenAI resource, including protocol and hostname. For example: https://my-resource.openai.azure.com.
- credential
- TokenCredential
A token credential used to authenticate with an Azure OpenAI resource.
- options
- AssistantsClientOptions
The options for configuring the client.
Property Details
pipeline
Method Details
cancelRun(string, string, CancelRunOptions)
Cancels a run of an in progress thread.
function cancelRun(threadId: string, runId: string, options?: CancelRunOptions): Promise<ThreadRun>
Parameters
- threadId
-
string
- runId
-
string
- options
- CancelRunOptions
Returns
Promise<ThreadRun>
createAssistant(AssistantCreationOptions, CreateAssistantOptions)
Creates a new assistant.
function createAssistant(body: AssistantCreationOptions, options?: CreateAssistantOptions): Promise<Assistant>
Parameters
- options
- CreateAssistantOptions
Returns
Promise<Assistant>
createAssistantFile(string, string, CreateAssistantFileOptions)
Attaches a previously uploaded file to an assistant for use by tools that can read files.
function createAssistantFile(assistantId: string, fileId: string, options?: CreateAssistantFileOptions): Promise<AssistantFile>
Parameters
- assistantId
-
string
- fileId
-
string
- options
- CreateAssistantFileOptions
Returns
Promise<AssistantFile>
createMessage(string, string, string, CreateMessageOptions)
Creates a new message on a specified thread.
function createMessage(threadId: string, role: string, content: string, options?: CreateMessageOptions): Promise<ThreadMessage>
Parameters
- threadId
-
string
- role
-
string
- content
-
string
- options
- CreateMessageOptions
Returns
Promise<ThreadMessage>
createRun(string, CreateRunOptions, CreateRunRequestOptions)
Creates a new run for an assistant thread.
function createRun(threadId: string, createRunOptions: CreateRunOptions, options?: CreateRunRequestOptions): Promise<ThreadRun>
Parameters
- threadId
-
string
- createRunOptions
- CreateRunOptions
- options
- CreateRunRequestOptions
Returns
Promise<ThreadRun>
createThread(AssistantThreadCreationOptions, CreateThreadOptions)
Creates a new thread. Threads contain messages and can be run by assistants.
function createThread(body?: AssistantThreadCreationOptions, options?: CreateThreadOptions): Promise<AssistantThread>
Parameters
- options
- CreateThreadOptions
Returns
Promise<AssistantThread>
createThreadAndRun(CreateAndRunThreadOptions, CreateThreadAndRunOptions)
Creates a new assistant thread and immediately starts a run using that new thread.
function createThreadAndRun(body: CreateAndRunThreadOptions, options?: CreateThreadAndRunOptions): Promise<ThreadRun>
Parameters
- options
- CreateThreadAndRunOptions
Returns
Promise<ThreadRun>
deleteAssistant(string, DeleteAssistantOptions)
Deletes an assistant.
function deleteAssistant(assistantId: string, options?: DeleteAssistantOptions): Promise<AssistantDeletionStatus>
Parameters
- assistantId
-
string
- options
- DeleteAssistantOptions
Returns
Promise<AssistantDeletionStatus>
deleteAssistantFile(string, string, DeleteAssistantFileOptions)
Unlinks a previously attached file from an assistant, rendering it unavailable for use by tools that can read files.
function deleteAssistantFile(assistantId: string, fileId: string, options?: DeleteAssistantFileOptions): Promise<AssistantFileDeletionStatus>
Parameters
- assistantId
-
string
- fileId
-
string
- options
- DeleteAssistantFileOptions
Returns
Promise<AssistantFileDeletionStatus>
deleteFile(string, DeleteFileOptions)
Delete a previously uploaded file.
function deleteFile(fileId: string, options?: DeleteFileOptions): Promise<FileDeletionStatus>
Parameters
- fileId
-
string
- options
- DeleteFileOptions
Returns
Promise<FileDeletionStatus>
deleteThread(string, DeleteThreadOptions)
Deletes an existing thread.
function deleteThread(threadId: string, options?: DeleteThreadOptions): Promise<ThreadDeletionStatus>
Parameters
- threadId
-
string
- options
- DeleteThreadOptions
Returns
Promise<ThreadDeletionStatus>
getAssistant(string, GetAssistantOptions)
Retrieves an existing assistant.
function getAssistant(assistantId: string, options?: GetAssistantOptions): Promise<Assistant>
Parameters
- assistantId
-
string
- options
- GetAssistantOptions
Returns
Promise<Assistant>
getAssistantFile(string, string, GetAssistantFileOptions)
Retrieves a file attached to an assistant.
function getAssistantFile(assistantId: string, fileId: string, options?: GetAssistantFileOptions): Promise<AssistantFile>
Parameters
- assistantId
-
string
- fileId
-
string
- options
- GetAssistantFileOptions
Returns
Promise<AssistantFile>
getFile(string, GetFileOptions)
Returns information about a specific file. Does not retrieve file content.
function getFile(fileId: string, options?: GetFileOptions): Promise<InputFile>
Parameters
- fileId
-
string
- options
- GetFileOptions
Returns
Promise<InputFile>
getMessage(string, string, GetMessageOptions)
Gets an existing message from an existing thread.
function getMessage(threadId: string, messageId: string, options?: GetMessageOptions): Promise<ThreadMessage>
Parameters
- threadId
-
string
- messageId
-
string
- options
- GetMessageOptions
Returns
Promise<ThreadMessage>
getMessageFile(string, string, string, GetMessageFileOptions)
Gets information about a file attachment to a message within a thread.
function getMessageFile(threadId: string, messageId: string, fileId: string, options?: GetMessageFileOptions): Promise<MessageFile>
Parameters
- threadId
-
string
- messageId
-
string
- fileId
-
string
- options
- GetMessageFileOptions
Returns
Promise<MessageFile>
getRun(string, string, GetRunOptions)
Gets an existing run from an existing thread.
function getRun(threadId: string, runId: string, options?: GetRunOptions): Promise<ThreadRun>
Parameters
- threadId
-
string
- runId
-
string
- options
- GetRunOptions
Returns
Promise<ThreadRun>
getRunStep(string, string, string, GetRunStepOptions)
Gets a single run step from a thread run.
function getRunStep(threadId: string, runId: string, stepId: string, options?: GetRunStepOptions): Promise<RunStep>
Parameters
- threadId
-
string
- runId
-
string
- stepId
-
string
- options
- GetRunStepOptions
Returns
Promise<RunStep>
getThread(string, GetThreadOptions)
Gets information about an existing thread.
function getThread(threadId: string, options?: GetThreadOptions): Promise<AssistantThread>
Parameters
- threadId
-
string
- options
- GetThreadOptions
Returns
Promise<AssistantThread>
listAssistantFiles(string, ListAssistantFilesOptions)
Gets a list of files attached to a specific assistant, as used by tools that can read files.
function listAssistantFiles(assistantId: string, options?: ListAssistantFilesOptions): Promise<ListResponseOf<AssistantFile>>
Parameters
- assistantId
-
string
- options
- ListAssistantFilesOptions
Returns
Promise<ListResponseOf<AssistantFile>>
listAssistants(ListAssistantsOptions)
Gets a list of assistants that were previously created.
function listAssistants(options?: ListAssistantsOptions): Promise<ListResponseOf<Assistant>>
Parameters
- options
- ListAssistantsOptions
Returns
Promise<ListResponseOf<Assistant>>
listFiles(ListFilesOptions)
Gets a list of previously uploaded files.
function listFiles(options?: ListFilesOptions): Promise<FileListResponse>
Parameters
- options
- ListFilesOptions
Returns
Promise<FileListResponse>
listMessageFiles(string, string, ListMessageFilesOptions)
Gets a list of previously uploaded files associated with a message from a thread.
function listMessageFiles(threadId: string, messageId: string, options?: ListMessageFilesOptions): Promise<ListResponseOf<MessageFile>>
Parameters
- threadId
-
string
- messageId
-
string
- options
- ListMessageFilesOptions
Returns
Promise<ListResponseOf<MessageFile>>
listMessages(string, ListMessagesOptions)
Gets a list of messages that exist on a thread.
function listMessages(threadId: string, options?: ListMessagesOptions): Promise<ListResponseOf<ThreadMessage>>
Parameters
- threadId
-
string
- options
- ListMessagesOptions
Returns
Promise<ListResponseOf<ThreadMessage>>
listRuns(string, ListRunsOptions)
Gets a list of runs for a specified thread.
function listRuns(threadId: string, options?: ListRunsOptions): Promise<ListResponseOf<ThreadRun>>
Parameters
- threadId
-
string
- options
- ListRunsOptions
Returns
Promise<ListResponseOf<ThreadRun>>
listRunSteps(string, string, ListRunStepsOptions)
Gets a list of run steps from a thread run.
function listRunSteps(threadId: string, runId: string, options?: ListRunStepsOptions): Promise<ListResponseOf<RunStep>>
Parameters
- threadId
-
string
- runId
-
string
- options
- ListRunStepsOptions
Returns
Promise<ListResponseOf<RunStep>>
submitToolOutputsToRun(string, string, ToolOutput[], SubmitToolOutputsToRunOptions)
Submits outputs from tools as requested by tool calls in a run. Runs that need submitted tool outputs will have a status of 'requires_action' with a required_action.type of 'submit_tool_outputs'.
function submitToolOutputsToRun(threadId: string, runId: string, toolOutputs: ToolOutput[], options?: SubmitToolOutputsToRunOptions): Promise<ThreadRun>
Parameters
- threadId
-
string
- runId
-
string
- toolOutputs
- options
- SubmitToolOutputsToRunOptions
Returns
Promise<ThreadRun>
updateAssistant(string, UpdateAssistantOptions, UpdateAssistantRequestOptions)
Modifies an existing assistant.
function updateAssistant(assistantId: string, body: UpdateAssistantOptions, options?: UpdateAssistantRequestOptions): Promise<Assistant>
Parameters
- assistantId
-
string
- options
- UpdateAssistantRequestOptions
Returns
Promise<Assistant>
updateMessage(string, string, UpdateMessageOptions)
Modifies an existing message on an existing thread.
function updateMessage(threadId: string, messageId: string, options?: UpdateMessageOptions): Promise<ThreadMessage>
Parameters
- threadId
-
string
- messageId
-
string
- options
- UpdateMessageOptions
Returns
Promise<ThreadMessage>
updateRun(string, string, UpdateRunOptions)
Modifies an existing thread run.
function updateRun(threadId: string, runId: string, options?: UpdateRunOptions): Promise<ThreadRun>
Parameters
- threadId
-
string
- runId
-
string
- options
- UpdateRunOptions
Returns
Promise<ThreadRun>
updateThread(string, UpdateThreadOptions)
Modifies an existing thread.
function updateThread(threadId: string, options?: UpdateThreadOptions): Promise<AssistantThread>
Parameters
- threadId
-
string
- options
- UpdateThreadOptions
Returns
Promise<AssistantThread>
uploadFile(Uint8Array, string, UploadFileOptions)
Uploads a file for use by other operations.
function uploadFile(file: Uint8Array, purpose: string, options?: UploadFileOptions): Promise<InputFile>
Parameters
- file
-
Uint8Array
- purpose
-
string
- options
- UploadFileOptions
Returns
Promise<InputFile>
Azure SDK for JavaScript