Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions apps/sim/lib/logs/execution/logging-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ export function calculateCostSummary(traceSpans: any[]): {
}
}

// Recursively collect all spans with cost information from the trace span tree
const collectCostSpans = (spans: any[]): any[] => {
const costSpans: any[] = []

Expand Down Expand Up @@ -119,12 +118,12 @@ export function calculateCostSummary(traceSpans: any[]): {
totalCost += span.cost.total || 0
totalInputCost += span.cost.input || 0
totalOutputCost += span.cost.output || 0
// Tokens are at span.tokens, not span.cost.tokens
const promptTokens = span.tokens?.prompt ?? span.tokens?.input ?? 0
const completionTokens = span.tokens?.completion ?? span.tokens?.output ?? 0
totalTokens += span.tokens?.total || 0
totalPromptTokens += span.tokens?.prompt || 0
totalCompletionTokens += span.tokens?.completion || 0
totalPromptTokens += promptTokens
totalCompletionTokens += completionTokens

// Aggregate model-specific costs - model is at span.model, not span.cost.model
if (span.model) {
const model = span.model
if (!models[model]) {
Expand All @@ -138,8 +137,8 @@ export function calculateCostSummary(traceSpans: any[]): {
models[model].input += span.cost.input || 0
models[model].output += span.cost.output || 0
models[model].total += span.cost.total || 0
models[model].tokens.prompt += span.tokens?.prompt || 0
models[model].tokens.completion += span.tokens?.completion || 0
models[model].tokens.prompt += promptTokens
models[model].tokens.completion += completionTokens
models[model].tokens.total += span.tokens?.total || 0
}
}
Expand Down