Skip to content

feat: track OpenRouter usage#134

Open
wjiayis wants to merge 13 commits intostagingfrom
feat/proj-cost-track
Open

feat: track OpenRouter usage#134
wjiayis wants to merge 13 commits intostagingfrom
feat/proj-cost-track

Conversation

@wjiayis
Copy link
Copy Markdown
Member

@wjiayis wjiayis commented Mar 22, 2026

Store usage information in database to track user behavior (if user is not BYOK) as a precursor to billing users, e.g.,

Hourly:

  {
    _id: ObjectId('69cd2e9a926e4b5665909027'),
    user_id: ObjectId('6975da46d6096ac1b07342c2'),
    hour_bucket: ISODate('2026-04-01T14:00:00.000Z'),
    project_id: '69746440592738ba2708cc34',
    success_cost: 0.014026150000000001,
    failed_cost: 0.024026150312000001,
    updated_at: ISODate('2026-04-01T14:41:37.465Z')
  }

Weekly:

  {
    _id: ObjectId('69cd2e9a926e4b5665909028'),
    week_bucket: ISODate('2026-03-30T00:00:00.000Z'),
    project_id: '69746440592738ba2708cc34',
    user_id: ObjectId('6975da46d6096ac1b07342c2'),
    success_cost: 0.014026150000000001,
    failed_cost: 0.024026150312000001,
    updated_at: ISODate('2026-04-01T14:41:37.465Z')
  }

Lifetime:

  {
    _id: ObjectId('69cd2e9a926e4b5665909029'),
    user_id: ObjectId('6975da46d6096ac1b07342c2'),
    project_id: '69746440592738ba2708cc34',
    success_cost: 0.014026150000000001,
    failed_cost: 0.024026150312000001,
    updated_at: ISODate('2026-04-01T14:41:37.465Z')
  }

@wjiayis wjiayis self-assigned this Mar 22, 2026
@wjiayis wjiayis added the enhancement New feature or request label Mar 22, 2026
@wjiayis wjiayis requested review from 4ndrelim and Junyi-99 and removed request for Junyi-99 March 22, 2026 08:49
@wjiayis
Copy link
Copy Markdown
Member Author

wjiayis commented Mar 22, 2026

For discussion: do we plan to / how do we track token usage for XtraMCP?

Junyi-99
Junyi-99 previously approved these changes Mar 23, 2026
@4ndrelim
Copy link
Copy Markdown
Member

4ndrelim commented Mar 25, 2026

For discussion: do we plan to / how do we track token usage for XtraMCP?

That's a good question. With the current approach of tracking by project ID, it makes it difficult to track tokens across the two backend. There are two approaches:

  1. Requests to xtramcp, and the responses, go through PD backend via internal/services/toolkit/toolcall_v2.go. We can track tokens coming in and out.
  2. Alternatively, since tokens are tracked on the DB, xtramcp can similarly access it and update tokens tracking.

The latter approach will require passing in project ID to xtramcp and there will be some coupling between xtramcp and DB service for tokens tracking. The former might be easier to manage since all tokens tracking is managed in PD, but we might need additional logic / info passed from xtramcp to get accurate token tracking since not all MCP functions rely on LLM generation (for example, citation verifier or relevant papers search). We may end-up over counting.

Maybe we can leave this for now, and focus on the PD tokens tracking first. There will be some major enhancements (incorporation of skills) for xtramcp. It may even replace some of the existing functionalities. Though i havent gotten around into exploring fully yet. Once this is firmed up, let's revisit.

4ndrelim
4ndrelim previously approved these changes Mar 25, 2026
Copy link
Copy Markdown
Member

@4ndrelim 4ndrelim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wjiayis Thanks for taking this up. Let's test this on staging, and propose a meet with the rest again to decide on a launch timeline. We can propose early on but set a later date, thinking it might be apt to do an upgrade to some of the backend LLM capabilities, and we can launch all these together.

@Junyi-99
Copy link
Copy Markdown
Member

@4ndrelim Hi andre, the staging environment is currently unavailable, i will try to fix it on weekends.

@wjiayis wjiayis dismissed stale reviews from 4ndrelim and Junyi-99 via 3d2ce5e March 27, 2026 13:48
@Junyi-99
Copy link
Copy Markdown
Member

@4ndrelim
Copy link
Copy Markdown
Member

4ndrelim commented Mar 31, 2026

Let's find a date this week to run through this on staging.

@kah-seng I believe we havent tested yours on staging as well. Should we also pick a date this week? Not sure if its too much to do both at once or if there is anything to de-conflict. If not, we can split.

@wjiayis
Copy link
Copy Markdown
Member Author

wjiayis commented Apr 1, 2026

@4ndrelim All comments have been resolved and this branch is ready for merging into staging. I'll merge it after @kah-seng finish testing his changes on staging, for clarity.

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants