glean/usage
Token usage.
Types
The tokens one model call used, or the sum over a whole run.
Providers count differently; glean puts their numbers on one scale:
input_tokens and output_tokens are totals, and the other fields say
how much of each total was cached or spent on reasoning.
pub type Usage {
Usage(
input_tokens: Int,
output_tokens: Int,
cache_read_tokens: Int,
cache_write_tokens: Int,
reasoning_tokens: Int,
)
}
Constructors
-
Usage( input_tokens: Int, output_tokens: Int, cache_read_tokens: Int, cache_write_tokens: Int, reasoning_tokens: Int, )Arguments
- input_tokens
-
Every input token, including the ones read from or written to a prompt cache.
- output_tokens
-
Every output token, including the ones spent on reasoning.
- cache_read_tokens
-
Of the input tokens, those read from a prompt cache, which providers bill at a discount.
- cache_write_tokens
-
Of the input tokens, those written to a prompt cache, which Claude bills at a premium. 0 for providers that don’t report it.
- reasoning_tokens
-
Of the output tokens, those spent on reasoning. 0 for providers that don’t report it separately, such as Claude.
Values
pub fn new(
input_tokens input: Int,
output_tokens output: Int,
) -> Usage
Usage with nothing cached and no reasoning reported.