Omni.Usage (Omni v1.2.1)

Copy Markdown View Source

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

Types

t()

Token usage and cost breakdown.

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

t()

@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.

Functions

add(a, b)

@spec add(t(), t()) :: t()

Sums corresponding fields of two usage structs.

new(attrs)

@spec new(Enumerable.t()) :: t()

Creates a new usage struct from a keyword list or map.

sum(usages)

@spec sum([t()]) :: t()

Reduces a list of usage structs into a single summed usage.