Skip to content

Add detailed token usage#319264

Merged
dbaeumer merged 2 commits into
mainfrom
dbaeumer/unconscious-ant-brown
Jun 1, 2026
Merged

Add detailed token usage#319264
dbaeumer merged 2 commits into
mainfrom
dbaeumer/unconscious-ant-brown

Conversation

@dbaeumer
Copy link
Copy Markdown
Member

@dbaeumer dbaeumer commented Jun 1, 2026

Enhance the display of token usage in the chat interface by calculating and formatting total, input, cached, and output tokens. This update improves the visibility of token metrics for each chat request item.

Copilot AI review requested due to automatic review settings June 1, 2026 06:28
@dbaeumer dbaeumer enabled auto-merge (squash) June 1, 2026 06:28
@dbaeumer dbaeumer self-assigned this Jun 1, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances the Copilot request log tree UI by showing more detailed token usage metrics (total, input, cached, output) for chat request entries, improving observability of per-request and per-prompt token costs.

Changes:

  • Add helpers to compute total tokens and format a token breakdown string for tooltips.
  • Update ChatRequestItem to display total tokens in the description and include a detailed breakdown in the tooltip.
  • Add a per-prompt aggregated token summary on ChatPromptItem (computed from child successful ChatML requests).
Show a summary per file
File Description
extensions/copilot/src/extension/log/vscode-node/requestLogTree.ts Adds token usage aggregation/formatting and surfaces it in request log tree item descriptions/tooltips.

Copilot's findings

  • Files reviewed: 1/1 changed files
  • Comments generated: 2

Comment thread extensions/copilot/src/extension/log/vscode-node/requestLogTree.ts Outdated
Comment on lines 31 to 46
/**
* Serialize MCP server definitions to a JSON-safe format.
* Excludes sensitive headers like Authorization.
*/
function tokenTotal(usage: APIUsage): number {
return usage.total_tokens ?? (usage.prompt_tokens + usage.completion_tokens);
}

function formatTokenBreakdown(usage: APIUsage): string {
const fmt = (n: number) => n.toLocaleString('en-US');
const cached = usage.prompt_tokens_details?.cached_tokens ?? 0;
const input = Math.max(0, usage.prompt_tokens - cached);
return `input: ${fmt(input)}, cached: ${fmt(cached)}, output: ${fmt(usage.completion_tokens)}`;
}

function serializeMcpServers(servers: readonly vscode.McpServerDefinition[]): object[] {
@dbaeumer dbaeumer merged commit 1608eb8 into main Jun 1, 2026
39 of 40 checks passed
@dbaeumer dbaeumer deleted the dbaeumer/unconscious-ant-brown branch June 1, 2026 07:44
@vs-code-engineering vs-code-engineering Bot added this to the 1.124.0 milestone Jun 1, 2026
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.

3 participants