@@ -45,6 +45,7 @@ export interface SessionErrorCompleteParams {
4545 stackTrace ?: string
4646 }
4747 traceSpans ?: TraceSpan [ ]
48+ skipCost ?: boolean
4849}
4950
5051export interface SessionCancelledParams {
@@ -342,27 +343,42 @@ export class LoggingSession {
342343 }
343344
344345 try {
345- const { endedAt, totalDurationMs, error, traceSpans } = params
346+ const { endedAt, totalDurationMs, error, traceSpans, skipCost } = params
346347
347348 const endTime = endedAt ? new Date ( endedAt ) : new Date ( )
348349 const durationMs = typeof totalDurationMs === 'number' ? totalDurationMs : 0
349350 const startTime = new Date ( endTime . getTime ( ) - Math . max ( 1 , durationMs ) )
350351
351352 const hasProvidedSpans = Array . isArray ( traceSpans ) && traceSpans . length > 0
352353
353- const costSummary = hasProvidedSpans
354- ? calculateCostSummary ( traceSpans )
355- : {
356- totalCost : BASE_EXECUTION_CHARGE ,
354+ // When skipCost is true (preprocessing errors), don't charge anything
355+ // When we have trace spans, calculate actual cost from them
356+ // Otherwise, charge the base execution fee for errors that occurred during execution
357+ const costSummary = skipCost
358+ ? {
359+ totalCost : 0 ,
357360 totalInputCost : 0 ,
358361 totalOutputCost : 0 ,
359362 totalTokens : 0 ,
360363 totalPromptTokens : 0 ,
361364 totalCompletionTokens : 0 ,
362- baseExecutionCharge : BASE_EXECUTION_CHARGE ,
365+ baseExecutionCharge : 0 ,
363366 modelCost : 0 ,
364367 models : { } ,
365368 }
369+ : hasProvidedSpans
370+ ? calculateCostSummary ( traceSpans )
371+ : {
372+ totalCost : BASE_EXECUTION_CHARGE ,
373+ totalInputCost : 0 ,
374+ totalOutputCost : 0 ,
375+ totalTokens : 0 ,
376+ totalPromptTokens : 0 ,
377+ totalCompletionTokens : 0 ,
378+ baseExecutionCharge : BASE_EXECUTION_CHARGE ,
379+ modelCost : 0 ,
380+ models : { } ,
381+ }
366382
367383 const message = error ?. message || 'Execution failed before starting blocks'
368384
0 commit comments