Skip to content

fix(cost-center): the billing module does not calculate LLMToken consumption#6749

Open
jockey-x wants to merge 1 commit intolabring:mainfrom
jockey-x:fix-billing
Open

fix(cost-center): the billing module does not calculate LLMToken consumption#6749
jockey-x wants to merge 1 commit intolabring:mainfrom
jockey-x:fix-billing

Conversation

@jockey-x
Copy link

@jockey-x jockey-x commented Mar 2, 2026

Fix LLMToken cost consistency in consumption APIs

Problem

The getTotalAppCost() method already includes LLMToken fees, but GetConsumptionAmount() and GetWorkspaceConsumptionAmount() only query app_costs.amount, missing the amount field for LLMToken and AppStore types. This causes inconsistent data between the appOverview
endpoint and the consumption endpoints.

Solution

Modified GetConsumptionAmount() and GetWorkspaceConsumptionAmount() in service/account/dao/interface.go to use MongoDB's $facet operator, which queries both:

  1. app_costs.amount - for regular applications (sub-consumption type)
  2. amount field - for AppStore and LLMToken types (direct consumption)

Changes

  • Updated GetConsumptionAmount() to aggregate both cost types and return the sum
  • Updated GetWorkspaceConsumptionAmount() to merge results from both cost types, grouped by namespace

Impact

  • /api/billing/consumption now includes LLMToken costs in the total amount
  • /api/billing/workspace-consumption now includes LLMToken costs per workspace
  • Data consistency is maintained across all billing-related endpoints

@jockey-x jockey-x requested a review from a team as a code owner March 2, 2026 07:53
@cla-assistant
Copy link

cla-assistant bot commented Mar 2, 2026

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants