pub struct Amount {
pub minor: i64,
pub exponent: u8,
pub unit: String,
}Expand description
An amount of money or credit, in integer minor units.
Not a float, and the reason is not stylistic. A balance is compared against
zero on every routing decision that reads it, and binary floating point
cannot hold ordinary decimal amounts exactly — the nearest f64 to 0.1 is
not 0.1, so sums drift and a comparison near zero can fall either way. The
providers agree: DeepSeek and MiniMax both send decimal strings, and
Anthropic sends integer minor units with an exponent.
Parse a provider’s own representation once, where its precision is still known, rather than passing a float along and re-rendering it.
Fields§
§minor: i64The amount in minor units: 1050 with exponent: 2 is 10.50.
exponent: u8Decimal places in minor. 2 for currencies with cents; 0 for whole
credits or points.
unit: StringWhat the amount is denominated in: a currency code like "USD", or a
provider’s own label for its credits.
A free string rather than a currency enum, because not every pool is money — some are points that convert to no currency, and an enum would force those into a currency slot or drop them.