Skip to main content
Deno 2 is finally here 🎉️
Learn more
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<WithRequestID<T>>
import { APIPromise } from "https://deno.land/x/openai@v4.64.0/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<WithRequestID<T>>)

Properties

private
parsedPromise: Promise<WithRequestID<T>> | undefined

Methods

private
parse(): Promise<WithRequestID<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<WithRequestID<T> | TResult>
finally(onfinally?: (() => void) | undefined | null): Promise<WithRequestID<T>>
then<TResult1 = WithRequestID<T>, TResult2 = never>(onfulfilled?: ((value: WithRequestID<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)