|
|
@@ -24,7 +24,7 @@ import {
|
|
|
FreeUsageLimitError,
|
|
|
SubscriptionUsageLimitError,
|
|
|
} from "./error"
|
|
|
-import { createBodyConverter, createStreamPartConverter, createResponseConverter, UsageInfo } from "./provider/provider"
|
|
|
+import { buildCostChunk, createBodyConverter, createStreamPartConverter, createResponseConverter, UsageInfo } from "./provider/provider"
|
|
|
import { anthropicHelper } from "./provider/anthropic"
|
|
|
import { googleHelper } from "./provider/google"
|
|
|
import { openaiHelper } from "./provider/openai"
|
|
|
@@ -90,7 +90,7 @@ export async function handler(
|
|
|
const projectId = input.request.headers.get("x-opencode-project") ?? ""
|
|
|
const ocClient = input.request.headers.get("x-opencode-client") ?? ""
|
|
|
logger.metric({
|
|
|
- is_tream: isStream,
|
|
|
+ is_stream: isStream,
|
|
|
session: sessionId,
|
|
|
request: requestId,
|
|
|
client: ocClient,
|
|
|
@@ -230,7 +230,7 @@ export async function handler(
|
|
|
const body = JSON.stringify(
|
|
|
responseConverter({
|
|
|
...json,
|
|
|
- cost: calculateOccuredCost(billingSource, costInfo),
|
|
|
+ cost: calculateOccurredCost(billingSource, costInfo),
|
|
|
}),
|
|
|
)
|
|
|
logger.metric({ response_length: body.length })
|
|
|
@@ -274,8 +274,8 @@ export async function handler(
|
|
|
await trialLimiter?.track(usageInfo)
|
|
|
await trackUsage(sessionId, billingSource, authInfo, modelInfo, providerInfo, usageInfo, costInfo)
|
|
|
await reload(billingSource, authInfo, costInfo)
|
|
|
- const cost = calculateOccuredCost(billingSource, costInfo)
|
|
|
- c.enqueue(encoder.encode(usageParser.buidlCostChunk(cost)))
|
|
|
+ const cost = calculateOccurredCost(billingSource, costInfo)
|
|
|
+ c.enqueue(encoder.encode(buildCostChunk(opts.format, cost)))
|
|
|
}
|
|
|
c.close()
|
|
|
return
|
|
|
@@ -818,7 +818,7 @@ export async function handler(
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- function calculateOccuredCost(billingSource: BillingSource, costInfo: CostInfo) {
|
|
|
+ function calculateOccurredCost(billingSource: BillingSource, costInfo: CostInfo) {
|
|
|
return billingSource === "balance" ? (costInfo.totalCostInCent / 100).toFixed(8) : "0"
|
|
|
}
|
|
|
|