@@ -19,6 +19,7 @@ import {
1919 calculateCost ,
2020 prepareToolExecution ,
2121 prepareToolsWithUsageControl ,
22+ sumToolCosts ,
2223} from '@/providers/utils'
2324import { executeTool } from '@/tools'
2425
@@ -490,7 +491,7 @@ export async function executeAnthropicProviderRequest(
490491 }
491492
492493 const toolCalls = [ ]
493- const toolResults = [ ]
494+ const toolResults : any [ ] = [ ]
494495 const currentMessages = [ ...messages ]
495496 let iterationCount = 0
496497 let hasUsedForcedTool = false
@@ -783,10 +784,12 @@ export async function executeAnthropicProviderRequest(
783784 }
784785
785786 const streamCost = calculateCost ( request . model , usage . input_tokens , usage . output_tokens )
787+ const tc = sumToolCosts ( toolResults )
786788 streamingResult . execution . output . cost = {
787789 input : accumulatedCost . input + streamCost . input ,
788790 output : accumulatedCost . output + streamCost . output ,
789- total : accumulatedCost . total + streamCost . total ,
791+ toolCost : tc || undefined ,
792+ total : accumulatedCost . total + streamCost . total + tc ,
790793 }
791794
792795 const streamEndTime = Date . now ( )
@@ -829,6 +832,7 @@ export async function executeAnthropicProviderRequest(
829832 cost : {
830833 input : accumulatedCost . input ,
831834 output : accumulatedCost . output ,
835+ toolCost : undefined as number | undefined ,
832836 total : accumulatedCost . total ,
833837 } ,
834838 } ,
@@ -901,7 +905,7 @@ export async function executeAnthropicProviderRequest(
901905 }
902906
903907 const toolCalls = [ ]
904- const toolResults = [ ]
908+ const toolResults : any [ ] = [ ]
905909 const currentMessages = [ ...messages ]
906910 let iterationCount = 0
907911 let hasUsedForcedTool = false
@@ -1208,10 +1212,12 @@ export async function executeAnthropicProviderRequest(
12081212 }
12091213
12101214 const streamCost = calculateCost ( request . model , usage . input_tokens , usage . output_tokens )
1215+ const tc2 = sumToolCosts ( toolResults )
12111216 streamingResult . execution . output . cost = {
12121217 input : cost . input + streamCost . input ,
12131218 output : cost . output + streamCost . output ,
1214- total : cost . total + streamCost . total ,
1219+ toolCost : tc2 || undefined ,
1220+ total : cost . total + streamCost . total + tc2 ,
12151221 }
12161222
12171223 const streamEndTime = Date . now ( )
@@ -1254,6 +1260,7 @@ export async function executeAnthropicProviderRequest(
12541260 cost : {
12551261 input : cost . input ,
12561262 output : cost . output ,
1263+ toolCost : undefined as number | undefined ,
12571264 total : cost . total ,
12581265 } ,
12591266 } ,
0 commit comments