Skip to content

fix(plan): estimate Copilot AI credits from tokens and say when the total is incomplete (#1199) - #1201

Merged
iamtoruk merged 3 commits into
mainfrom
fix/copilot-credit-estimate
Aug 31, 2026
Merged

iamtoruk merged 3 commits into
mainfrom
fix/copilot-credit-estimate

Conversation

@iamtoruk

Copy link
Copy Markdown
Member

Fixes #1199.

Problem

Only the Copilot CLI's ~/.copilot/session-store.db rows 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. copilotCreditSpend summed only the exact rows and set creditsIncomplete, but that flag was a bare boolean in JSON: the codeburn plan headline showed a confident 3.9 / 20000 AI Credits with no caveat while GitHub showed 19,326.

Fix

  • Requests without an exact figure are estimated from tokens at the model's listed API rate, 1 credit = $0.01. Verified against real session-store rows: that is exactly how GitHub bills credits (list rate with the cache-read/write split; request_multiplier is 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.
  • New add-only plan fields: estimatedCredits, creditRatedCalls, creditUnratedCalls, creditsNote (spentCredits and creditsIncomplete unchanged in meaning).
  • Headline says so whenever anything is estimated: Copilot Max: ~9800 / 20000 AI Credits (estimated; 4 of 473 requests carry GitHub's exact figure); unchanged when every request is exact.
  • The bar and percentUsed follow 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.
  • A session that carries any exact figure is never estimated on top of, so paired store rows and JSONL twins cannot double count (tested).
  • docs/providers/copilot.md documents 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 --noEmit clean; 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).
  • Dev run on a real machine: 11 Copilot CLI requests, spentCredits 9.334625 matches the session-store sum exactly, creditsIncomplete false, 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).

iamtoruk and others added 3 commits August 31, 2026 03:07
…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.
@iamtoruk

Copy link
Copy Markdown
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.

@iamtoruk
iamtoruk merged commit 1059849 into main Aug 31, 2026
16 checks passed
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.

Codeburn undercounts GitHub Copilot Business AI Credits

1 participant