/** * Token cost service that tracks LLM token usage and costs. * * Fetches pricing data from LiteLLM repository and caches it for 1 day. * Automatically tracks token usage when LLMs are registered and invoked. */ import { ModelPricing, ModelUsageStats, ModelUsageTokens, TokenCostCalculatedHelper, TokenUsageEntry, UsageSummary } from './views'; import { BaseChatModel } from '../llm/base'; import { ChatInvokeUsage } from '../llm/views'; /** * Service for tracking token usage and calculating costs */ export declare class TokenCost { private static readonly CACHE_DIR_NAME; private static readonly CACHE_DURATION_MS; private static readonly PRICING_URL; private include_cost; private usage_history; private registered_llms; private pricing_data; private initialized; private cache_dir; constructor(include_cost?: boolean); /** * Initialize the service by loading pricing data */ initialize(): Promise; /** * Load pricing data from cache or fetch from GitHub */ private loadPricingData; /** * Find the most recent valid cache file */ private findValidCache; /** * Check if a specific cache file is valid and not expired */ private isCacheValid; /** * Load pricing data from a specific cache file */ private loadFromCache; /** * Fetch pricing data from LiteLLM GitHub and cache it with timestamp */ private fetchAndCachePricingData; /** * Get pricing information for a specific model */ getModelPricing(modelName: string): Promise; /** * Calculate cost for a specific model and usage */ calculateCost(model: string, usage: ChatInvokeUsage): Promise; /** * Add token usage entry to history (without calculating cost) */ addUsage(model: string, usage: ChatInvokeUsage): TokenUsageEntry; /** * Log usage to the logger with colors */ private logUsage; /** * Build a clear display of input tokens breakdown with emojis and optional costs */ private buildInputTokensDisplay; /** * Register an LLM to automatically track its token usage * * Guarantees that the same instance is not registered multiple times */ registerLlm(llm: BaseChatModel): BaseChatModel; /** * Get a unique ID for an object (simple hash of object properties) */ private getObjectId; /** * Get usage tokens for a specific model */ getUsageTokensForModel(model: string): ModelUsageTokens; /** * Get summary of token usage and costs (costs calculated on-the-fly) */ getUsageSummary(model?: string, since?: Date): Promise; /** * Format token count with k suffix for thousands */ private formatTokens; /** * Log a comprehensive usage summary per model with colors and nice formatting */ logUsageSummary(): Promise; /** * Get cost breakdown by model */ getCostByModel(): Promise>; /** * Clear usage history */ clearHistory(): void; /** * Force refresh of pricing data from GitHub */ refreshPricingData(): Promise; /** * Clean up old cache files, keeping only the most recent ones */ cleanOldCaches(keepCount?: number): Promise; /** * Ensure pricing data is loaded in the background */ ensurePricingLoaded(): Promise; } //# sourceMappingURL=index.d.ts.map