Skip to main content

cost_per_million

Function cost_per_million 

Source
pub fn cost_per_million(model: &str) -> (f64, f64)
Expand description

Returns (input_price, output_price) in USD per million tokens. Uses substring matching to handle version suffixes (e.g. “claude-sonnet-4-20250514”).

Match order matters: specific names (gpt-4o-mini, o1-mini) are tested before their broader prefixes (gpt-4o, o1) to prevent premature hits. This is tested by the ordering of the if-else chain — adding a new model that is a substring of an existing one must go ABOVE the broader match. Unknown models get a conservative (1.0, 3.0) fallback so cost tracking never silently returns zero for a billable model.