Skip to main content
The Deno 2 Release Candidate is here
Learn more
Module

x/openai_deno/mod.ts>OpenAI

OpenAI API wrapper for deno.
Latest
class OpenAI
import { OpenAI } from "https://deno.land/x/openai_deno@v0.9.8/mod.ts";

Constructors

new
OpenAI(token?: string, organizationToken?: string)

Properties

optional
_organizationToken: string
optional
_token: string
readonly
organizationToken: string | undefined
readonly
token: string | undefined

Methods

private
convertLogProbs(logProbs?: LogProbsRaw | null): LogProbs | undefined
deprecated
cancelFineTune(fineTuneID: string): Promise<FineTune>

Immediately cancel a fine-tune job.

cancelFineTuningJob(jobID: string): Promise<FineTuningJob>

Immediately cancel a fine-tune job.

cancelRun(threadID: string, runID: string): Promise<Run>

Cancels a run that is inProgress.

deprecated
createAnswer(engineID: string, args: AnswerArgs): Promise<AnswerResponse>
createAssistant(model: string, params?: CreateAssistantParams): Promise<Assistant>

Create an assistant with a model and instructions.

createAssistantFile(assistantID: string, fileID: string): Promise<AssistantFile>

Create an assistant file by attaching a File to an assistant.

createChat(
model: string,
messages: ChatFormat[],
): Promise<CreateChatResponse>

Creates a completion for the chat message

deprecated
createClassification(engineID: string, args: ClassificationArgs): Promise<ClassificationResponse>

Creates a completion for the provided prompt and parameters

deprecated
createEdit(
model: string,
instruction: string,
): Promise<CreateEditResponse>

Creates a new edit for the provided input, instruction, and parameters

createEmbeddings(
model: string,
input: string | string[] | number[][],
user?: string,
): Promise<CreateEmbeddingsResponse>

Creates an embedding vector representing the input text.

deprecated
createFineTune(trainingFile: OpenAIFile | string, params?: CreateFineTuneParams): Promise<FineTune>

Creates a job that fine-tunes a specified model from a given dataset.

Response includes details of the enqueued job including job status and the name of the fine-tuned models once complete.

Learn more about Fine-tuning

createFineTuningJob(
trainingFile: OpenAIFile | string,
model: string,
): Promise<FineTuningJob>

Creates a job that fine-tunes a specified model from a given dataset.

Response includes details of the enqueued job including job status and the name of the fine-tuned models once complete.

Learn more about fine-tuning

createImage(prompt: string, params?: CreateImageParams): Promise<CreateImageResponse>

Creates an image given a prompt.

createImageEdit(
image: string | BlobPart,
prompt: string,
filename?: string,
): Promise<CreateImageResponse>

Creates an edited or extended image given an original image and a prompt.

createImageVariation(
image: string | BlobPart,
filename?: string,
): Promise<CreateImageResponse>

Creates a variation of a given image.

createMessage(
threadID: string,
role: "user" | string,
content: string,
): Promise<Message>

Create a message.

createModeration(input: string | string[], model?: "text-moderation-latest" | "text-moderation-stable"): Promise<Moderation[]>

Classifies if text violates OpenAI's Content Policy

createRun(
threadID: string,
assistantID: string,
params?: CreateRunParams,
): Promise<Run>

Create a run.

deprecated
createSearch(engineID: string, args: SearchArgs): Promise<SearchResponse[]>
createSpeech(
model: "tts-1" | "tts-1-hd" | string,
input: string,
voice:
| "alloy"
| "echo"
| "fable"
| "onyx"
| "nova"
| "shimmer"
| string
,
): Promise<Blob>

Generates audio from the input text.

Create a thread.

createThreadAndRun(assistantID: string, params?: CreateThreadAndRunParams): Promise<Run>

A run object.

createTranscription(
file: string | BlobPart,
model: string,
filename?: string,
): Promise<CreateTranscriptionResponse>

Transcribes audio into the input language.

createTranslation(
file: string | BlobPart,
model: string,
filename?: string,
): Promise<CreateTranslationResponse>

Translates audio into into English.

deleteAssistant(assistantID: string): Promise<DeleteResponse>

Delete an assistant.

deleteAssistantFile(assistantID: string, fileID: string): Promise<DeleteResponse>

Delete an assistant file.

deleteFile(fileID: string): Promise<DeleteResponse>

Delete a file.

deleteModel(modelID: string): Promise<DeleteResponse>

Delete a fine-tuned model. You must have the Owner role in your organization.

deleteThread(threadID: string): Promise<DeleteResponse>

Delete a thread.

