claude-cost 0.1.0

Calculate Claude API call cost from a usage block. Cache-aware (cache_creation, cache_read), supports Anthropic API and AWS Bedrock model IDs, BYO pricing override. No SDK dependency.
Documentation
//! # 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);
//! ```

#![deny(missing_docs)]

mod normalize;
mod pricing;
mod usage;

pub use normalize::normalize_model_id;
pub use pricing::{default_pricing, Pricing, DEFAULT_PRICING_TABLE};
pub use usage::Usage;