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

AssistantsClient(KeyCredential, AssistantsClientOptions)

Initializes an instance of AssistantsClient for use with the non-Azure OpenAI endpoint.

AssistantsClient(string, KeyCredential, AssistantsClientOptions)

Initializes an instance of AssistantsClient for use with an OpenAI resource.

AssistantsClient(string, TokenCredential, AssistantsClientOptions)

Initializes an instance of AssistantsClient for use with an Azure OpenAI resource.

Properties

pipeline

The pipeline used by this client to make requests

Methods

cancelRun(string, string, CancelRunOptions)

Cancels a run of an in progress thread.

createAssistant(AssistantCreationOptions, CreateAssistantOptions)

Creates a new assistant.

createAssistantFile(string, string, CreateAssistantFileOptions)

Attaches a previously uploaded file to an assistant for use by tools that can read files.

createMessage(string, string, string, CreateMessageOptions)

Creates a new message on a specified thread.

createRun(string, CreateRunOptions, CreateRunRequestOptions)

Creates a new run for an assistant thread.

createThread(AssistantThreadCreationOptions, CreateThreadOptions)

Creates a new thread. Threads contain messages and can be run by assistants.

createThreadAndRun(CreateAndRunThreadOptions, CreateThreadAndRunOptions)

Creates a new assistant thread and immediately starts a run using that new thread.

deleteAssistant(string, DeleteAssistantOptions)

Deletes an assistant.

deleteAssistantFile(string, string, DeleteAssistantFileOptions)

Unlinks a previously attached file from an assistant, rendering it unavailable for use by tools that can read files.

deleteFile(string, DeleteFileOptions)

Delete a previously uploaded file.

deleteThread(string, DeleteThreadOptions)

Deletes an existing thread.

getAssistant(string, GetAssistantOptions)

Retrieves an existing assistant.

getAssistantFile(string, string, GetAssistantFileOptions)

Retrieves a file attached to an assistant.

getFile(string, GetFileOptions)

Returns information about a specific file. Does not retrieve file content.

getMessage(string, string, GetMessageOptions)

Gets an existing message from an existing thread.

getMessageFile(string, string, string, GetMessageFileOptions)

Gets information about a file attachment to a message within a thread.

getRun(string, string, GetRunOptions)

Gets an existing run from an existing thread.

getRunStep(string, string, string, GetRunStepOptions)

Gets a single run step from a thread run.

getThread(string, GetThreadOptions)

Gets information about an existing thread.

listAssistantFiles(string, ListAssistantFilesOptions)

Gets a list of files attached to a specific assistant, as used by tools that can read files.

listAssistants(ListAssistantsOptions)

Gets a list of assistants that were previously created.

listFiles(ListFilesOptions)

Gets a list of previously uploaded files.

listMessageFiles(string, string, ListMessageFilesOptions)

Gets a list of previously uploaded files associated with a message from a thread.

listMessages(string, ListMessagesOptions)

Gets a list of messages that exist on a thread.

listRuns(string, ListRunsOptions)

Gets a list of runs for a specified thread.

listRunSteps(string, string, ListRunStepsOptions)

Gets a list of run steps from a thread run.

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'.

updateAssistant(string, UpdateAssistantOptions, UpdateAssistantRequestOptions)

Modifies an existing assistant.

updateMessage(string, string, UpdateMessageOptions)

Modifies an existing message on an existing thread.

updateRun(string, string, UpdateRunOptions)

Modifies an existing thread run.

updateThread(string, UpdateThreadOptions)

Modifies an existing thread.

uploadFile(Uint8Array, string, UploadFileOptions)

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

The pipeline used by this client to make requests

pipeline: Pipeline

Property Value

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

Returns

Promise<ThreadRun>

createAssistant(AssistantCreationOptions, CreateAssistantOptions)

Creates a new assistant.

function createAssistant(body: AssistantCreationOptions, options?: CreateAssistantOptions): Promise<Assistant>

Parameters

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

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

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

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

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

Returns

Promise<ThreadRun>

deleteAssistant(string, DeleteAssistantOptions)

Deletes an assistant.

function deleteAssistant(assistantId: string, options?: DeleteAssistantOptions): Promise<AssistantDeletionStatus>

Parameters

assistantId

string

Returns

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

Returns

deleteFile(string, DeleteFileOptions)

Delete a previously uploaded file.

function deleteFile(fileId: string, options?: DeleteFileOptions): Promise<FileDeletionStatus>

Parameters

fileId

string

Returns

deleteThread(string, DeleteThreadOptions)

Deletes an existing thread.

function deleteThread(threadId: string, options?: DeleteThreadOptions): Promise<ThreadDeletionStatus>

Parameters

threadId

string

Returns

getAssistant(string, GetAssistantOptions)

Retrieves an existing assistant.

function getAssistant(assistantId: string, options?: GetAssistantOptions): Promise<Assistant>

Parameters

assistantId

string

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

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

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

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

Returns

Promise<RunStep>

getThread(string, GetThreadOptions)

Gets information about an existing thread.

function getThread(threadId: string, options?: GetThreadOptions): Promise<AssistantThread>

Parameters

threadId

string

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

Returns

listAssistants(ListAssistantsOptions)

Gets a list of assistants that were previously created.

function listAssistants(options?: ListAssistantsOptions): Promise<ListResponseOf<Assistant>>

Parameters

Returns

listFiles(ListFilesOptions)

Gets a list of previously uploaded files.

function listFiles(options?: ListFilesOptions): Promise<FileListResponse>

Parameters

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

Returns

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

Returns

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

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

Returns

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

ToolOutput[]

Returns

Promise<ThreadRun>

updateAssistant(string, UpdateAssistantOptions, UpdateAssistantRequestOptions)

Modifies an existing assistant.

function updateAssistant(assistantId: string, body: UpdateAssistantOptions, options?: UpdateAssistantRequestOptions): Promise<Assistant>

Parameters

assistantId

string

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

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

Returns

Promise<ThreadRun>

updateThread(string, UpdateThreadOptions)

Modifies an existing thread.

function updateThread(threadId: string, options?: UpdateThreadOptions): Promise<AssistantThread>

Parameters

threadId

string

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

Returns

Promise<InputFile>