/** * Provider Pricing Service * * Fetches and caches pricing data for LLM providers to enable cost-aware routing. * Uses OpenRouter API as the primary data source for comprehensive pricing info. */ import type { Logger } from '../observability/logger.js'; /** * Pricing information for a provider model. */ export interface ProviderPricing { /** Provider name (e.g., 'openai', 'anthropic') */ provider: string; /** Model identifier */ model: string; /** Cost per million input tokens in USD */ inputPerMillion: number; /** Cost per million output tokens in USD */ outputPerMillion: number; /** Data source (e.g., 'openrouter', 'manual') */ source: string; /** When the pricing was last updated */ updatedAt: Date; } /** * Configuration for the pricing service. */ export interface PricingServiceConfig { /** Cache TTL in ms (default: 86400000 = 24 hours) */ cacheTtlMs?: number; /** OpenRouter API key for fetching pricing (optional, uses free endpoint) */ openRouterApiKey?: string; /** Timeout for API requests in ms (default: 10000) */ timeoutMs?: number; } /** * Service for fetching and managing provider pricing data. * * Features: * - Fetches pricing from OpenRouter API * - Caches pricing data with configurable TTL * - Falls back to manual pricing for providers not on OpenRouter * - Provides cost comparison utilities * * @example * ```typescript * const pricing = new PricingService(logger); * await pricing.refresh(); * * // Get pricing for a specific model * const cost = pricing.getPricing('openai', 'gpt-4o'); * * // Sort providers by cost * const sorted = pricing.sortByCost(['openai', 'anthropic', 'deepseek']); * ``` */ export declare class PricingService { private readonly config; private readonly logger; private cache; private lastFetch; constructor(logger: Logger, config?: PricingServiceConfig); /** * Fetch/refresh pricing data from OpenRouter API. */ refresh(): Promise; /** * Get pricing for a specific provider/model. */ getPricing(provider: string, model: string): ProviderPricing | undefined; /** * Get all cached pricing data. */ getAllPricing(): ProviderPricing[]; /** * Sort providers by cost (cheapest first). * Uses average of input/output costs for comparison. */ sortByCost(providers: Array<{ provider: string; model: string; }>): Array<{ provider: string; model: string; cost: number; }>; /** * Get cheapest provider from a list. */ getCheapest(providers: Array<{ provider: string; model: string; }>): { provider: string; model: string; } | undefined; /** * Check if cache is stale. */ isCacheStale(): boolean; /** * Format a cost summary string for logging. */ formatCostSummary(providers: Array<{ provider: string; model: string; }>): string; /** * Calculate estimated cost for a request. */ estimateCost(provider: string, model: string, inputTokens: number, outputTokens: number): number | null; private getCacheKey; private parseOpenRouterResponse; } //# sourceMappingURL=pricing.d.ts.map