Skip to content

feat(usage): API key name in Recent Requests + Usage by Combo tracking#48

Closed
mahdiwafy wants to merge 5 commits into
Vanszs:mainfrom
mahdiwafy:feat/usage-per-key
Closed

feat(usage): API key name in Recent Requests + Usage by Combo tracking#48
mahdiwafy wants to merge 5 commits into
Vanszs:mainfrom
mahdiwafy:feat/usage-per-key

Conversation

@mahdiwafy

Copy link
Copy Markdown

Summary

Adds API key name column to the Recent Requests card and introduces per-combo usage tracking.

Changes

Recent Requests — API Key column

The Recent Requests card now shows which API key was used for each request. Previously only showed: Status | Model | In/Out | When. Now shows: Status | Key | Model | In/Out | When.

Usage by Combo — new table view

  • New comboName column in usageHistory table (migration 004)
  • comboName flows through the entire request pipeline: chat.jschatCorestreamingHandler/nonStreamingHandlerrequestDetailsaveRequestUsage
  • byCombo aggregation in usageDaily and getUsageStats()
  • New "Usage by Combo" option in the usage table selector

Files changed (11 files, +108/-20)

File Change
open-sse/handlers/chatCore.js Accept comboName param, add to sharedCtx
open-sse/handlers/chatCore/requestDetail.js Pass comboName to saveRequestUsage
open-sse/handlers/chatCore/streamingHandler.js Pass comboName to saveUsageStats
open-sse/handlers/chatCore/nonStreamingHandler.js Pass comboName to saveUsageStats
src/sse/handlers/chat.js Pass comboName through handleSingleModelChat
src/lib/db/migrations/004-add-combo-name-column.js New migration — add comboName TEXT column
src/lib/db/migrations/index.js Register migration 004
src/lib/db/schema.js Add comboName to schema
src/lib/db/repos/usageRepo.js comboName in INSERT, SELECT, aggregation, recentRequests
src/shared/components/UsageStats.js Key column in RecentRequests, Usage by Combo table option

Migration

Migration 004 adds comboName TEXT column to usageHistory. Non-breaking — existing rows get NULL, new rows populate automatically when request comes through a combo.

Testing

  • Build: clean
  • Sandbox tested with production DB (38K+ rows) — API returns correct keyName and comboName fields in recentRequests
  • byApiKey aggregation unaffected (33 entries verified)
  • byCombo aggregation works (0 entries for legacy data, will populate for new combo requests)

…mbo tracking

- Add 'Key' column to Recent Requests card showing API key name
- Add comboName field to usageHistory DB table (migration 004)
- Wire comboName through entire request pipeline:
  chat.js → chatCore → streamingHandler/nonStreamingHandler → requestDetail → usageRepo
- Add byCombo aggregation in usageDaily and getUsageStats
- Add 'Usage by Combo' option in usage table selector
- Include apiKey + keyName in recentRequests API response

Files changed:
- open-sse/handlers/chatCore.js: accept comboName param, add to sharedCtx
- open-sse/handlers/chatCore/requestDetail.js: pass comboName to saveRequestUsage
- open-sse/handlers/chatCore/streamingHandler.js: pass comboName to saveUsageStats
- open-sse/handlers/chatCore/nonStreamingHandler.js: pass comboName to saveUsageStats
- src/sse/handlers/chat.js: pass comboName through handleSingleModelChat
- src/lib/db/migrations/004-add-combo-name-column.js: new migration
- src/lib/db/migrations/index.js: register migration 004
- src/lib/db/schema.js: add comboName column
- src/lib/db/repos/usageRepo.js: comboName in INSERT, SELECT, aggregation, recentRequests
- src/shared/components/UsageStats.js: Key column in RecentRequests, Usage by Combo table
@Vanszs

Vanszs commented Jul 12, 2026

Copy link
Copy Markdown
Owner

open-sse/handlers/chatCore/sseToJsonHandler.js is skipped. comboName is not destructured in handleForcedSSEToJson and missing from saveUsageStats calls (line 142 & 218).
if sse-to-json fallback triggers (e.g. codex/kimi), combo usage stats will leak/drop (comboName becomes null).

fix sseToJsonHandler.js to pass comboName down, then request re-review.

@mahdiwafy

Copy link
Copy Markdown
Author

Fixed. comboName added to handleForcedSSEToJson params + both saveUsageStats calls in sseToJsonHandler.js. Ready for re-review. @Vanszs

@mahdiwafy mahdiwafy closed this Jul 13, 2026
@mahdiwafy mahdiwafy deleted the feat/usage-per-key branch July 13, 2026 02:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants