Module cost
Structs§
- Tool
Loop Cost Tracking Context - Context for cost tracking within the tool call loop.
Scoped via
tokio::task_local!at call sites (channels, gateway). - Turn
Usage - Per-scope token/cost accumulator derived from the usage events emitted during a single task-local runtime invocation.
- Unpriced
Model - A model with token usage whose ledger records explicitly report that one or more token-bearing pricing dimensions were unavailable.
Statics§
Functions§
- build_
model_ provider_ pricing - build_
type_ level_ model_ provider_ pricing - check_
tool_ loop_ budget - Check budget before an LLM call. Returns
Nonewhen no cost tracking context is scoped (tests, delegate, CLI without cost config). - compute_
cost_ usd - Compute cost_usd for a provider/model/usage triple using the task-local pricing context but WITHOUT updating any accumulators. For emitting Usage events for rejected attempts where the cost is already accounted via settle_provider_attempts. Prices the usage exactly like the settlement path, including the cache-write band, so the projected rejected cost and the settled record agree.
- provider_
pricing - record_
rejected_ tool_ loop_ cost_ usage - Record usage from a rejected provider attempt without replacing the accepted response’s context-window fill.
- record_
tool_ loop_ cost_ usage - Record token usage from an accepted LLM response via the task-local cost
tracker. Returns
(total_tokens, cost_usd)on success,Nonewhen not scoped or no usage. - tool_
loop_ cost_ tracking_ context_ for_ agent - tool_
loop_ cost_ tracking_ context_ from_ tracker - unpriced_
models_ in_ summary - Return per-model unpriced token subsets from the ledger-derived summary, sorted by model id for stable output.