Skip to main content

Module usage

Module usage 

Source
Expand description

Token usage and cost tracking.

Every response carries a Usage record counting input and output tokens, with optional fields for reasoning and cache tokens when the provider reports them.

Cost tracks monetary cost in microdollars (1 USD = 1,000,000 microdollars). Integer arithmetic avoids floating-point rounding issues when aggregating costs across many requests. Use total_usd for display purposes.

§Invariant

Cost enforces total == input + output at construction time. The fields are private — use Cost::new to build one, and the accessor methods to read values. Deserialization recomputes the total from input and output, ignoring any total in the JSON.

Structs§

Cost
Monetary cost in microdollars (1 USD = 1,000,000 microdollars).
ModelPricing
Pricing information for a specific model.
Usage
Token counts for a single request/response pair.
UsageTracker
Tracks cumulative token usage across multiple LLM calls.