std.usage
Generated by
sema docfromstdlib/sema/usage.sema. Import withfrom 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 eai-search’s
(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.)
struct Usage
Section titled “struct Usage”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 |
struct Pricing
Section titled “struct Pricing”Fields
| field | type | descriptor |
|---|---|---|
input | f64 | |
cached_input | f64 | |
output | f64 | |
calls | f64 |
def zero() -> Usage !{}Returns Usage
Effects !{}
estimate_cost
Section titled “estimate_cost”def estimate_cost(u: Usage, p: Pricing) -> f64 !{}Parameters
| name | type |
|---|---|
u | Usage |
p | Pricing |
Returns f64
Effects !{}