API Client for interfacing with the OpenAI API.

Hierarchy

  • APIClient
    • OpenAIClient

Constructors

  • API Client for interfacing with the OpenAI API.

    Parameters

    Returns OpenAIClient

Properties

apiKey: string
audio: Audio
baseURL: string
batches: Batches
beta: Beta
fineTuning: FineTuning
httpAgent: undefined | Agent
idempotencyHeader?: string
images: Images
maxRetries: number
models: Models
moderations: Moderations
organization: null | string
project: null | string
timeout: number
uploads: Uploads
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
fileFromPath: {
    (path: string, options?: FileFromPathOptions): Promise<File>;
    (path: string, filename?: string, options?: FileFromPathOptions): Promise<File>;
}
toFile: ((value: ToFileInput | PromiseLike<ToFileInput>, name?: null | string, options?: FilePropertyBag) => Promise<FileLike>)

Type declaration

    • (value, name?, options?): Promise<FileLike>
    • 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<FileLike>

      a File with the given properties

Methods

  • Parameters

    • opts: FinalRequestOptions<unknown>

    Returns Headers

  • Type Parameters

    • Req

    Parameters

    • options: FinalRequestOptions<Req>

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

    • req: RequestInit
    • timeout: number
    • url: string
  • Type Parameters

    • Req

    Parameters

    • path: string
    • query: undefined | null | Req

    Returns string

  • Override this to add your own default headers, for example:

    { ...super.defaultHeaders(), Authorization: 'Bearer 123', }

    Parameters

    • opts: FinalRequestOptions<unknown>

    Returns Headers

  • Returns string

  • Returns undefined | DefaultQuery

  • Type Parameters

    • Req
    • Rsp

    Parameters

    Returns APIPromise<Rsp>

  • Parameters

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

    Returns Promise<Response>

  • Type Parameters

    • Req
    • Rsp

    Parameters

    Returns APIPromise<Rsp>

  • Type Parameters

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

    Parameters

    Returns PagePromise<PageClass, Item>

  • Returns RequestClient

  • Parameters

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

    Returns APIError

  • Parameters

    • headers: undefined | null | HeadersInit

    Returns Record<string, string>

  • Type Parameters

    • Req
    • Rsp

    Parameters

    Returns APIPromise<Rsp>

  • Type Parameters

    • Req
    • Rsp

    Parameters

    Returns APIPromise<Rsp>

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

    Parameters

    • options: FinalRequestOptions<unknown>

    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<unknown>;
          url: string;
      }
      • options: FinalRequestOptions<unknown>
      • url: string

    Returns Promise<void>

  • Type Parameters

    • Req
    • Rsp

    Parameters

    Returns APIPromise<Rsp>

  • Type Parameters

    • Req
    • Rsp

    Parameters

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

    Returns APIPromise<Rsp>

  • Type Parameters

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

    Parameters

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

          • Rest...args: [client: APIClient, response: Response, body: unknown, options: FinalRequestOptions<unknown>]

          Returns PageClass

    • options: FinalRequestOptions<unknown>

    Returns PagePromise<PageClass, Item>

  • Parameters

    • query: Record<string, unknown>

    Returns string

  • Override this to add your own headers validation:

    Parameters

    • headers: Headers
    • customHeaders: Headers

    Returns void