import { ChatCompletionMessageParam } from 'openai/resources/chat';
import { AIConfig } from '../../config/ai.config';
/**
 * Result of an OpenAI completion request
 */
export interface OpenAICompletionResult {
    content: string;
    promptTokens: number;
    completionTokens: number;
    totalTokens: number;
    model: string;
    finishReason: string | null;
    executionTimeMs: number;
}
/**
 * Options for OpenAI completion requests
 */
export interface OpenAICompletionOptions {
    temperature?: number;
    maxTokens?: number;
    topP?: number;
    frequencyPenalty?: number;
    presencePenalty?: number;
    stop?: string | string[];
    systemPrompt?: string;
    responseFormat?: 'text' | 'json';
}
/**
 * Error with retry information
 */
export declare class OpenAIServiceError extends Error {
    readonly code?: string | undefined;
    readonly statusCode?: number | undefined;
    readonly retryable: boolean;
    readonly retryAfterMs?: number | undefined;
    constructor(message: string, code?: string | undefined, statusCode?: number | undefined, retryable?: boolean, retryAfterMs?: number | undefined);
}
/**
 * Service for interacting with OpenAI API
 * Implements GPT-4-turbo client with retry logic, token counting, and error handling
 */
export declare class OpenAIService {
    private client;
    private config;
    private requestCount;
    private totalTokensUsed;
    constructor(config?: AIConfig);
    /**
     * Send a completion request to OpenAI with retry logic
     * @param messages Chat messages to send
     * @param options Additional options for the completion
     * @returns Completion result with token usage
     */
    complete(messages: ChatCompletionMessageParam[], options?: OpenAICompletionOptions): Promise<OpenAICompletionResult>;
    /**
     * Stream a completion from OpenAI
     * @param messages Chat messages to send
     * @param options Additional options for the completion
     * @param onChunk Callback for each streamed chunk
     * @returns Final completion result
     */
    streamComplete(messages: ChatCompletionMessageParam[], options: OpenAICompletionOptions | undefined, onChunk: (chunk: string) => void): Promise<OpenAICompletionResult>;
    /**
     * Execute a function with exponential backoff retry logic
     * @param fn Function to execute
     * @param maxRetries Maximum number of retry attempts
     * @returns Result of the function
     */
    private executeWithRetry;
    /**
     * Check if an error is retryable
     * @param error The error to check
     * @returns True if the error is retryable
     */
    private isRetryableError;
    /**
     * Calculate backoff delay with jitter
     * @param baseDelay Base delay in milliseconds
     * @param attempt Current attempt number
     * @param error The error that occurred
     * @returns Delay in milliseconds
     */
    private calculateBackoffDelay;
    /**
     * Wrap an error with additional context
     * @param error The original error
     * @param retryCount Number of retries attempted
     * @returns Wrapped error
     */
    private wrapError;
    /**
     * Build messages array with optional system prompt
     * @param messages User messages
     * @param systemPrompt Optional system prompt
     * @returns Complete messages array
     */
    private buildMessages;
    /**
     * Estimate token count for a string (rough approximation)
     * @param text Text to estimate tokens for
     * @returns Estimated token count
     */
    private estimateTokens;
    /**
     * Sleep for a specified duration
     * @param ms Duration in milliseconds
     */
    private sleep;
    /**
     * Get token usage statistics
     * @returns Token usage stats
     */
    getUsageStats(): {
        requestCount: number;
        totalTokensUsed: number;
        estimatedCost: number;
    };
    /**
     * Reset usage statistics
     */
    resetUsageStats(): void;
    /**
     * Test the connection to OpenAI API
     * @returns True if connection is successful
     */
    testConnection(): Promise<boolean>;
}
//# sourceMappingURL=openai.service.d.ts.map