/** * Usage record for a single LLM call */ export interface LLMUsageRecord { provider: string; model: string; inputTokens: number; outputTokens: number; reasoningTokens: number; cacheHitTokens: number; cost: number; timestamp: number; } /** * Image generation usage record */ export interface ImageUsageRecord { model: string; imageCount: number; cost: number; timestamp: number; } /** * Aggregated cost data for a single model */ export interface ModelCostSummary { provider: string; model: string; totalCost: number; callCount: number; totalInputTokens: number; totalOutputTokens: number; totalReasoningTokens: number; totalCacheHitTokens: number; } /** * Aggregated cost data for image generation by model */ export interface ImageCostSummary { model: string; totalCost: number; totalImages: number; callCount: number; } /** * Complete cost summary across all models and providers */ export interface CostSummary { totalCost: number; totalCalls: number; totalInputTokens: number; totalCacheHitTokens: number; totalOutputTokens: number; totalReasoningTokens: number; byModel: Record; images: Record; startTime: number; endTime: number; } /** * Formatted cost summary for display */ export interface FormattedCostSummary { totalCost: string; totalCalls: number; totalTokens: number; duration: string; models: Array<{ model: string; provider: string; cost: string; calls: number; inputTokens: number; cachedTokens: number; outputTokens: number; reasoningTokens: number; }>; images: Array<{ model: string; cost: string; images: number; calls: number; }>; } /** * Tracks and accumulates LLM usage costs across all providers and models. * * This class provides a centralized way to monitor LLM spending, * aggregating costs by model and provider. It can be used by consumers * (such as the engine) to build cost dashboards and spending reports. * * @example * import { LLMCostTracker } from '@adaptic/lumic-utils'; * * const tracker = getLLMCostTracker(); * // ... make LLM calls (cost tracking is automatic when wired in) ... * const summary = tracker.getCostSummary(); * console.log(`Total cost: $${summary.totalCost}`); */ export declare class LLMCostTracker { private usageRecords; private imageRecords; private startTime; /** * Records usage from an LLM call. * * @param provider - The LLM provider ('openai' or 'deepseek') * @param model - The model name (e.g., 'gpt-5', 'deepseek-chat') * @param inputTokens - Number of input/prompt tokens * @param outputTokens - Number of output/completion tokens * @param reasoningTokens - Number of reasoning tokens (default: 0) * @param cacheHitTokens - Number of cache hit tokens (default: 0) */ trackUsage(provider: string, model: string, inputTokens: number, outputTokens: number, reasoningTokens?: number, cacheHitTokens?: number): void; /** * Records usage from an image generation call. * * @param model - The image model name (e.g., 'gpt-image-1') * @param imageCount - Number of images generated */ trackImageUsage(model: string, imageCount: number): void; /** * Returns accumulated costs aggregated by model. * * @returns Record of model name to ModelCostSummary */ getCosts(): Record; /** * Returns accumulated image generation costs aggregated by model. * * @returns Record of model name to ImageCostSummary */ getImageCosts(): Record; /** * Returns a complete cost summary across all models and providers. * * @returns CostSummary with totals and per-model breakdowns */ getCostSummary(): CostSummary; /** * Returns a human-readable formatted cost summary. * * @returns FormattedCostSummary with dollar amounts and readable durations */ getFormattedCostSummary(): FormattedCostSummary; /** * Resets all accumulated cost data and restarts the tracking period. */ resetCosts(): void; /** * Returns the total number of tracked LLM calls (not including images). */ getCallCount(): number; /** * Returns the total number of tracked image generation calls. */ getImageCallCount(): number; } /** * Returns the global LLM cost tracker instance. * Use this for application-wide cost tracking. * * @returns The global LLMCostTracker instance */ export declare function getLLMCostTracker(): LLMCostTracker; /** * Replaces the global LLM cost tracker instance. * Useful for testing or providing a custom implementation. * * @param tracker - The new LLMCostTracker instance to use */ export declare function setLLMCostTracker(tracker: LLMCostTracker): void; /** * Resets the global LLM cost tracker to a fresh instance. * Convenience function equivalent to `setLLMCostTracker(new LLMCostTracker())`. */ export declare function resetLLMCostTracker(): void;