Stage 3 of 4. Rust. Plan about 2 hours.
The fixture rate card uses nano-dollars per token. Charge uncached input, cached input and output at separate rates. Every multiplication and sum is checked for overflow, and no floating-point rounding can silently change the bill.
pj token counter and cost meter 3
Implementation boundary
pub fn cost(usage:&Usage,rates:&Rates)->Result<u64,Error>Primary reference: Official reference.
Worked Orchard case
Before coding, review Rust ownership and Result and Tokenizers. Complete stage 2 first.
Use supplied integer rate cards in nano-dollars per token. With input=2, output=5 and cached=1, the recorded request costs 260 nano-dollars. These fixture rates are not current provider prices.
60 uncached * 2 = 120
40 cached * 1 = 40
20 output * 5 = 100
total=260 nano_dollarsBuild and inspect
Multiply and add with checked u64 operations. Do not round each component through floating-point dollars.
Implement the stage in your learner workspace. The CLI helpers are provided adapters and import your functions; they do not substitute the reference solution.
python3 scripts/project_test.py token-counter-and-cost-meter --stage 3 --path learning-artifacts/token-counter-and-cost-meterPredict the intermediate state above, then run the stage. A fresh stub fails; a passing reference run does not establish completion of your learner workspace.
Investigate next
How would an overflow affect budget admission if arithmetic wrapped silently?