ExAgent.Message.Usage (ExAgent v3.0.0)

View Source

Qualified metrics for a response or aggregate. accounting is a versioned, string-keyed JSON map, separate from additive token details. Reported means reported to the host by the Model contract, not audited provider presence. Cost is always an estimate in cents, never an invoice.

Stability — Stable.

payload_omitted marks bounded postdecode omission of oversized details or dimensions. Retained metric availability remains explicit; omitted values are not zero. The marker is versioned independently of accounting v1.

An adapter with plain counts can set accounting: nil and use nil for any unreported count. ExAgent.Message.new_response/2 qualifies those counts as reported. Supply a complete version 1 map to describe normalized or partial usage. See the usage example.

The optional accounting key "service_tier" carries the provider's returned tier as a short label. An aggregate keeps the label when its component reports all have the same tier.

The candidate units field optionally describes non-token measurements. It accepts only "audio_input_milliseconds", "audio_output_milliseconds", "input_characters", "output_images", "output_pages" and "rerank_search_units". Each entry has the string keys "value" (a non-negative integer or nil), "availability" and "quality". Values with coverage "available" or "partial" carry a count with quality "measured", "reported", "normalized" or "mixed". An "unavailable" value is nil with "unknown" quality. An omitted unit makes no claim and is neutral when combining reports. Cost and token limits continue to use their own evidence.

Summary

Functions

Return the provider's service tier for this report, or nil when unknown. An aggregate returns a tier when all component reports agree.

Attach a host price in cents. Pass a number for a complete estimate or {:partial, cents} for a known subtotal. Use zero only when it is known. Passing nil as usage starts a report with no token measurements.

Types

t()

@type t() :: %ExAgent.Message.Usage{
  accounting: map() | nil,
  details: map(),
  input_tokens: non_neg_integer() | nil,
  output_tokens: non_neg_integer() | nil,
  payload_omitted: term(),
  units: %{optional(String.t()) => unit()}
}

unit()

(candidate API)
@type unit() :: %{required(String.t()) => non_neg_integer() | String.t() | nil}

Functions

service_tier(arg1)

(candidate API)
@spec service_tier(t() | nil) :: String.t() | nil

Return the provider's service tier for this report, or nil when unknown. An aggregate returns a tier when all component reports agree.

with_estimated_cost(usage, cents)

(candidate API)
@spec with_estimated_cost(t() | nil, number() | {:partial, number()}) :: t()

Attach a host price in cents. Pass a number for a complete estimate or {:partial, cents} for a known subtotal. Use zero only when it is known. Passing nil as usage starts a report with no token measurements.