ExLLM.Cost (ex_llm v0.1.0)

View Source

Cost 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

calculate(provider, model, token_usage)

@spec calculate(String.t(), String.t(), ExLLM.Types.token_usage()) ::
  ExLLM.Types.cost_result() | %{error: String.t()}

Calculate cost for token usage.

compare(token_usage, provider_models)

Compare costs across different providers for the same usage.

estimate_tokens(text)

@spec estimate_tokens(String.t() | map() | [map()]) :: non_neg_integer()

Estimate token count for text using heuristic analysis.

format(cost_in_dollars)

@spec format(float()) :: String.t()

Format cost for human-readable display.

get_pricing(provider, model)

@spec get_pricing(String.t(), String.t()) :: %{input: float(), output: float()} | nil

Get pricing for a specific provider and model.

list_pricing()

@spec list_pricing() :: [
  %{
    provider: String.t(),
    model: String.t(),
    input_per_1m: float(),
    output_per_1m: float()
  }
]

List all available models and their pricing.