API Client for interfacing with the OpenAI API.

Constructors

  • API Client for interfacing with the OpenAI API.

    Parameters

    Returns OpenAIClient

Properties

apiKey: string
baseURL: string
batches: Batches
beta: Beta
chat: Chat
containers: Containers
evals: Evals
fetchOptions: undefined | MergedRequestInit
fineTuning: FineTuning
idempotencyHeader?: string
images: Images
logLevel: undefined | LogLevel
logger: undefined | Logger
maxRetries: number
models: Models
moderations: Moderations
organization: null | string
project: null | string
timeout: number
uploads: Uploads
vectorStores: VectorStores
APIConnectionError: typeof APIConnectionError
APIConnectionTimeoutError: typeof APIConnectionTimeoutError
APIError: typeof APIError
APIUserAbortError: typeof APIUserAbortError
AuthenticationError: typeof AuthenticationError
BadRequestError: typeof BadRequestError
ConflictError: typeof ConflictError
DEFAULT_TIMEOUT: number
InternalServerError: typeof InternalServerError
NotFoundError: typeof NotFoundError
OpenAI: typeof OpenAIClient
OpenAIError: typeof OpenAIError
PermissionDeniedError: typeof PermissionDeniedError
RateLimitError: typeof RateLimitError
UnprocessableEntityError: typeof UnprocessableEntityError
toFile: ((value: ToFileInput | PromiseLike<ToFileInput>, name?: null | string, options?: FilePropertyBag) => Promise<File>)

Type declaration

    • (value, name?, options?): Promise<File>
    • Helper for creating a File to pass to an SDK upload method from a variety of different data formats

      Parameters

      • value: ToFileInput | PromiseLike<ToFileInput>

        the raw content of the file. Can be an Uploadable, BlobLikePart, or AsyncIterable of BlobLikeParts

      • Optionalname: null | string

        the name of the file. If omitted, toFile will try to determine a file name from bits if possible

      • Optionaloptions: FilePropertyBag

        additional properties

      Returns Promise<File>

      a File with the given properties

Methods

  • Parameters

    • opts: FinalRequestOptions

    Returns undefined | NullableHeaders

  • Parameters

    • inputOptions: FinalRequestOptions
    • Optional__namedParameters: {
          retryCount?: number;
      }
      • OptionalretryCount?: number

    Returns {
        req: FinalizedRequestInit;
        timeout: number;
        url: string;
    }

    • req: FinalizedRequestInit
    • timeout: number
    • url: string
  • Parameters

    • path: string
    • query: undefined | null | Record<string, unknown>

    Returns string

  • Returns string

  • Returns undefined | Record<string, undefined | string>

  • Type Parameters

    • Rsp

    Parameters

    • path: string
    • Optionalopts: PromiseOrValue<RequestOptions>

    Returns APIPromise<Rsp>

  • Parameters

    • url: _RequestInfo
    • init: undefined | RequestInit
    • ms: number
    • controller: AbortController

    Returns Promise<Response>

  • Type Parameters

    • Rsp

    Parameters

    • path: string
    • Optionalopts: PromiseOrValue<RequestOptions>

    Returns APIPromise<Rsp>

  • Type Parameters

    • Item
    • PageClass extends AbstractPage<Item> = AbstractPage<Item>

    Parameters

    • path: string
    • Page: (new (...args: any[]) => PageClass)
    • Optionalopts: RequestOptions

    Returns PagePromise<PageClass, Item>

  • Parameters

    • status: number
    • error: Object
    • message: undefined | string
    • headers: Headers

    Returns APIError<undefined | number, undefined | Headers, undefined | Object>

  • Type Parameters

    • Rsp

    Parameters

    • path: string
    • Optionalopts: PromiseOrValue<RequestOptions>

    Returns APIPromise<Rsp>

  • Type Parameters

    • Rsp

    Parameters

    • path: string
    • Optionalopts: PromiseOrValue<RequestOptions>

    Returns APIPromise<Rsp>

  • Used as a callback for mutating the given FinalRequestOptions object.

    Parameters

    • options: FinalRequestOptions

    Returns Promise<void>

  • Used as a callback for mutating the given RequestInit object.

    This is useful for cases where you want to add certain headers based off of the request properties, e.g. method or url.

    Parameters

    • request: RequestInit
    • __namedParameters: {
          options: FinalRequestOptions;
          url: string;
      }
      • options: FinalRequestOptions
      • url: string

    Returns Promise<void>

  • Type Parameters

    • Rsp

    Parameters

    • path: string
    • Optionalopts: PromiseOrValue<RequestOptions>

    Returns APIPromise<Rsp>

  • Type Parameters

    • Rsp

    Parameters

    • options: PromiseOrValue<FinalRequestOptions>
    • OptionalremainingRetries: null | number

    Returns APIPromise<Rsp>

  • Type Parameters

    • Item = unknown
    • PageClass extends AbstractPage<Item> = AbstractPage<Item>

    Parameters

    • Page: (new (...args: [client: OpenAIClient, response: Response, body: unknown, options: FinalRequestOptions]) => PageClass)
        • new (...args): PageClass
        • Parameters

          • Rest...args: [client: OpenAIClient, response: Response, body: unknown, options: FinalRequestOptions]

          Returns PageClass

    • options: FinalRequestOptions

    Returns PagePromise<PageClass, Item>

  • Parameters

    • query: Record<string, unknown>

    Returns string

  • Parameters

    • __namedParameters: NullableHeaders

    Returns void

  • Create a new client instance re-using the same options given to the current client with optional overriding.

    Parameters

    Returns this