Token counts and computed costs for a generation request.
Costs are computed from token counts and the pricing data on the %Model{}
struct. Available on every %Response{} via response.usage.
Struct fields
:input_tokens,:output_tokens— request and generated token counts:cache_read_tokens,:cache_write_tokens— prompt caching token counts:total_tokens— sum of all token counts:input_cost,:output_cost,:cache_read_cost,:cache_write_cost— per-category USD costs derived from model pricing:total_cost— sum of all USD cost fields
All fields default to 0. Use add/2 and sum/1 to accumulate across
multiple requests.
Summary
Functions
Sums corresponding fields of two usage structs.
Creates a new usage struct from a keyword list or map.
Reduces a list of usage structs into a single summed usage.
Types
@type t() :: %Omni.Usage{ cache_read_cost: number(), cache_read_tokens: non_neg_integer(), cache_write_cost: number(), cache_write_tokens: non_neg_integer(), input_cost: number(), input_tokens: non_neg_integer(), output_cost: number(), output_tokens: non_neg_integer(), total_cost: number(), total_tokens: non_neg_integer() }
Token usage and cost breakdown.