This commit is contained in:
2026-08-23 22:52:13 +02:00
parent 8983cfc8a1
commit 296dc3c841
32 changed files with 2025 additions and 52 deletions
+12 -3
View File
@@ -54,9 +54,12 @@ type Call struct {
Error string
FinishReason string
PromptTokens int
OutputTokens int
TotalTokens int
Duration time.Duration
// CachedPromptTokens is the cached subset of PromptTokens — billed far cheaper,
// so cost accounting must know about it.
CachedPromptTokens int
OutputTokens int
TotalTokens int
Duration time.Duration
}
// CallContext is the per-call metadata processing/campaigns attach to ctx before
@@ -110,6 +113,9 @@ type Recorder struct {
mu sync.Mutex
failed bool // stop log-spamming once writes are known to fail
// prices caches ai_model_prices for cost rollup (see cost.go).
prices priceCache
}
// NewRecorder returns a Recorder writing to pool. nil pool yields a no-op recorder.
@@ -170,6 +176,9 @@ func (r *Recorder) Record(ctx context.Context, c Call) {
if err != nil {
r.noteFailure(err)
}
// Roll the same call into the durable daily cost aggregate. ai_call_logs is
// pruned after a week; spend has to survive for years (see cost.go).
r.recordUsage(ctx, c)
}
func (r *Recorder) noteFailure(err error) {