/** * COST CONTROLLER - Budget management & billing alerts * Per-user budgets, cost attribution, hard stops, soft warnings */ import { ModelProvider } from '../../types/vendors'; export interface CostConfig { default_budget?: number; default_budget_period?: BudgetPeriod; alert_thresholds?: number[]; hard_limit_enabled?: boolean; cost_attribution_enabled?: boolean; currency?: string; } export declare enum BudgetPeriod { HOURLY = "hourly", DAILY = "daily", WEEKLY = "weekly", MONTHLY = "monthly", ANNUAL = "annual", LIFETIME = "lifetime" } export interface Budget { user_id: string; amount: number; period: BudgetPeriod; start_date: Date; end_date?: Date; current_spend: number; alert_thresholds: number[]; alerts_sent: number[]; hard_limit: boolean; metadata?: Record; } export interface CostEntry { id: string; user_id: string; model: string; provider: ModelProvider; timestamp: Date; input_tokens: number; output_tokens: number; total_tokens: number; input_cost: number; output_cost: number; total_cost: number; request_id?: string; metadata?: Record; } export interface CostAlert { id: string; user_id: string; budget_id: string; threshold: number; current_spend: number; budget_amount: number; timestamp: Date; severity: 'info' | 'warning' | 'critical'; message: string; notified: boolean; } export interface CostStats { user_id: string; period: BudgetPeriod; total_cost: number; budget_amount?: number; budget_remaining?: number; budget_used_percentage?: number; total_requests: number; total_tokens: number; cost_by_model: Record; cost_by_provider: Record; average_cost_per_request: number; } export interface ModelPricing { provider: ModelProvider; model: string; input_cost_per_million: number; output_cost_per_million: number; currency: string; } export declare class PricingDatabase { private pricing; constructor(); /** * Get pricing for a model */ getPricing(provider: ModelProvider, model: string): ModelPricing | null; /** * Set pricing for a model */ setPricing(pricing: ModelPricing): void; /** * Calculate cost for tokens */ calculateCost(provider: ModelProvider, model: string, input_tokens: number, output_tokens: number): { input_cost: number; output_cost: number; total_cost: number; } | null; /** * Get all pricing entries */ getAllPricing(): ModelPricing[]; private getPricingKey; private loadDefaultPricing; } export declare class CostController { private config; private pricing_db; private budgets; private cost_entries; private alerts; constructor(config?: CostConfig, pricing_db?: PricingDatabase); /** * Create or update a budget for a user */ setBudget(budget: Budget): void; /** * Get budget for a user */ getBudget(user_id: string): Budget | null; /** * Check if user can make request (within budget) */ canMakeRequest(user_id: string): { allowed: boolean; reason?: string; budget?: Budget; }; /** * Record cost for a request */ recordCost(entry: Omit): CostEntry; /** * Calculate and record cost from token usage */ recordTokenUsage(user_id: string, provider: ModelProvider, model: string, input_tokens: number, output_tokens: number, request_id?: string): CostEntry | null; /** * Get cost statistics for a user */ getStats(user_id: string, period?: BudgetPeriod): CostStats; /** * Get all alerts */ getAlerts(user_id?: string): CostAlert[]; /** * Get pricing database */ getPricingDatabase(): PricingDatabase; private checkAlertThresholds; private createAlert; private shouldResetBudget; private resetBudget; private getPeriodStart; private getPeriodEnd; private filterEntriesByPeriod; private generateId; } export declare class BudgetExceededError extends Error { readonly budget: Budget; readonly current_spend: number; constructor(message: string, budget: Budget); } //# sourceMappingURL=cost-controller.d.ts.map