type SharedRequestOptions = { apiKey?: string; apiUrl?: string; fetch?: typeof fetch; headers?: Record; signal?: AbortSignal; }; declare namespace OpenAICompletionTypes { type RequestOptions = SharedRequestOptions; type Request = { model: string; prompt: string | Array | Array | Array>; suffix?: string | null; max_tokens?: number | null; temperature?: number | null; top_p?: number | null; n?: number | null; logprobs?: number | null; echo?: boolean | null; stop?: string | null | Array; presence_penalty?: number | null; frequency_penalty?: number | null; best_of?: number | null; logit_bias?: Record | null; user?: string; }; type Response = { id: string; object: string; created: number; model: string; choices: Choice[]; usage?: { completion_tokens: number; prompt_tokens: number; total_tokens: number; }; }; type Choice = { text: string; index: number; logprobs: { text_offset?: Array; token_logprobs?: Array; tokens?: Array; top_logprobs?: Array>; } | null; finish_reason: 'stop' | 'length'; }; type Chunk = { id: string; object: string; created: number; model: string; choices: Choice[]; }; } /** * Run a completion against the OpenAI API. * * @see https://platform.openai.com/docs/api-reference/completions * * @param request The request body sent to OpenAI. See OpenAI's documentation for /v1/completions for supported parameters. * @param options * @param options.apiKey OpenAI API key. * @param options.apiUrl The url of the OpenAI (or compatible) API. Defaults to https://api.openai.com/v1/completions. * @param options.fetch A custom implementation of fetch. Defaults to globalThis.fetch. * @param options.headers Optionally add additional HTTP headers to the request. * @param options.signal An AbortSignal that can be used to abort the fetch request. * @returns OpenAI completion. See OpenAI's documentation for /v1/completions. */ declare function run(request: OpenAICompletionTypes.Request, options: OpenAICompletionTypes.RequestOptions): Promise; /** * Run a streaming completion against the OpenAI API. The resulting stream is the raw unmodified bytes from the API. * * @see https://platform.openai.com/docs/api-reference/completions * * @param request The request body sent to OpenAI. See OpenAI's documentation for /v1/completions for supported parameters. * @param options * @param options.apiKey OpenAI API key. * @param options.apiUrl The url of the OpenAI (or compatible) API. Defaults to https://api.openai.com/v1/completions. * @param options.fetch A custom implementation of fetch. Defaults to globalThis.fetch. * @param options.headers Optionally add additional HTTP headers to the request. * @param options.signal An AbortSignal that can be used to abort the fetch request. * @returns A stream of bytes directly from the API. */ declare function streamBytes(request: OpenAICompletionTypes.Request, options: OpenAICompletionTypes.RequestOptions): Promise>; /** * Run a streaming completion against the OpenAI API. The resulting stream is the parsed stream data as JavaScript objects. * * @see https://platform.openai.com/docs/api-reference/completions * * @param request The request body sent to OpenAI. See OpenAI's documentation for /v1/completions for supported parameters. * @param options * @param options.apiKey OpenAI API key. * @param options.apiUrl The url of the OpenAI (or compatible) API. Defaults to https://api.openai.com/v1/completions. * @param options.fetch A custom implementation of fetch. Defaults to globalThis.fetch. * @param options.headers Optionally add additional HTTP headers to the request. * @param options.signal An AbortSignal that can be used to abort the fetch request. * @returns A stream of objects representing each chunk from the API. */ declare function stream(request: OpenAICompletionTypes.Request, options: OpenAICompletionTypes.RequestOptions): Promise>; /** * Run a streaming completion against the OpenAI API. The resulting stream emits only the string tokens. * * @see https://platform.openai.com/docs/api-reference/completions * * @param request The request body sent to OpenAI. See OpenAI's documentation for /v1/completions for supported parameters. * @param options * @param options.apiKey OpenAI API key. * @param options.apiUrl The url of the OpenAI (or compatible) API. Defaults to https://api.openai.com/v1/completions. * @param options.fetch A custom implementation of fetch. Defaults to globalThis.fetch. * @param options.headers Optionally add additional HTTP headers to the request. * @param options.signal An AbortSignal that can be used to abort the fetch request. * @returns A stream of tokens from the API. */ declare function streamTokens(request: OpenAICompletionTypes.Request, options: OpenAICompletionTypes.RequestOptions): Promise>; /** * An object that encapsulates methods for calling the OpenAI Completion API. */ declare class OpenAICompletion { static run: typeof run; static stream: typeof stream; static streamBytes: typeof streamBytes; static streamTokens: typeof streamTokens; } export { OpenAICompletion, OpenAICompletionTypes };