Usage class final

Token accounting for one assistant response, reported inline by providers.

Ported from pi's Usage.

Constructors

Usage({required int input, required int output, required int cacheRead, required int cacheWrite, int? cacheWrite1h, int? reasoning, required int totalTokens, required UsageCost cost})
const
Usage.fromJson(Map<String, dynamic> json)
Deserializes from a JSON map produced by toJson.
factory

Properties

cacheRead → int
Tokens read from the prompt cache.
final
cacheWrite → int
Tokens written to the prompt cache.
final
cacheWrite1h → int?
Subset of cacheWrite written with 1h retention. Only Anthropic reports this split.
final
cost → UsageCost
Cost breakdown in USD.
final
hashCode → int
The hash code for this object.
no setterinherited
input → int
Input (prompt) tokens.
final
output → int
Output (completion) tokens.
final
reasoning → int?
Reasoning/thinking tokens, when the provider reports them. This is a subset of output: output already includes these tokens. Set by providers that expose a reasoning breakdown; null otherwise.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
totalTokens → int
Total tokens as reported by the provider.
final

Methods

copyWith({int? input, int? output, int? cacheRead, int? cacheWrite, int? cacheWrite1h, int? reasoning, int? totalTokens, UsageCost? cost}) → Usage
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toJson() → Map<String, dynamic>
Serializes to a JSON map.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Constants

zero → const Usage
Zero-valued usage, used to seed partial messages before the provider reports real numbers.