AgentSessionManager.Cost.CostCalculator (AgentSessionManager v0.8.0)

Copy Markdown View Source

Converts token usage counts into USD cost estimates using configurable per-model pricing tables.

Summary

Types

pricing_table()

@type pricing_table() :: map()

rate_entry()

@type rate_entry() :: map()

token_counts()

@type token_counts() :: map()

Functions

calculate(tokens, provider, model, pricing_table)

@spec calculate(token_counts(), String.t() | nil, String.t() | nil, pricing_table()) ::
  {:ok, float()} | {:error, :no_rates}

calculate_run_cost(run, pricing_table)

@spec calculate_run_cost(AgentSessionManager.Core.Run.t(), pricing_table()) ::
  {:ok, float()} | {:error, :no_rates}

default_pricing_table()

@spec default_pricing_table() :: pricing_table()

normalize_legacy_rates(pricing_table)

@spec normalize_legacy_rates(map()) :: map()

resolve_rates(provider, model, pricing_table)

@spec resolve_rates(String.t() | nil, String.t() | nil, pricing_table()) ::
  {:ok, rate_entry()} | {:error, :no_rates}