import { Stream } from "./streaming.js"; import { APIError } from "./error.js"; import { type Readable, type Agent, type RequestInfo, type RequestInit, type Response, type HeadersInit } from "./_shims/index.js"; export { type Response }; export { maybeMultipartFormRequestOptions, multipartFormRequestOptions, createForm, type Uploadable, } from "./uploads.js"; export type Fetch = (url: RequestInfo, init?: RequestInit) => Promise; type PromiseOrValue = T | Promise; type APIResponseProps = { response: Response; options: FinalRequestOptions; controller: AbortController; }; /** * A subclass of `Promise` providing additional helper methods * for interacting with the SDK. */ export declare class APIPromise extends Promise { private responsePromise; private parseResponse; private parsedPromise; constructor(responsePromise: Promise, parseResponse?: (props: APIResponseProps) => PromiseOrValue); _thenUnwrap(transform: (data: T) => U): APIPromise; /** * 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 {@link 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) */ asResponse(): Promise; /** * 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 {@link 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) */ withResponse(): Promise<{ data: T; response: Response; }>; private parse; then(onfulfilled?: ((value: T) => TResult1 | PromiseLike) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike) | undefined | null): Promise; catch(onrejected?: ((reason: any) => TResult | PromiseLike) | undefined | null): Promise; finally(onfinally?: (() => void) | undefined | null): Promise; } export declare abstract class APIClient { baseURL: string; maxRetries: number; timeout: number; httpAgent: Agent | undefined; private fetch; protected idempotencyHeader?: string; constructor({ baseURL, maxRetries, timeout, // 10 minutes httpAgent, fetch: overridenFetch, }: { baseURL: string; maxRetries?: number | undefined; timeout: number | undefined; httpAgent: Agent | undefined; fetch: Fetch | undefined; }); protected authHeaders(opts: FinalRequestOptions): Headers; /** * Override this to add your own default headers, for example: * * { * ...super.defaultHeaders(), * Authorization: 'Bearer 123', * } */ protected defaultHeaders(opts: FinalRequestOptions): Headers; protected abstract defaultQuery(): DefaultQuery | undefined; /** * Override this to add your own headers validation: */ protected validateHeaders(headers: Headers, customHeaders: Headers): void; protected defaultIdempotencyKey(): string; get(path: string, opts?: PromiseOrValue>): APIPromise; post(path: string, opts?: PromiseOrValue>): APIPromise; patch(path: string, opts?: PromiseOrValue>): APIPromise; put(path: string, opts?: PromiseOrValue>): APIPromise; delete(path: string, opts?: PromiseOrValue>): APIPromise; private methodRequest; getAPIList = AbstractPage>(path: string, Page: new (...args: any[]) => PageClass, opts?: RequestOptions): PagePromise; private calculateContentLength; buildRequest(options: FinalRequestOptions): { req: RequestInit; url: string; timeout: number; }; private buildHeaders; /** * Used as a callback for mutating the given `FinalRequestOptions` object. */ protected prepareOptions(options: FinalRequestOptions): Promise; /** * 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`. */ protected prepareRequest(request: RequestInit, { url, options }: { url: string; options: FinalRequestOptions; }): Promise; protected parseHeaders(headers: HeadersInit | null | undefined): Record; protected makeStatusError(status: number | undefined, error: Object | undefined, message: string | undefined, headers: Headers | undefined): APIError; request(options: PromiseOrValue>, remainingRetries?: number | null): APIPromise; private makeRequest; requestAPIList = AbstractPage>(Page: new (...args: ConstructorParameters) => PageClass, options: FinalRequestOptions): PagePromise; buildURL(path: string, query: Req | null | undefined): string; protected stringifyQuery(query: Record): string; fetchWithTimeout(url: RequestInfo, init: RequestInit | undefined, ms: number, controller: AbortController): Promise; protected getRequestClient(): RequestClient; private shouldRetry; private retryRequest; private calculateDefaultRetryTimeoutMillis; private getUserAgent; } export type PageInfo = { url: URL; } | { params: Record | null; }; export declare abstract class AbstractPage implements AsyncIterable { #private; protected options: FinalRequestOptions; protected response: Response; protected body: unknown; constructor(client: APIClient, response: Response, body: unknown, options: FinalRequestOptions); /** * @deprecated Use nextPageInfo instead */ abstract nextPageParams(): Partial> | null; abstract nextPageInfo(): PageInfo | null; abstract getPaginatedItems(): Item[]; hasNextPage(): boolean; getNextPage(): Promise; iterPages(): AsyncGenerator, void, unknown>; [Symbol.asyncIterator](): AsyncGenerator, void, unknown>; } /** * This subclass of Promise will resolve to an instantiated Page once the request completes. * * It also implements AsyncIterable to allow auto-paginating iteration on an unawaited list call, eg: * * for await (const item of client.items.list()) { * console.log(item) * } */ export declare class PagePromise, Item = ReturnType[number]> extends APIPromise implements AsyncIterable { constructor(client: APIClient, request: Promise, Page: new (...args: ConstructorParameters) => PageClass); /** * Allow auto-paginating iteration on an unawaited list call, eg: * * for await (const item of client.items.list()) { * console.log(item) * } */ [Symbol.asyncIterator](): AsyncGenerator, void, unknown>; } export declare const createResponseHeaders: (headers: Awaited>['headers']) => Record; type HTTPMethod = 'get' | 'post' | 'put' | 'patch' | 'delete'; export type RequestClient = { fetch: Fetch; }; export type Headers = Record; export type DefaultQuery = Record; export type KeysEnum = { [P in keyof Required]: true; }; export type RequestOptions | Readable> = { method?: HTTPMethod; path?: string; query?: Req | undefined; body?: Req | null | undefined; headers?: Headers | undefined; maxRetries?: number; stream?: boolean | undefined; timeout?: number; httpAgent?: Agent; signal?: AbortSignal | undefined | null; idempotencyKey?: string; __binaryResponse?: boolean | undefined; __streamClass?: typeof Stream; }; export declare const isRequestOptions: (obj: unknown) => obj is RequestOptions; export type FinalRequestOptions | Readable> = RequestOptions & { method: HTTPMethod; path: string; }; export declare const safeJSON: (text: string) => any; export declare const sleep: (ms: number) => Promise; export declare const castToError: (err: any) => Error; export declare const ensurePresent: (value: T | null | undefined) => T; /** * Read an environment variable. * * Trims beginning and trailing whitespace. * * Will return undefined if the environment variable doesn't exist or cannot be accessed. */ export declare const readEnv: (env: string) => string | undefined; export declare const coerceInteger: (value: unknown) => number; export declare const coerceFloat: (value: unknown) => number; export declare const coerceBoolean: (value: unknown) => boolean; export declare const maybeCoerceInteger: (value: unknown) => number | undefined; export declare const maybeCoerceFloat: (value: unknown) => number | undefined; export declare const maybeCoerceBoolean: (value: unknown) => boolean | undefined; export declare function isEmptyObj(obj: Object | null | undefined): boolean; export declare function hasOwn(obj: Object, key: string): boolean; export declare function debug(action: string, ...args: any[]): void; export declare const isRunningInBrowser: () => boolean; export interface HeadersProtocol { get: (header: string) => string | null | undefined; } export type HeadersLike = Record | HeadersProtocol; export declare const isHeadersProtocol: (headers: any) => headers is HeadersProtocol; export declare const getRequiredHeader: (headers: HeadersLike, header: string) => string; /** * Encodes a string to Base64 format. */ export declare const toBase64: (str: string | null | undefined) => string; export declare function isObj(obj: unknown): obj is Record; //# sourceMappingURL=core.d.ts.map