import { AICapabilities, AIInterface, AIMessage, AIModel, AIResponse, BaseAIOptions, ChatOptions, CompletionOptions, EmbeddingOptions, EmbeddingResponse, ImageDescriptionOptions, ImageEmbeddingOptions, ImageGenerationOptions, ImageGenerationResponse, MessageOptions, TTSOptions, TTSResponse, VideoGenerationJob, VideoGenerationOptions, VideoGenerationResult, VideoGenerationStatusResult, Voice, VoiceCloneOptions, VoiceDesignOptions, VoiceListOptions } from '../types'; /** * Determines whether a model uses OpenAI's newer reasoning-model request * shape: `max_completion_tokens` in place of `max_tokens`, and no * `temperature` parameter at all (a non-default `temperature` is rejected * with a 400 error). * * This applies to the `gpt-5` family (`gpt-5`, `gpt-5-mini`, `gpt-5-nano`, * and future `gpt-5*` variants) and the `o`-series reasoning models (`o1`, * `o3`, `o4`, and their variants such as `o1-mini`, `o3-mini`, `o4-mini`). * See OpenAI's reasoning models guide and the Chat Completions API * reference for `max_completion_tokens`: * https://platform.openai.com/docs/guides/reasoning * https://platform.openai.com/docs/api-reference/chat/create * * The match is a conservative prefix/family check so future `gpt-5*` and * `o1`/`o3`/`o4` variants are covered without needing an allowlist update. * Models outside these families (`gpt-4.x`, `gpt-3.5`, etc.) are unaffected * and keep sending `max_tokens` and `temperature` as before. * * Gateway providers (`BifrostProvider`, some `LiteLLMProvider` deployments) * route with a vendor-prefixed model id, e.g. `openai/gpt-5-mini` — see * `BifrostProvider`'s own `defaultModel: 'openai/gpt-4o-mini'` convention in * `bifrost.ts`. Only the final path segment is matched against the family * checks so those gateway-routed ids are recognized the same as a bare * `gpt-5-mini`. * * Internal request-shaping helper: exported at module level only so it can * be unit-tested directly. It is not re-exported from the package entry * point (`src/index.ts`) and is not part of the package's public API. * * @param model - The model identifier (e.g. `gpt-5-mini`, `openai/gpt-5-mini`, `gpt-4.1-mini`) * @returns `true` when the model requires `max_completion_tokens` and rejects `temperature` */ export declare function usesCompletionTokenLimit(model: string | undefined): boolean; /** * Builds the output-token-limit and temperature fields for a chat/completion * request body, shaped for the given model per {@link usesCompletionTokenLimit}. * * For models that require it: sends `max_completion_tokens` and omits * `max_tokens`, and omits `temperature` entirely (never sends a default * value in its place). For all other models: sends `max_tokens` and * `temperature` unchanged. Fields whose source value is `undefined` are * omitted rather than included as `undefined` keys. * * Internal request-shaping helper: exported at module level only so it can * be unit-tested directly. It is not re-exported from the package entry * point (`src/index.ts`) and is not part of the package's public API. */ export declare function buildTokenLimitRequestFields(model: string, maxTokens: number | undefined, temperature: number | undefined): { max_tokens?: number; max_completion_tokens?: number; temperature?: number; }; /** * Shared profile for OpenAI-compatible providers */ export interface OpenAICompatibleProfile { providerLabel: string; providerName: string; defaultModel: string; capabilities: AICapabilities; describeModel(modelId: string): string; getContextLength(modelId: string): number; getModelCapabilities(modelId: string): string[]; shouldIncludeModel(modelId: string): boolean; supportsFunctions(modelId: string): boolean; supportsVision(modelId: string): boolean; } export interface OpenAICompatibleOptions extends BaseAIOptions { type?: string; apiKey?: string; baseUrl?: string; organization?: string; } /** * OpenAI provider implementation that handles all interactions with OpenAI's API. * Supports GPT models, embeddings, function calling, streaming, and vision capabilities. */ export declare class OpenAIProvider implements AIInterface { private client; protected options: OpenAICompatibleOptions; protected readonly profile: OpenAICompatibleProfile; /** * Creates a new OpenAI provider instance * @param options - Configuration options for the OpenAI provider */ constructor(options: OpenAICompatibleOptions, profile?: OpenAICompatibleProfile); /** * Generate a chat completion using OpenAI's chat models * @param messages - Array of conversation messages * @param options - Optional configuration for the chat completion * @returns Promise resolving to the AI response with content and metadata * @throws {AIError} When the API request fails or returns invalid data * * @example * ```typescript * const response = await provider.chat([ * { role: 'system', content: 'You are a helpful assistant.' }, * { role: 'user', content: 'What is the capital of France?' } * ], { * model: 'gpt-4o', * temperature: 0.7, * maxTokens: 150 * }); * console.log(response.content); // "Paris is the capital of France." * ``` */ chat(messages: AIMessage[], options?: ChatOptions): Promise; /** * Generate a text completion for a given prompt * @param prompt - The text prompt to complete * @param options - Optional configuration for the completion * @returns Promise resolving to the AI response * @throws {AIError} When the API request fails * * @example * ```typescript * const response = await provider.complete('The weather today is', { * model: 'gpt-4o', * maxTokens: 50, * temperature: 0.5 * }); * ``` */ complete(prompt: string, options?: CompletionOptions): Promise; /** * Simple message interface for single-turn interactions with optional history * * @param text - The message text to send * @param options - Configuration options including history, model, etc. * @returns Promise resolving to the response content string * * @example * ```typescript * // Simple usage * const response = await provider.message('Hello!'); * * // With options * const response = await provider.message('Analyze this', { * model: 'gpt-4o', * responseFormat: { type: 'json_object' } * }); * * // With history * const response = await provider.message('What was my question?', { * history: [ * { role: 'user', content: 'What is 2+2?' }, * { role: 'assistant', content: '4' } * ] * }); * ``` */ message(text: string, options?: MessageOptions): Promise; /** * Generate embeddings for the given text(s) * @param text - Single text string or array of texts to embed * @param options - Optional configuration for embeddings * @returns Promise resolving to embeddings response with vector arrays * @throws {AIError} When the API request fails * * @example * ```typescript * // Single text embedding * const response1 = await provider.embed('Hello world'); * console.log(response1.embeddings[0]); // Array of numbers * * // Multiple text embeddings * const response2 = await provider.embed(['Text 1', 'Text 2']); * console.log(response2.embeddings.length); // 2 * ``` */ embed(text: string | string[], options?: EmbeddingOptions): Promise; /** * Convert an image to a base64 data URL * @param image - Image as URL, base64 data URL, or Buffer * @returns base64 data URL string * @private */ private imageToBase64; /** * Generate a text description of an image * @param image - Image as URL, base64 data URL, or Buffer * @param prompt - Custom prompt for description (optional) * @param options - Optional configuration * @returns Promise resolving to the description string * * @example * ```typescript * const description = await provider.describeImage('https://example.com/image.jpg'); * ``` */ describeImage(image: string | Buffer, prompt?: string, options?: ImageDescriptionOptions): Promise; /** * Generate embeddings for an image using describe-then-embed pattern * @param image - Image as URL, base64 data URL, or Buffer * @param options - Optional configuration for image embeddings * @returns Promise resolving to embeddings response * * @example * ```typescript * const embedding = await provider.embedImage('https://example.com/image.jpg'); * ``` */ embedImage(image: string | Buffer, options?: ImageEmbeddingOptions): Promise; /** * Generate an image from a text prompt using DALL-E * @param prompt - Text description of the image to generate * @param options - Optional configuration for image generation * @returns Promise resolving to generated image(s) * * @example * ```typescript * const result = await provider.generateImage('A sunset over mountains'); * fs.writeFileSync('image.png', result.images[0].data); * ``` */ generateImage(prompt: string, options?: ImageGenerationOptions): Promise; submitVideoGenerationJob(_options: VideoGenerationOptions): Promise; getVideoGenerationJob(_handle: VideoGenerationJob): Promise; fetchVideoGenerationResult(_handle: VideoGenerationJob): Promise; cancelVideoGenerationJob(_handle: VideoGenerationJob): Promise; validateVideoGenerationAccess(): Promise; /** * Stream a chat completion response in real-time * @param messages - Array of conversation messages * @param options - Optional configuration for the chat completion * @yields Individual content chunks as they arrive * @throws {AIError} When the streaming request fails * * @example * ```typescript * for await (const chunk of provider.stream([ * { role: 'user', content: 'Write a story about AI' } * ])) { * process.stdout.write(chunk); * } * ``` */ stream(messages: AIMessage[], options?: ChatOptions): AsyncIterable; /** * Count the number of tokens in the given text * @param text - The text to count tokens for * @returns Promise resolving to the estimated token count * * @remarks * OpenAI doesn't provide a direct token counting API, so this is an approximation * based on the general rule of ~4 characters per token. For precise counting, * consider using a dedicated tokenizer library. * * @example * ```typescript * const count = await provider.countTokens('Hello, world!'); * console.log(count); // Approximately 4 tokens * ``` */ countTokens(text: string): Promise; /** * Get a list of available OpenAI models * @returns Promise resolving to an array of model information * @throws {AIError} When the API request fails * * @example * ```typescript * const models = await provider.getModels(); * const gptModels = models.filter(m => m.id.includes('gpt')); * ``` */ getModels(): Promise; /** * Get the capabilities supported by this OpenAI provider * @returns Promise resolving to provider capabilities * * @example * ```typescript * const caps = await provider.getCapabilities(); * if (caps.functions) { * // Provider supports function calling * } * ``` */ getCapabilities(): Promise; synthesizeSpeech(_text: string, _options?: TTSOptions): Promise; streamSpeech(_text: string, _options?: TTSOptions): AsyncIterable; cloneVoice(_options: VoiceCloneOptions): Promise; designVoice(_options: VoiceDesignOptions): Promise; getVoices(_options?: VoiceListOptions): Promise; /** * Maps internal AI messages to OpenAI's message format * @param messages - Array of internal AI messages * @returns Array of OpenAI-compatible message parameters * @private */ private mapMessagesToOpenAI; /** * Maps internal tool choice format to OpenAI's tool choice format * @param toolChoice - Internal tool choice specification * @returns OpenAI-compatible tool choice option or undefined * @private */ private mapToolChoice; /** * Maps OpenAI usage information to internal token usage format * @param usage - OpenAI usage object from API response * @returns Internal token usage object or undefined * @private */ private mapUsage; /** * Maps OpenAI finish reason to internal finish reason format * @param reason - OpenAI finish reason from API response * @returns Internal finish reason * @private */ private mapFinishReason; /** * Gets the context length for a given OpenAI model * @param modelId - The OpenAI model identifier * @returns Maximum context length in tokens * @private */ /** * Maps OpenAI API errors to internal AI error types * @param error - The error object from OpenAI API * @returns Appropriate internal AI error instance * @private */ private mapError; } //# sourceMappingURL=openai.d.ts.map