Skip to content

[Feature] Token Usage & Cost Indicator per Response #756

Closed

Description

@akramcodez

Description

Display a small, subtle token count (and estimated cost, if applicable) at the bottom of every AI response.

Use Case

When using paid APIs (like OpenRouter or OpenAI), developers are highly sensitive to token usage. A small indicator helps them build an intuition for how much context they are sending and when they need to clear their session to save money.

Proposed Solution

Append a tiny, grayed-out string like (Tokens: 4.2k | ~$0.01) at the bottom of the AI's chat bubble (in the extension) or terminal output (in the CLI).

Alternatives Considered

  • Only showing it in a separate "Usage" tab, but placing it inline with the response is much more helpful for immediate feedback.

Additional Context

  • I have searched existing issues to ensure this is not a duplicate
  • This feature aligns with the project's goals (local-first AI assistance)

Implementation Notes (optional)

  • Most LLM API responses (via Vercel AI SDK) include a usage object in the response payload.
  • In the VS Code extension, this can be injected directly into the DOM below the messages-container.

Contribution Guidelines

  • If you would like to work on this issue, please comment below to ask for assignment first.
  • Before opening a Pull Request, please briefly share your implementation plan in this thread so we can align on the approach!

Activity

  1. added
    enhancement
    on Aug 3, 2026
  2. lakshay-2411 commented on Aug 3, 2026

    @lakshay-2411
    Contributor

    Can I work on this? @akramcodez

  3. akramcodez commented on Aug 3, 2026

    @akramcodez
    MemberAuthor

    Thanks for your interest, @lakshay-2411!

    Before I assign this issue, could you briefly share your implementation plan? I'd like to understand how you're planning to tackle it and ensure we're aligned on the approach.

    Also, please make sure to follow the repository's contributing guidelines. Looking forward to your plan!

  4. lakshay-2411 commented on Aug 4, 2026

    @lakshay-2411
    Contributor

    Brief approach

    For CLI:

    1. In conversation-loop.tsx, result.usage (provider-reported tokens per API call) is already in scope where AssistantMessage is queued - pass it as a new optional prop.
    2. Compute cost with the existing getModelPricing() helper (models.dev rates, cached); omit cost when pricing is unavailable (local models like Ollama).
    3. In AssistantMessage, upgrade the existing gray ~N tokens footer to show real usage + cost, e.g. Tokens: 4.2k | ~$0.01; fall back to the current estimate when the provider reports no usage.
    4. Add compact-number/cost formatters with unit tests, update component specs, add a minor changeset.

    For Extension:
    the extension's chat runs over ACP, and agent_message_chunk has no usage field - so the CLI side must send usage over the protocol (e.g. _meta on the final chunk or a dedicated update), and the webview renders the gray line under each message.

    Questions:
    Per API call or per turn? One user prompt can trigger several API calls in agentic tool loops. Should each rendered assistant message show its own call's usage, or should the whole turn's usage be aggregated into one indicator at the end?

  5. akramcodez commented on Aug 5, 2026

    @akramcodez
    MemberAuthor

    @lakshay-2411 Great, you're assigned to this issue. Let me know if you need any help.

  6. lakshay-2411 commented on Aug 5, 2026

    @lakshay-2411
    Contributor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions