MCPcopy Create free account
hub / github.com/diillson/chatcli / RecordRealUsage

Method RecordRealUsage

cli/cost_tracker.go:131–158  ·  view source on GitHub ↗

RecordRealUsage records actual token usage from an API response. This is the preferred path — provides accurate cost tracking.

(provider, model string, usage *models.UsageInfo)

Source from the content-addressed store, hash-verified

129// RecordRealUsage records actual token usage from an API response.
130// This is the preferred path — provides accurate cost tracking.
131func (ct *CostTracker) RecordRealUsage(provider, model string, usage *models.UsageInfo) {
132 if usage == nil {
133 return
134 }
135 ct.mu.Lock()
136 defer ct.mu.Unlock()
137
138 key := modelKey(provider, model)
139 rec := ct.getOrCreateRecord(key, provider, model)
140
141 rec.PromptTokens += int64(usage.PromptTokens)
142 rec.CompletionTokens += int64(usage.CompletionTokens)
143 rec.TotalTokens += int64(usage.TotalTokens)
144 rec.CacheCreationTokens += int64(usage.CacheCreationInputTokens)
145 rec.CacheReadTokens += int64(usage.CacheReadInputTokens)
146 rec.Requests++
147 if usage.IsReal {
148 rec.HasRealData = true
149 }
150
151 // Compute cost for this increment
152 ct.recomputeCost(rec)
153 ct.recomputeAggregates()
154
155 ct.lastProvider = provider
156 ct.lastModel = model
157 ct.lastUpdate = time.Now()
158}
159
160// RecordUsage records tokens used for a single LLM request (legacy path).
161func (ct *CostTracker) RecordUsage(provider, model string, promptTokens, completionTokens int) {

Callers 10

RecordUsageMethod · 0.95
EstimateAndRecordMethod · 0.95
TestEmitSessionSummaryFunction · 0.80
executeStreamingTurnMethod · 0.80
handleChatTurnResultMethod · 0.80
RunOnceMethod · 0.80
runMoaTurnNativeMethod · 0.80
RunOnceMethod · 0.80
executeChatAskNativeMethod · 0.80

Calls 6

getOrCreateRecordMethod · 0.95
recomputeCostMethod · 0.95
recomputeAggregatesMethod · 0.95
modelKeyFunction · 0.85
LockMethod · 0.80
UnlockMethod · 0.80

Tested by 1

TestEmitSessionSummaryFunction · 0.64