Show usage stats in context window for BYOK#315394
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes missing token/usage reporting for BYOK models in the Chat “Context Window” by propagating APIUsage through the VS Code Language Model streaming channel (as a custom LanguageModelDataPart) and decoding it back into the ChatResponse.usage returned to the chat layer.
Changes:
- Introduce
CustomDataPartMimeTypes.Usagefor streaming token usage as aLanguageModelDataPart. - Emit usage data parts from BYOK providers (Anthropic/Gemini) and from
CopilotLanguageModelWrapper. - Decode usage data parts in
ExtensionContributedChatEndpointand use them instead of hardcoded zero usage.
Show a summary per file
| File | Description |
|---|---|
| extensions/copilot/src/platform/endpoint/vscode-node/extChatEndpoint.ts | Collect Usage data parts from the response stream and populate ChatResponse.usage (fallback remains zeros). |
| extensions/copilot/src/platform/endpoint/common/endpointTypes.ts | Add CustomDataPartMimeTypes.Usage constant. |
| extensions/copilot/src/extension/conversation/vscode-node/languageModelAccess.ts | Have CopilotLanguageModelWrapper return APIUsage and emit it as a Usage LanguageModelDataPart. |
| extensions/copilot/src/extension/byok/vscode-node/geminiNativeProvider.ts | Emit Gemini BYOK usage as a Usage LanguageModelDataPart. |
| extensions/copilot/src/extension/byok/vscode-node/anthropicProvider.ts | Emit Anthropic BYOK usage as a Usage LanguageModelDataPart. |
Copilot's findings
- Files reviewed: 5/5 changed files
- Comments generated: 4
Contributor
blocks-ci screenshots changedReplace the contents of Updated blocks-ci-screenshots.md<!-- auto-generated by CI — do not edit manually -->
#### editor/codeEditor/CodeEditor/Dark

#### editor/codeEditor/CodeEditor/Light

#### editor/inlineChatZoneWidget/InlineChatZoneWidget/Dark

#### editor/inlineChatZoneWidget/InlineChatZoneWidget/Light

#### editor/inlineChatZoneWidget/InlineChatZoneWidgetTerminated/Dark

#### editor/inlineChatZoneWidget/InlineChatZoneWidgetTerminated/Light
 |
dmitrivMS
approved these changes
May 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #291100
The Context Window widget in chat shows
0%and zero token counts for all BYOK models. The root cause is inExtensionContributedChatEndpoint.makeChatRequest2— the success response hardcoded usage to all zeros.Fix:
Mirror the existing ContextManagement / StatefulMarker pattern by introducing a new CustomDataPartMimeTypes.Usage data part. BYOK providers emit token usage into the response stream as a LanguageModelDataPart, and ExtensionContributedChatEndpoint decodes it into the APIUsage returned to the chat layer.