1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//! # claude-cost
//!
//! Calculate Claude API call cost from a usage block.
//!
//! Anthropic returns four token counts on a Claude response:
//! `input_tokens`, `output_tokens`, `cache_creation_input_tokens`, and
//! `cache_read_input_tokens`. Each has its own price. This crate gives you
//! a small `Pricing` table for popular Claude models on the Anthropic API
//! and on AWS Bedrock, plus a `Usage` struct that knows how to compute
//! cost from those four fields.
//!
//! Pricing is best-effort and dated; verify against
//! <https://www.anthropic.com/pricing> and
//! <https://aws.amazon.com/bedrock/pricing/> before using these numbers
//! for billing.
//!
//! ## Quick example
//!
//! ```
//! use claude_cost::{Usage, default_pricing};
//!
//! let pricing = default_pricing("claude-sonnet-4-5").unwrap();
//! let usage = Usage {
//! input_tokens: 1_000,
//! output_tokens: 500,
//! cache_creation_input_tokens: 0,
//! cache_read_input_tokens: 0,
//! };
//! let cost = pricing.cost_for(&usage);
//! assert!((cost - 0.0105).abs() < 1e-6); // 1k * $3/1M + 500 * $15/1M
//! ```
//!
//! ## With a Bedrock model id
//!
//! ```
//! use claude_cost::default_pricing;
//! // The crate normalizes inference-profile prefixes (us./eu./apac.) and
//! // arn:aws:bedrock:* IDs back to the underlying model name.
//! assert!(default_pricing("us.anthropic.claude-sonnet-4-5").is_some());
//! ```
//!
//! ## BYO pricing
//!
//! ```
//! use claude_cost::{Pricing, Usage};
//! let custom = Pricing {
//! input_per_mtok: 1.25,
//! output_per_mtok: 5.0,
//! cache_read_per_mtok: 0.125,
//! cache_write_per_mtok: 1.5625,
//! };
//! let usage = Usage::default();
//! let _ = custom.cost_for(&usage);
//! ```
pub use normalize_model_id;
pub use ;
pub use Usage;