Skip to main content

Module pricing

Module pricing 

Source
Available on crate feature pricing only.
Expand description

Per-model pricing and cost calculation.

PricingTable is a snapshot of Anthropic’s published rates as of the crate release. Rates are provided in USD per million tokens (input_per_mtok, output_per_mtok, etc.). Server-tool fees are billed per-request.

Anthropic adjusts pricing periodically; treat the bundled rates as a best-effort default and pin your own via PricingTable::custom for billing-critical workloads. When PricingTable::cost is called for a model the table doesn’t know about, the function returns 0.0 and emits a one-time tracing::warn!.

Gated on the pricing feature.

use claude_api::pricing::PricingTable;
use claude_api::types::{ModelId, Usage};

let pricing = PricingTable::default();
let mut usage = Usage::default();
usage.input_tokens = 1_000_000;
usage.output_tokens = 200_000;
let usd = pricing.cost(&ModelId::SONNET_4_6, &usage);
assert!(usd > 0.0);

Structs§

CostBreakdown
Per-category breakdown of a usage cost, all in USD.
ModelPricing
Rates for a single model, all in USD per million tokens unless noted.
PricingTable
Per-model pricing snapshot.