Skip to main content
Module

x/openai/core.ts>APIPromise

Deno build of the official Typescript library for the OpenAI API.
Extremely Popular
Go to Latest
class APIPromise
extends Promise<T>
import { APIPromise } from "https://deno.land/x/openai@v4.47.1/core.ts";

A subclass of Promise providing additional helper methods for interacting with the SDK.

Constructors

new
APIPromise(responsePromise: Promise<APIResponseProps>, parseResponse?: (props: APIResponseProps) => PromiseOrValue<T>)

Properties

private
parsedPromise: Promise<T> | undefined

Methods

private
parse(): Promise<T>
_thenUnwrap<U>(transform: (data: T) => U): APIPromise<U>
asResponse(): Promise<Response>

Gets the raw Response instance instead of parsing the response data.

If you want to parse the response body but still get the Response instance, you can use withResponse().

👋 Getting the wrong TypeScript type for Response? Try setting "moduleResolution": "NodeNext" if you can, or add one of these imports before your first import … from 'openai':

  • import 'openai/shims/node' (if you're running on Node)
  • import 'openai/shims/web' (otherwise)
catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | undefined | null): Promise<T | TResult>
finally(onfinally?: (() => void) | undefined | null): Promise<T>
then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): Promise<TResult1 | TResult2>
withResponse(): Promise<{ data: T; response: Response; }>

Gets the parsed response data and the raw Response instance.

If you just want to get the raw Response instance without parsing it, you can use asResponse().

👋 Getting the wrong TypeScript type for Response? Try setting "moduleResolution": "NodeNext" if you can, or add one of these imports before your first import … from 'openai':

  • import 'openai/shims/node' (if you're running on Node)
  • import 'openai/shims/web' (otherwise)