Report costs for ordinary runs

This commit is contained in:
2026-11-22 18:28:39 +00:00
parent 81a2a7591d
commit d77e3e2f83
5 changed files with 142 additions and 5 deletions

View File

@@ -137,6 +137,9 @@ func NewRunnerWithRepairer(
}
func (r *Runner) Run(ctx context.Context, req domain.RunRequest) (*domain.RunResult, error) {
if observation.CostFromContext(ctx) == nil {
ctx = observation.WithCostAccumulator(ctx, &observation.CostAccumulator{})
}
recorder := observation.FromContext(ctx)
runID := ""
if recorder != nil {
@@ -274,7 +277,7 @@ func (r *Runner) executePreparedRun(
exchange = domain.CaptureExchange(parent, runID, prepared.Messages[parent.MessageCount():], genResp.Content)
}
return &domain.RunResult{
result := &domain.RunResult{
Exchange: exchange,
ParentRunID: prepared.ParentRunID,
RunID: runID,
@@ -295,7 +298,11 @@ func (r *Runner) executePreparedRun(
StartTime: start,
EndTime: end,
Duration: end.Sub(start),
}, nil
}
if cost := observation.CostFromContext(ctx); cost != nil {
result.CostUSD = cost.Observed()
}
return result, nil
}
func wrapGenerationError(err error) error {