MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / compute_cost

Function compute_cost

atomic-agent/src/provenance/detail.rs:61–64  ·  view source on GitHub ↗

Compute the USD cost for a pair of token counts. Uses [`COST_PER_M_INPUT`] and [`COST_PER_M_OUTPUT`] so every layer that touches token accounting produces identical values. # Example ``` use atomic_agent::provenance::detail::compute_cost; let cost = compute_cost(16_083, 3_746); let expected = (16_083.0 / 1_000_000.0) * 5.0 + (3_746.0 / 1_000_000.0) * 25.0; assert!((cost - expected).abs() < 1e-9

(input_tokens: u32, output_tokens: u32)

Source from the content-addressed store, hash-verified

59/// assert!((cost - expected).abs() < 1e-9);
60/// ```
61pub fn compute_cost(input_tokens: u32, output_tokens: u32) -> f64 {
62 (input_tokens as f64 / 1_000_000.0) * COST_PER_M_INPUT
63 + (output_tokens as f64 / 1_000_000.0) * COST_PER_M_OUTPUT
64}
65
66// ---------------------------------------------------------------------------
67// Shared sub-structs

Callers 4

from_countsMethod · 0.85
addMethod · 0.85
from_phasesMethod · 0.85

Calls

no outgoing calls

Tested by 1