@@ -24,7 +24,13 @@ import {
2424 FreeUsageLimitError ,
2525 SubscriptionUsageLimitError ,
2626} from "./error"
27- import { createBodyConverter , createStreamPartConverter , createResponseConverter , UsageInfo } from "./provider/provider"
27+ import {
28+ buildCostChunk ,
29+ createBodyConverter ,
30+ createStreamPartConverter ,
31+ createResponseConverter ,
32+ UsageInfo ,
33+ } from "./provider/provider"
2834import { anthropicHelper } from "./provider/anthropic"
2935import { googleHelper } from "./provider/google"
3036import { openaiHelper } from "./provider/openai"
@@ -90,7 +96,7 @@ export async function handler(
9096 const projectId = input . request . headers . get ( "x-opencode-project" ) ?? ""
9197 const ocClient = input . request . headers . get ( "x-opencode-client" ) ?? ""
9298 logger . metric ( {
93- is_tream : isStream ,
99+ is_stream : isStream ,
94100 session : sessionId ,
95101 request : requestId ,
96102 client : ocClient ,
@@ -230,7 +236,7 @@ export async function handler(
230236 const body = JSON . stringify (
231237 responseConverter ( {
232238 ...json ,
233- cost : calculateOccuredCost ( billingSource , costInfo ) ,
239+ cost : calculateOccurredCost ( billingSource , costInfo ) ,
234240 } ) ,
235241 )
236242 logger . metric ( { response_length : body . length } )
@@ -274,8 +280,8 @@ export async function handler(
274280 await trialLimiter ?. track ( usageInfo )
275281 await trackUsage ( sessionId , billingSource , authInfo , modelInfo , providerInfo , usageInfo , costInfo )
276282 await reload ( billingSource , authInfo , costInfo )
277- const cost = calculateOccuredCost ( billingSource , costInfo )
278- c . enqueue ( encoder . encode ( usageParser . buidlCostChunk ( cost ) ) )
283+ const cost = calculateOccurredCost ( billingSource , costInfo )
284+ c . enqueue ( encoder . encode ( buildCostChunk ( opts . format , cost ) ) )
279285 }
280286 c . close ( )
281287 return
@@ -818,7 +824,7 @@ export async function handler(
818824 }
819825 }
820826
821- function calculateOccuredCost ( billingSource : BillingSource , costInfo : CostInfo ) {
827+ function calculateOccurredCost ( billingSource : BillingSource , costInfo : CostInfo ) {
822828 return billingSource === "balance" ? ( costInfo . totalCostInCent / 100 ) . toFixed ( 8 ) : "0"
823829 }
824830
0 commit comments