multi-provider llm cost calculation with token-based pricing
Calculates real-time API costs for LLM requests across multiple providers (OpenAI, Anthropic, Google, Azure, Ollama, etc.) by parsing token counts and applying provider-specific pricing matrices. The library maintains an internal registry of model pricing tiers that are updated as providers change their rates, enabling developers to estimate costs before or after API calls without manual rate lookups.
Unique: Maintains a centralized, provider-agnostic pricing registry that abstracts away provider-specific rate structures, allowing single-call cost lookups across OpenAI, Anthropic, Google, Azure, and Ollama without conditional logic in application code
vs alternatives: Simpler and more maintainable than manually tracking pricing spreadsheets or hardcoding rates, with built-in support for multiple providers in a single library vs. writing custom cost calculation logic per provider
token count estimation with provider-specific tokenizers
Estimates token counts for text input using provider-specific tokenization algorithms (e.g., tiktoken for OpenAI, custom tokenizers for Anthropic/Google). The library wraps tokenizer implementations and provides a unified interface to get accurate token counts before sending requests, enabling precise cost pre-calculation without making actual API calls.
Unique: Provides a unified tokenization interface that abstracts away provider-specific tokenizer implementations, allowing developers to call a single method regardless of whether they're using OpenAI, Anthropic, or other providers
vs alternatives: More convenient than importing and managing multiple tokenizer libraries separately, with automatic fallback to approximate token counts if exact tokenizers are unavailable
cumulative cost tracking across multiple api calls
Tracks and aggregates costs across multiple LLM API calls within a session, batch, or application lifetime. The library provides methods to log individual call costs and retrieve cumulative statistics, enabling developers to monitor total spend and identify cost spikes without external logging infrastructure.
Unique: Provides simple in-memory cost accumulation without requiring external databases or logging services, making it easy to add cost tracking to existing LLM applications with minimal setup
vs alternatives: Lighter weight than integrating with external cost monitoring platforms, with zero configuration needed for basic tracking use cases
model pricing registry with provider-specific rate structures
Maintains an internal database of model identifiers, their associated providers, and pricing tiers (input cost per 1K tokens, output cost per 1K tokens). The registry is structured to handle provider-specific pricing variations (e.g., different rates for different regions or deployment types) and provides lookup methods to retrieve pricing for any known model without external API calls.
Unique: Centralizes pricing information for multiple providers in a single, version-controlled registry that can be updated independently of provider APIs, reducing runtime dependencies and improving reliability
vs alternatives: More reliable than querying provider pricing APIs at runtime (which can fail or rate-limit), and more maintainable than hardcoding prices throughout application code
cost comparison across model variants and providers
Enables side-by-side cost analysis for different model choices by calculating costs for the same input across multiple models or providers. Developers can pass a prompt and receive a cost breakdown for each model option, facilitating informed decisions about which model to use based on cost-performance tradeoffs.
Unique: Provides a unified comparison interface that abstracts away differences in how various providers price their models, allowing developers to compare costs across OpenAI, Anthropic, Google, and other providers in a single call
vs alternatives: More convenient than manually calculating costs for each model separately, with built-in sorting and filtering to identify the most cost-effective options