import { z } from "zod"; import { Result } from "@praha/byethrow"; import { TupleToUnion } from "type-fest"; //#region src/_types.d.ts /** * Available cost calculation modes * - auto: Use pre-calculated costs when available, otherwise calculate from tokens * - calculate: Always calculate costs from token counts using model pricing * - display: Always use pre-calculated costs, show 0 for missing costs */ declare const CostModes: readonly ['auto', 'calculate', 'display']; /** * Union type for cost calculation modes */ type CostMode = TupleToUnion; /** * Available sort orders for data presentation */ declare const SortOrders: readonly ['desc', 'asc']; /** * Union type for sort order options */ type SortOrder = TupleToUnion; /** * Zod schema for model pricing information from LiteLLM */ declare const modelPricingSchema: z.ZodObject<{ input_cost_per_token: z.ZodOptional; output_cost_per_token: z.ZodOptional; cache_creation_input_token_cost: z.ZodOptional; cache_read_input_token_cost: z.ZodOptional; }, "strip", z.ZodTypeAny, { input_cost_per_token?: number | undefined; output_cost_per_token?: number | undefined; cache_creation_input_token_cost?: number | undefined; cache_read_input_token_cost?: number | undefined; }, { input_cost_per_token?: number | undefined; output_cost_per_token?: number | undefined; cache_creation_input_token_cost?: number | undefined; cache_read_input_token_cost?: number | undefined; }>; /** * Type definition for model pricing information */ type ModelPricing = z.infer; //#endregion //#region src/pricing-fetcher.d.ts /** * Fetches and caches model pricing information from LiteLLM * Implements Disposable pattern for automatic resource cleanup */ declare class PricingFetcher implements Disposable { private cachedPricing; private readonly offline; /** * Creates a new PricingFetcher instance * @param offline - Whether to use pre-fetched pricing data instead of fetching from API */ constructor(offline?: boolean); /** * Implements Disposable interface for automatic cleanup */ [Symbol.dispose](): void; /** * Clears the cached pricing data */ clearCache(): void; /** * Loads offline pricing data from pre-fetched cache * @returns Map of model names to pricing information */ private loadOfflinePricing; private handleFallbackToCachedPricing; private ensurePricingLoaded; /** * Fetches all available model pricing data * @returns Map of model names to pricing information */ fetchModelPricing(): Result.ResultAsync, Error>; /** * Gets pricing information for a specific model with fallback matching * Tries exact match first, then provider prefixes, then partial matches * @param modelName - Name of the model to get pricing for * @returns Model pricing information or null if not found */ getModelPricing(modelName: string): Result.ResultAsync; /** * Calculates the cost for given token usage and model * @param tokens - Token usage breakdown * @param tokens.input_tokens - Number of input tokens * @param tokens.output_tokens - Number of output tokens * @param tokens.cache_creation_input_tokens - Number of cache creation tokens * @param tokens.cache_read_input_tokens - Number of cache read tokens * @param modelName - Name of the model used * @returns Total cost in USD */ calculateCostFromTokens(tokens: { input_tokens: number; output_tokens: number; cache_creation_input_tokens?: number; cache_read_input_tokens?: number; }, modelName: string): Result.ResultAsync; /** * Calculates cost from token usage and pricing information * @param tokens - Token usage breakdown * @param tokens.input_tokens - Number of input tokens * @param tokens.output_tokens - Number of output tokens * @param tokens.cache_creation_input_tokens - Number of cache creation tokens * @param tokens.cache_read_input_tokens - Number of cache read tokens * @param pricing - Model pricing rates * @returns Total cost in USD */ calculateCostFromPricing(tokens: { input_tokens: number; output_tokens: number; cache_creation_input_tokens?: number; cache_read_input_tokens?: number; }, pricing: ModelPricing): number; } //#endregion export { CostMode as n, SortOrder as r, PricingFetcher as t };