/** * Cost tracking for AI agent loops * Estimates token usage and calculates costs based on model pricing */ export interface ModelPricing { name: string; inputPricePerMillion: number; outputPricePerMillion: number; cacheWritePricePerMillion?: number; cacheReadPricePerMillion?: number; } export declare const MODEL_PRICING: Record; /** * Resolve pricing for a model ID. * Matches against MODEL_PRICING keys as substrings of the model ID, * so "anthropic/claude-4.5-sonnet-20250929" matches "claude-4.5-sonnet". * More specific matches (longer keys) take priority. */ export declare function resolveModelPricing(model: string): ModelPricing; export interface TokenEstimate { inputTokens: number; outputTokens: number; totalTokens: number; } export interface CostEstimate { inputCost: number; outputCost: number; totalCost: number; } export interface CacheMetrics { cacheCreationTokens: number; cacheReadTokens: number; cacheSavings: number; } export interface IterationCost { iteration: number; tokens: TokenEstimate; cost: CostEstimate; cache?: CacheMetrics; timestamp: Date; } export interface CostTrackerStats { totalIterations: number; totalTokens: TokenEstimate; totalCost: CostEstimate; avgTokensPerIteration: TokenEstimate; avgCostPerIteration: CostEstimate; projectedCost?: CostEstimate; totalCacheSavings: number; iterations: IterationCost[]; } export interface PlanBudget { name: string; /** Monthly spending limit in USD (0 = unlimited/pay-as-you-go) */ monthlyLimit: number; } /** Known plan budgets (approximate monthly API spending limits) */ export declare const KNOWN_PLANS: Record; export interface CostTrackerConfig { model: string; maxIterations?: number; /** Maximum cost in USD before the loop should stop (0 = unlimited) */ maxCost?: number; /** Plan budget for percentage display */ planBudget?: PlanBudget; } /** * Estimate token count from text * Rough approximation: ~4 characters per token for English text */ export declare function estimateTokens(text: string): number; /** * Calculate cost from tokens and pricing */ export declare function calculateCost(tokens: TokenEstimate, pricing: ModelPricing): CostEstimate; /** * Format cost as USD string */ export declare function formatCost(cost: number): string; /** * Format token count with K/M suffixes */ export declare function formatTokens(tokens: number): string; /** * Cost tracker for monitoring loop expenses */ export declare class CostTracker { private config; private pricing; private iterations; private _visionCalls; private _visionCost; constructor(config: CostTrackerConfig); /** * Record an iteration's token usage (estimated from text) */ recordIteration(input: string, output: string): IterationCost; /** * Record an iteration with actual API usage data (includes cache metrics) */ recordIterationWithUsage(usage: { inputTokens: number; outputTokens: number; cacheCreationInputTokens?: number; cacheReadInputTokens?: number; }): IterationCost; /** * Record a vision API call (visual comparison) and add its cost to the running total. */ recordVisionCall(usage: { inputTokens: number; outputTokens: number; }): void; /** Number of vision API calls made */ get visionCalls(): number; /** Total cost of vision API calls */ get visionCost(): number; /** * Get current statistics */ getStats(): CostTrackerStats; /** * Get plan usage percentage (null if no plan budget configured) */ getPlanPercentage(): string | null; /** * Format stats for CLI display */ formatStats(): string; /** * Format a summary for activity.md */ formatSummary(): string; /** * Check if accumulated cost exceeds the configured budget. * Returns the budget and current total if over, null otherwise. */ isOverBudget(): { maxCost: number; currentCost: number; } | null; /** * Get the last iteration's cost */ getLastIterationCost(): IterationCost | undefined; /** * Reset the tracker */ reset(): void; } //# sourceMappingURL=cost-tracker.d.ts.map