Method RecordSpendAsync
- Namespace
- MailFathom.Infrastructure.Observability
- Assembly
- MailFathom.Infrastructure.dll
RecordSpendAsync(ChatTokenUsage, CancellationToken)
Adds what one run consumed to the current period.
public Task RecordSpendAsync(ChatTokenUsage usage, CancellationToken cancellationToken)
Parameters
usageChatTokenUsageThe tokens that run sent and received, across every call it made.
cancellationTokenCancellationTokenCancels the write.
Returns
- Task
A task that completes when the period has been charged.
Remarks
Charged once as the run ends rather than once per provider call, which is the cost the ADR above accepted and the cost it refused: a tool loop turns once per message of a backfill, and a database round trip per turn is not what "a run is already about to spend a provider's tokens" pays for. It is charged on every ending, so a run that failed, was refused, or was cancelled part way through still spends what it spent.
Exceptions
- ArgumentNullException
Thrown when
usageis null.