Repository navigation
Copilot: count every agent round and bill exact credits in VS Code chat sessions - #1752
Merged
Merged
Conversation
…ssions Copilot Chat 0.69 keeps only the last model call of an agent request in result.metadata. Read the request's modelTotals (input, cache reads, output over every call) first, then root completionTokens, then metadata. Carry copilotCredits as nanoAiu so plan credits are exact. Bump the copilot parse tag so cached chat sessions re-parse. modelKeyMatches no longer lets claude-sonnet-4 capture claude-sonnet-4-6.
A chat-session request that records copilotCredits now costs credits x $0.01 through costFromBilling; requests without it stay priced from tokens. A chat session whose id matches a session-state dir is left to the agent-host path so it is counted once.
…by one, re-derive past days A chat-session journal request is left out when the same session has billed agent-host usage (session-state calls with tokens or nanoAiu, or session-store rows). Plan credits rate chat-session requests individually, so older requests in a mixed session keep their estimate. DAILY_CACHE_VERSION 75 with copilot pending re-derive so settled days pick up the new counts.
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.
In agent mode one Copilot message runs many model rounds. VS Code stores the last round in
result.metadata.outputTokens/promptTokensand the request totals incompletionTokens,modelTotalsandcopilotCredits; the chat-session parsers read the last-round fields first, so long agent chats undercounted output badly (a user saw 3.6K output vs 129K, $6.91 vs ~$19.30 billed).modelTotals→ rootcompletionTokens→metadata.outputTokens; input and cache read frommodelTotalswhen present.copilotCreditsis carried asnanoAiu; when present, USD = credits × $0.01 viacostFromBilling(GitHub usage-based billing rate). Requests without credits stay token-priced. Agent-host path unchanged.DAILY_CACHE_VERSION75 and Copilot re-derive version 75, so settled days pick up the fix.claude-sonnet-4-6now displays as Sonnet 4.6 (display matching only; pricing lookup unchanged).Checks: tsc clean; full suite 5211 passed, 0 failed; real-data before/after identical for every non-Copilot provider (16 at 30 days, 22 all-time) and identical overview totals after the v74 → v75 cache migration. Independent review of the money logic and the delta: safe to merge.