ExLLM.Cost (ex_llm v0.5.0)
View SourceCost calculation functionality for ExLLM.
Provides token estimation, cost calculation, and pricing information for all supported LLM providers.
Summary
Functions
Calculate cost for token usage.
Compare costs across different providers for the same usage.
Estimate token count for text using heuristic analysis.
Format cost for human-readable display.
Get pricing for a specific provider and model.
List all available models and their pricing.
Functions
@spec calculate(String.t(), String.t(), ExLLM.Types.token_usage()) :: ExLLM.Types.cost_result() | %{error: String.t()}
Calculate cost for token usage.
@spec compare(ExLLM.Types.token_usage(), [{String.t(), String.t()}]) :: [ ExLLM.Types.cost_result() ]
Compare costs across different providers for the same usage.
@spec estimate_tokens(String.t() | map() | [map()]) :: non_neg_integer()
Estimate token count for text using heuristic analysis.
Format cost for human-readable display.
Get pricing for a specific provider and model.
@spec list_pricing() :: [ %{ provider: String.t(), model: String.t(), input_per_1m: float(), output_per_1m: float() } ]
List all available models and their pricing.