Skip to main content

Module spend

Module spend 

Source
Expand description

What each agent has used through the gateway today, counted from the usage in each response times the route’s price table. The live table is in memory; once attach has been called every change is also written to the history store (storage::spend_day) and the last two days are read back at start, so an srv restart does not start the day again. The day is the UTC day.

Structs§

Spend

Functions§

agents_today
The agents that have a day of spend today.
alerted
The highest alert level (0, 50, 80 or 100) already sent for the agent’s day.
attach
Keeps the day’s table in store from now on: reads the last two days, then writes each change from a thread of its own.
cost
The cost of tokens on model: a cached read at the cache price, the rest of the input at the input price.
record
Adds one response to the agent’s day on route and returns that response’s cost: the provider’s own charge when the response reported one (actual), else the price table’s estimate.
reset_session
Clears agent’s provider-reported session total: a new process (spawn, restart, resume) starts its own, as the harness’s own total does.
reset_today
Zeroes the agent’s day (a spend that was wrong): its rows are removed, here and in the store. Returns the dollars that were counted.
restore
Reads the last two days back from store into the live table, keeping what the table already holds. Returns the number of rows read.
rewrite_result_total
line, a JSON frame from the harness, with a route agent’s result totals replaced by the provider’s own charge: the harness prices its tokens with Claude’s rates, which on a route are wrong by orders of magnitude (#30143). total_cost_usd becomes the session total, which the turn ledger takes the rise of; cost_usd becomes this turn’s rise, because the pane adds each frame’s value to its running total. None when the line is not a result frame, reports no total, or the agent is not on a route (none of its responses carried a charge).
route_today_usd
What every agent has spent on route so far today.
session_usd
The provider-reported spend for agent since reset_session, or None when none of its responses reported a charge (the agent is not on a route).
set_alerted
Records the alert level sent for the agent’s day, on each of its rows so it survives a restart. A raised cap sets it back down to where the day now stands.
today
The agent’s use so far today, over every route it used.