cost-meter 0.1.0

Aggregate LLM API cost across providers, models, and time windows. Provider-agnostic — pairs with claude-cost, openai-cost, gemini-cost, bedrock-cost. No SDK dependency.
Documentation
  • Coverage
  • 100%
    24 out of 24 items documented1 out of 11 items with examples
  • Size
  • Source code size: 25.82 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 473 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 8s Average build duration of successful builds.
  • all releases: 8s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • MukundaKatta/cost-meter
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • MukundaKatta

cost-meter

crates.io docs.rs

Aggregate LLM API cost across providers, models, and time windows. Provider-agnostic — pairs with claude-cost, openai-cost, gemini-cost, and bedrock-cost.

Why

Every team that runs LLMs in production rebuilds the same dashboard: a counter of calls and dollars, broken down by provider and model. This is the small, dependency-free piece that does the counting.

Usage

use cost_meter::{Meter, Call};

let mut meter = Meter::new();

meter.record(Call {
    provider: "anthropic",
    model: "claude-sonnet-4-5",
    input_tokens: 1_000,
    output_tokens: 500,
    cost_usd: 0.0105,
});
meter.record(Call {
    provider: "openai",
    model: "gpt-5",
    input_tokens: 2_000,
    output_tokens: 800,
    cost_usd: 0.0105,
});

let s = meter.snapshot();
println!("total spend: ${:.4} over {} calls", s.total_cost_usd, s.total_calls);

for (provider, b) in meter.by_provider() {
    println!("{provider}: {} calls, ${:.4}", b.calls, b.cost_usd);
}

Pair it with one of the pricing crates:

use claude_cost::{Usage, default_pricing};
use cost_meter::{Meter, Call};

let model = "claude-sonnet-4-5";
let pricing = default_pricing(model).unwrap();
let usage = Usage { input_tokens: 1000, output_tokens: 500, ..Default::default() };
let cost = pricing.cost_for(&usage);

let mut m = Meter::new();
m.record(Call {
    provider: "anthropic",
    model,
    input_tokens: usage.input_tokens,
    output_tokens: usage.output_tokens,
    cost_usd: cost,
});

Features

  • serde — derive Serialize/Deserialize on Bucket and Snapshot.

License

MIT or Apache-2.0.