UNPKG

@juspay/neurolink

Version:

Universal AI Development Platform with working MCP integration, multi-provider support, voice (TTS/STT/realtime), and professional CLI. 58+ external MCP servers discoverable, multimodal file processing, RAG pipelines. Build, test, and deploy AI applicatio

110 lines (109 loc) 3.4 kB
/** * Token Usage Tracker * Aggregates token usage and cost across spans */ import type { ObservabilityModelPricing, SpanData, TokenUsageStats } from "../types/index.js"; /** * Token tracker for aggregating usage across spans */ export declare class TokenTracker { private stats; private customPricing; /** * Set custom pricing for a single model * @param modelName - The model name (e.g., "gpt-4o", "claude-3-5-sonnet") * @param pricing - The pricing information */ setObservabilityModelPricing(modelName: string, pricing: ObservabilityModelPricing): void; /** * Update pricing for an existing model (alias for setObservabilityModelPricing) * @param model - The model name * @param pricing - The new pricing information */ updatePricing(model: string, pricing: ObservabilityModelPricing): void; /** * Load pricing configuration from a config object * Useful for loading pricing from environment or config files * @param config - Record of model names to pricing information */ loadPricingFromConfig(config: Record<string, ObservabilityModelPricing>): void; /** * Get pricing for a specific model * @param model - The model name * @returns The pricing information or undefined if not found */ getModelPricing(model: string): ObservabilityModelPricing | undefined; /** * Get all available model pricing (custom + built-in) * @returns Record of all model pricing */ getAllPricing(): Record<string, ObservabilityModelPricing>; /** * Remove custom pricing for a model (falls back to built-in) * @param model - The model name to remove custom pricing for */ removeCustomPricing(model: string): boolean; /** * Track token usage from a span */ trackSpan(span: SpanData): void; /** * Calculate cost from token counts and provider/model */ private calculateCost; /** * Track token usage from a simple usage object * This is a convenience method for tracking usage without a full span * @param usage - Token usage data */ trackUsage(usage: { promptTokens?: number; completionTokens?: number; totalTokens?: number; model?: string; provider?: string; }): void; /** * Get current stats */ getStats(): TokenUsageStats; /** * Get stats for a specific time window of spans */ getStatsForWindow(spans: SpanData[]): TokenUsageStats; /** * Reset all stats */ reset(): void; /** * Export stats as JSON */ toJSON(): Record<string, unknown>; /** * Format cost as currency string */ formatCost(cost: number, currency?: string): string; /** * Get a summary string of current stats */ getSummary(): string; } /** * Enrich span with token usage attributes */ export declare function enrichSpanWithTokenUsage(span: SpanData, usage: { promptTokens?: number; completionTokens?: number; totalTokens?: number; cacheCreationTokens?: number; cacheReadTokens?: number; reasoningTokens?: number; }): SpanData; /** * Get the global token tracker instance */ export declare function getTokenTracker(): TokenTracker; /** * Reset the global token tracker (for testing) */ export declare function resetTokenTracker(): void;