Skip to content

feat: show a conversation's context size and token usage - #74

Merged
bencode merged 1 commit into
mainfrom
feat/token-usage
Oct 2, 2026
Merged

bencode merged 1 commit into
mainfrom
feat/token-usage

Conversation

@bencode

@bencode bencode commented Oct 2, 2026

Copy link
Copy Markdown
Owner

What

A line under the composer shows two numbers, e.g. 9.1K / 1M · 35.3K used:

  • Context. The current context size, from pi's estimateContextTokens, against the selected model's contextWindow when the catalog states one.
  • Used. Total tokens across every model call in the conversation.

Hovering shows exact numbers, the context percentage, and input/output. Both are computed from the saved messages, so a reopened conversation shows them straight away.

Related changes

  • Vision usage is counted. analyze_image and analyze_pdf_page call the vision model themselves. They now report its usage on the tool result (Metered in tool.ts). Pi keeps it out of the context, and the "used" total includes it.
  • Custom BYOK models have an unknown window. Their contextWindow was a guessed 128k. Pi 1.0 uses it to cap maxTokens once a conversation nears it. It is now 0, which pi reads as unknown, and no window is shown.
  • Composer layout. The attachment, model and effort controls move under the input box, beside the usage line, so the box holds only the text area and the send/stop button. The text area starts at two lines.
  • Selects. All selects draw their own chevron with space from the edge, since the native arrow ignores padding. The model select uses field-sizing: content so its width fits the chosen option rather than the longest one.

Verification

  • pnpm check passes.
  • New tests:
    • A unit test for the usage totals, including tool usage.
    • An integration test that the line appears after a reply and after reopening.
  • Checked in the running app.

A line under the composer shows the current context size, against the
selected model's window when the catalog states one, and the tokens the
conversation has used. Image analysis reports its vision model usage on
the tool result so the total includes it. A reader's own custom endpoint
now declares an unknown context window instead of a guessed 128k.

The attachment, model and effort controls move under the input box,
beside the token usage, so the box holds only the text and the send
button. Selects draw their own chevron, since the native one sits
against the edge, and the model select fits the chosen option.
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