Repository navigation
fix(plan): estimate Copilot AI credits from tokens and say when the total is incomplete (#1199) - #1201
Merged
Conversation
…otal is incomplete (#1199) Only Copilot CLI session-store rows carry total_nano_aiu, so a typical user has a handful of exactly rated requests and hundreds of unrated ones, and codeburn plan showed the exact-only sum as if it were the whole bill. Price every unrated request from its tokens at listed API rates (1 credit = $0.01) and carry that as estimatedCredits alongside creditRatedCalls / creditUnratedCalls. A session that already carries an exact figure is never estimated on top of: total_nano_aiu bills that request's whole token set, JSONL twin included. spentCredits, the bar and percentUsed stay on GitHub's exact figures. The plan headline, and status JSON via creditsNote, now say how much of the total is estimated.
…l session-store rows (#1199)
Member
Author
|
Follow-up scope note: checked GitHub's quota endpoint on a live account after the June 2026 billing change. It reports only chat, completions and premium_interactions snapshots, no AI-credit figure, so a live authoritative credit number is not available from that endpoint today. The token-priced estimate in this PR stays the local best effort. |
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 #1199.
Problem
Only the Copilot CLI's
~/.copilot/session-store.dbrows carry an exact credit value (total_nano_aiu). VS Code chat sessions, transcripts, the OTel database, JetBrains stores and the CLI session-state JSONL never do, so on a typical machine most Copilot requests have no exact figure.copilotCreditSpendsummed only the exact rows and setcreditsIncomplete, but that flag was a bare boolean in JSON: thecodeburn planheadline showed a confident3.9 / 20000 AI Creditswith no caveat while GitHub showed 19,326.Fix
request_multiplieris the legacy premium-request weight and never touches credits). On Copilot CLI events CodeBurn's pricing landed within about 15% of the exact bill; VS Code sessions record no cache split, so their estimate can land either side.estimatedCredits,creditRatedCalls,creditUnratedCalls,creditsNote(spentCreditsandcreditsIncompleteunchanged in meaning).Copilot Max: ~9800 / 20000 AI Credits (estimated; 4 of 473 requests carry GitHub's exact figure); unchanged when every request is exact.percentUsedfollow the estimate while any request is unrated (a bar at 0% beside a real 19k bill was the misleading picture), and the exact figure once every request carries one.docs/providers/copilot.mddocuments which sources carry exact credits and how to read the note. The menubar payload carries no plan data, so it is untouched.Verification
npx tsc --noEmitclean;npm test: 3905 passed, 5 skipped (9 new tests: estimate math, rated/unrated counts, pairing no-double-count, both headline states, JSON fields end to end).spentCredits9.334625 matches the session-store sum exactly,creditsIncompletefalse, note reads complete.Not in scope here: using the live GitHub quota figure as the authoritative number when a token is available (follow-up once the endpoint's AI-credit snapshot is confirmed).