claude-cost
Calculate Claude API call cost from a usage block.
Cache-aware (cache_creation_input_tokens, cache_read_input_tokens),
works for both Anthropic's first-party API and AWS Bedrock model IDs
(including ARNs, version suffixes, and cross-region inference profiles).
Bring-your-own pricing override. No SDK dependency.
Install
[]
= "0.1"
# optional: deserialize Usage from Anthropic's JSON response shape
= { = "0.1", = ["serde"] }
Use
use ;
let pricing = default_pricing.unwrap;
let usage = Usage ;
let cost = pricing.cost_for;
// cost = 0.001653 USD
Works the same with Bedrock model identifiers:
use default_pricing;
assert!;
assert!;
let arn = "arn:aws:bedrock:us-east-1::foundation-model/anthropic.claude-opus-4-7";
assert!;
Bring your own pricing for unsupported models:
use ;
let custom = Pricing ;
let usage = Usage ;
let cost = custom.cost_for; // = 1.25
What it does NOT do
- No HTTP client. This crate doesn't talk to Anthropic or Bedrock.
- No usage tracking / aggregation. Wrap it yourself if you want a ledger.
- No prompt caching logic. Just cost math from the usage numbers Anthropic returns.
- No tokenizer. Pass the token counts the API gave you.
Pricing source
Built-in rates reflect anthropic.com/pricing and aws.amazon.com/bedrock/pricing as of 2026-Q2. Verify before using these for billing — rates change.
Sibling to bedrock-kit
on the Python side, which embeds the same logic in a full Bedrock client.
License
MIT OR Apache-2.0