deprecated
getEngine(engineID: string): Promise<EngineResponse>
deprecated
getEngines(): Promise<EngineResponse[]>
getFile(fileID: string): Promise<OpenAIFile>

Alias for OpenAI#retrieveFile. This method is deprecated and will be removed in a future version.

getFiles(): Promise<OpenAIFile[]>

Alias for OpenAI#this.listFiles. This method is deprecated and will be removed in a future version.

listAssistantFiles(assistantID: string, query?: ListAssistantFileQuery): Promise<AssistantFile[]>

Returns a list of assistant files.

Returns a list of assistants.

listFiles(): Promise<OpenAIFile[]>

Returns a list of files that belong to the user's organization.

deprecated
listFineTuneEvents(fineTuneID: string): Promise<FineTuneEvent[]>

Get fine-grained status updates for a fine-tune job.

deprecated
listFineTunes(): Promise<FineTune[]>

List your organization's fine-tuning jobs

listFineTuningEvents(
jobID: string,
after?: string,
limit?: number,
): Promise<FineTuningEvent[]>
listFineTuningJobs(after?: string, limit?: number): Promise<FineTuningJob[]>

List your organization's fine-tuning jobs

listMessageFiles(
threadID: string,
messageID: string,
): Promise<MessageFile[]>

Returns a list of message files.

listMessages(threadID: string, query?: ListMessageQuery): Promise<Message[]>

Returns a list of messages for a given thread.

listModels(): Promise<Model[]>

Lists the currently available models, and provides basic information about each one such as the owner and availability.

listRuns(threadID: string, query?: ListRunQuery): Promise<Run[]>

Returns a list of runs belonging to a thread.

listRunSteps(
threadID: string,
runID: string,
): Promise<RunStep[]>

Returns a list of run steps belonging to a run.

modifyAssistant(assistantID: string, params?: Partial<CreateAssistantParams> & { model?: string; }): Promise<Assistant>

Modifies an assistant.

modifyMessage(
threadID: string,
messageID: string,
params?: HasMetadata,
): Promise<Message>

Modifies a message.

modifyRun(
threadID: string,
runID: string,
params?: HasMetadata,
): Promise<Run>

Modifies a run.

modifyThread(threadID: string, params?: Partial<HasMetadata>): Promise<Thread>

Modifies a thread.

request<R>(unnamed 0: { method?:
| "GET"
| "POST"
| "PATCH"
| "PUT"
| "DELETE"
; url: string; headers?: { [name: string]: string; }; body?: Record<string, unknown> | FormData | string; raw?: false; query?: Record<string, string | undefined>; }
): Promise<R>
request<R>(unnamed 0: { method?:
| "GET"
| "POST"
| "PATCH"
| "PUT"
| "DELETE"
; url: string; headers?: { [name: string]: string; }; body?: Record<string, unknown> | FormData | string; raw?: true; query?: Record<string, string | undefined>; }
): Promise<Blob>
retrieveAssistant(assistantID: string): Promise<Assistant>

Retrieves an assistant.

retrieveAssistantFile(assistantID: string, fileID: string): Promise<AssistantFile>

Retrieves an AssistantFile.

retrieveFile(fileID: string): Promise<OpenAIFile>

Returns information about a specific file.

retrieveFileContent(fileID: string): Promise<Blob>

Returns the contents of the specified file

deprecated
retrieveFineTune(fineTuneID: string): Promise<FineTune>

Gets info about the fine-tune job.

Learn more about Fine-tuning

retrieveFineTuningJob(jobID: string): Promise<FineTuningJob>

Get info about a fine-tuning job.

retrieveMessage(threadID: string, messageID: string): Promise<Message>

Retrieve a message.

retrieveMessageFile(
threadID: string,
messageID: string,
fileID: string,
): Promise<MessageFile>

Retrieves a message file.

retrieveModel(modelID: string): Promise<Model>

Retrieves a model instance, providing basic information about the model such as the owner and permissioning.

retrieveRun(threadID: string, runID: string): Promise<Run>

Retrieves a run.

retrieveRunStep(
threadID: string,
runID: string,
stepID: string,
): Promise<RunStep>

Retrieves a run step.

retrieveThread(threadID: string): Promise<Thread>

Retrieves a thread.

submitToolOutputsToRun(
threadID: string,
runID: string,
toolCalls: ToolCall[],
): Promise<Run>

When a run has the status: "requiresAction" and requiredAction.type is submitToolOutputs, 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.

uploadFile(
file: string | BlobPart,
purpose: string,
filename?: string,
): Promise<OpenAIFile>

Upload a file that contains document(s) to be used across various endpoints/features. Currently, the size of all the files uploaded by one organization can be up to 1 GB. Please contact OpenAI if you need to increase the storage limit.