/** * Token and Cost Estimator * * Estimates token usage and cost for LLM API calls. * Uses approximate token counting (4 characters per token for English text). * * Pricing is NOT owned here — it is sourced from the provider descriptors (the * single source of truth) via `getModelPricing` from `config/providers.config`. * This module only turns that pricing into token/cost estimates. */ import type { LLMMessage, LLMUsage } from '../types/llm.types.js'; import type { ModelPricing } from '../types/model.types.js'; export interface TokenEstimate { /** Estimated cost in USD */ estimatedCost: { amount: number; currency: 'USD'; }; /** Estimated completion tokens (based on typical response ratios) */ estimatedCompletionTokens: number; /** Prompt tokens (input) */ promptTokens: number; /** Total estimated tokens */ totalTokens: number; /** Tokens read from cache (optional, populated from actual usage) */ cacheReadTokens?: number; /** Tokens written to cache (optional, populated from actual usage) */ cacheWriteTokens?: number; /** Estimated cost savings from caching in USD (optional) */ cacheSavings?: number; } /** * Estimate token usage and cost for a set of messages * * @param messages - Array of LLM messages * @param model - Model name for pricing lookup * @returns Token estimate with cost */ export declare function estimateTokens(messages: LLMMessage[], model?: string): TokenEstimate; /** * Estimate tokens from a single string * * @param text - Text to estimate * @returns Approximate token count */ export declare function estimateTokensFromText(text: string): number; /** * Format token estimate for display * * @param estimate - Token estimate to format * @returns Formatted string */ export declare function formatTokenEstimate(estimate: TokenEstimate): string; /** * Calculate actual cost from real usage data, including cache pricing * * @param usage - Actual token usage from API response * @param model - Model name for pricing lookup * @returns Total cost and cache savings in USD */ export interface ActualCostResult { cacheReadCost: number; cacheSavings: number; cacheWriteCost: number; inputCost: number; outputCost: number; totalCost: number; unknownModel: boolean; } export declare function calculateActualCost(usage: LLMUsage, model?: string): ActualCostResult; /** * Get pricing info for a model (sourced from the provider descriptors) * * @param model - Model name (registry alias or resolved API id) * @returns Pricing info or undefined */ export declare function getModelPricing(model: string): ModelPricing | undefined; /** * Check if a model has known pricing * * @param model - Model name * @returns True if pricing is available */ export declare function hasKnownPricing(model: string): boolean; //# sourceMappingURL=token-estimator.d.ts.map