Skip to content

Conversation

dustinhealy
Copy link
Collaborator

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:

  • Added and tested a new API endpoint GET /:conversationId/costs in messages.js to compute and return per-message and total token costs (in tokens and USD) for a conversation, using the Transaction and Message models. [1] [2]

Frontend integration:

  • Updated 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]
  • Modified 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:

  • Added a new 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

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

Testing

Manual confirmation of UX / UI consistency and token / price accuracy using AzureOpenAI endpoint

Screenshots

Screenshot 2025-08-21 at 3 29 34 AM Per-Message Token and Cost Tracking

Screenshot 2025-08-21 at 3 29 43 AM Prompt, Completion, and Total Conversation Token and Cost Display

Screenshot 2025-08-21 at 3 30 12 AM Settings Toggle to Enable/Disable Cost Tracking Display

Checklist

  • My code adheres to this project's style guidelines
  • I have performed a self-review of my own code
  • I have commented in any complex areas of my code
  • I have made pertinent documentation changes
  • My changes do not introduce new warnings
  • I have written tests demonstrating that my changes are effective or that my feature works
  • Local unit tests pass with my changes
  • A pull request for updating the documentation has been submitted.

@danny-avila danny-avila marked this pull request as draft August 22, 2025 15:46
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.

1 participant