💰 feat: Conversation Cost Tracking #9190
Draft
+1,148
−26
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This pull request introduces new conversation cost tracking displays which can be toggled in the Chat section of the Settings menu using the new 'Show cost tracking' switch. In order to support this functionality, a new endpoint to calculate per-message and total token costs for each conversation has been added along with corresponding unit tests, as well as variety of updates to the frontend to fetch and display these costs in the chat UI efficiently.
Backend enhancements:
GET /:conversationId/costs
inmessages.js
to compute and return per-message and total token costs (in tokens and USD) for a conversation, using theTransaction
andMessage
models. [1] [2]Frontend integration:
ChatView.tsx
to fetch conversation costs using a new query hook, manage the visibility of the cost bar based on scroll position, and pass cost data down to message components. [1] [2] [3] [4] [5]MessagesView.tsx
,Message.tsx
,MultiMessage.tsx
,MessageParts.tsx
and their props to accept and propagate cost information for each message. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17]UI updates:
CostBar
component to visually display prompt, completion, and total costs (in tokens and USD) at the bottom of the chat window, with smooth transitions based on scroll position. [1] [2] [3]Change Type
Testing
Manual confirmation of UX / UI consistency and token / price accuracy using AzureOpenAI endpoint
Screenshots
Checklist