Skip to content

std.usage

Generated by sema doc from stdlib/sema/usage.sema. Import with from std.usage import …. For a narrative introduction see std.usage.

std.usage — model usage accounting (design ①).

Accumulate token usage across calls and price it. Replaces hand-rolled (result, usage) tuple threading and SymbolicAI’s ~470-line MetadataTracker. Pricing is passed in by the caller — rates are never hardcoded. (For ambient, automatic accounting see the with meter as u: scope, §3.6.)

Fields

field type descriptor
prompt_tokens int
completion_tokens int
reasoning_tokens int
cached_tokens int
total_calls int
total_tokens int
cost_estimate f64

Fields

field type descriptor
input f64
cached_input f64
output f64
calls f64
def zero() -> Usage !{}

Returns Usage

Effects !{}

def estimate_cost(u: Usage, p: Pricing) -> f64 !{}

Parameters

name type
u Usage
p Pricing

Returns f64

Effects !{}