codeburn icon indicating copy to clipboard operation
codeburn copied to clipboard

Incorrect costing for copilot usage since the switchover to metered billing

Open stephanjohnson opened this issue 5 months ago • 10 comments

Great project ❤️

Now that copilot is using metered billing... I want to use this a bit more actively 😄

I did update the installation, but I am not sure if the information I am seeing is correct.

Image

vs the GitHub dashboard

Image

I tried running codeburn from the application directory vs globally from my home directory. It made no difference.

Am I doing something wrong?

stephanjohnson avatar Jun 05 '26 02:06 stephanjohnson

I think there's something wrong with how it calculates or includes subagents. I ran a session on sonnet 4.6, spawned a subagent on opus 4.8, and it doesn't show up anywhere. The calculation is definitely off somehow.

dat-intellis avatar Jun 05 '26 09:06 dat-intellis

Thanks for the detailed report (and the screenshots — really helpful) 🙏

What's happening: codeburn estimates Copilot cost from tokens × the underlying model's API price (Copilot's logs don't record a real charge, so it infers the model from the session and prices the tokens at Anthropic/OpenAI API rates). The GitHub dashboard, on the other hand, bills by premium requests / metered usage, which is a request-count × per-model multiplier metric — a completely different unit from token cost. So the two numbers are expected to diverge; codeburn is showing "what these tokens would cost at API rates," not GitHub's billed amount.

This got more visible because of GitHub's billing changes. To build a model that actually matches your dashboard, I need to know which billing system you're on, since GitHub switched from premium-request billing to usage-based "AI Credits" on June 1, 2026 (annual Pro/Pro+ plans stay on the legacy premium-request model for now):

  1. Plan: Copilot Pro, Pro+, Business, or Enterprise?
  2. Billing system: Does your usage page show "premium requests" (legacy) or "AI Credits / usage-based" (new)? Monthly vs annual subscription is usually the tell.
  3. One calibration point: for a period, what does the GitHub dashboard show (premium-request count and/or the $ figure) vs what codeburn shows — even for a single model? That lets me validate the model against your real numbers.
  4. Which models do you mostly drive in Copilot (e.g., GPT-4.1, Claude Sonnet, Opus)? codeburn currently infers the family heuristically, which I want to verify.

I'll put up a branch for you to test once I know your setup, so we calibrate against your actual dashboard rather than guessing — the multiplier table has changed silently in the past, so your ground-truth numbers are the best validation.

@dat-intellis — on the subagent point: are you referring to Copilot subagents, or Claude Code? (Your "sonnet 4.6 / opus 4.8" wording sounds like it might be Claude Code.) If you can share which tool and roughly where it under-counted, I'll trace it — but it may be a separate issue from this Copilot-billing one.

iamtoruk avatar Jun 06 '26 01:06 iamtoruk

@iamtoruk > copilot cli subagents mostly using anthropic models - copilot supports a quite broad selection.

I am on a Business plan, with the new usage based billing. I started a normal session with a sonnet 4.6 model and delegated some work to a subagent using opus 4.8. The opus 4.8 usage does not register at all in codeburn.

Additionally, the official GitHub docs state that 1 AI credit is 0.01 USD. When I correlate the calculated AI credit usage within the current (first session of the day) copilot cli session and compare that against the codeburn calculation those numbers doesn't seem to correlate.

Sadly GitHub rest api's usage endpoints doesn't support a user level usage query for accounts who receive copilot through a business or enterprise - not yet anyway.

With the new model I want to keep a stricter view on my usage.

Let me know if you need anything further for debugging.

dat-intellis avatar Jun 07 '26 19:06 dat-intellis

  • Plan: Enterprise
  • Billing system: AI Credits / Metered usage
  • Calibration: Image
Image
  • Models: GPT 5.4/5.4, Opus 4.6/4.7/4.8

stephanjohnson avatar Jun 08 '26 07:06 stephanjohnson

I have no data since the github credit / token based changes. Github Copilot via vscode. We are on business subscription. Somebody similar problems?

richardbruenning avatar Jun 08 '26 11:06 richardbruenning

I ran into similar issues with big discrepancies between the actually charged costs and the codeburn reported costs. I believe one of the issues could be related to GitHub not exporting all credits/tokens. GitHub Copilot only logs output credits in its local session state, not input or cached tokens. As an alternative, I would like to propose otel as a basis and the current method as a fallback. CodeBurn already has the plumbing for SQLite-based providers. The OpenCode and KiloCode providers both delegate to a shared sqlite-session-parser.ts module. So the pattern exists there is only a need for a new adapter for the OTel schema. A separate issue might be the retail costs versus business subscriptions as commented on above.

steelp02 avatar Jun 10 '26 19:06 steelp02

I took the liberty to quickly code it in myself and it seems to be working: PR

steelp02 avatar Jun 10 '26 21:06 steelp02

In VS Code, this will turn on AI Agent debug logs with OTEL-like output that should give all details needed:

{
  "github.copilot.chat.agentDebugLog.enabled": true,
  "github.copilot.chat.agentDebugLog.fileLogging.enabled": true
}

There is another setting that will also publish the OTEL events if you setup an observation framework, but I haven't gone that far.

Doing this, someone at my company then vibe coded a script that could generate the correct output. There is a file VS Code installed somewhere that has the actual API costs, and the "AI credits" they are using now are just 100 credits = $1.

I'm not sure if you need debugging on to get the credits used or not, but you can definitely get them all from those logs.

Here are the log locations, depending on VS Code install type and platform:

Platform VS Code Variant Agent Debug Log Path
Windows Release %APPDATA%\Code\User\workspaceStorage\*/GitHub.copilot-chat/debug-logs/
Windows Insiders %APPDATA%\Code - Insiders\User\workspaceStorage\*/GitHub.copilot-chat/debug-logs/
macOS Release ~/Library/Application Support/Code/User/workspaceStorage/*/GitHub.copilot-chat/debug-logs/
macOS Insiders ~/Library/Application Support/Code - Insiders/User/workspaceStorage/*/GitHub.copilot-chat/debug-logs/
Linux Release ~/.config/Code/User/workspaceStorage/*/GitHub.copilot-chat/debug-logs/
Linux Insiders ~/.config/Code - Insiders/User/workspaceStorage/*/GitHub.copilot-chat/debug-logs/

LightCC avatar Jun 11 '26 16:06 LightCC

Status update, since two of the three problems in this thread are now fixed on main and ship in 0.9.15 (releasing this week):

  • Missing input/cache tokens (@steelp02's finding that only output lands in local session state): #477 merged, so the OTel agent-traces.db path now carries full token data including cache reads.
  • $0.00 cost for VS Code Copilot Chat users: #563 merged; the provider now reads VS Code's core chatSessions journals, which were the only on-disk source with token counts for that setup.

Everyone on this thread is on 0.9.14 or older, which predates both. Once 0.9.15 is out, please re-test before we chase the remaining delta.

What is still open is the billing unit. codeburn prices tokens at API rates; your dashboards bill AI Credits at $0.01 per credit. To build credit parity I need one calibration artifact from an affected machine, since the exact credit computation (per-model multipliers, whether input/cache tokens participate, rounding) is not documented anywhere I can verify:

One day's dashboard credit count for Copilot, next to that same day's agent-traces.db (or a debug-log excerpt using @LightCC's settings above). Aggregate numbers are enough; no prompt content needed.

@LightCC, if you can locate that local file with the per-model costs your colleague's script used, its path and shape would shortcut this considerably.

@dat-intellis, on the invisible opus 4.8 subagent usage: #563 may already cover it depending on where Copilot CLI wrote those sessions. Could you re-check on 0.9.15 and, if it still does not register, open a separate issue with the CLI version? That keeps this one focused on billing parity.

With one paired sample I can put up a calibration branch for you to verify against your real dashboards, which was always the plan here.

iamtoruk avatar Jul 02 '26 04:07 iamtoruk

Adding this here to provide some additional context / data from a Business-plan machine on usage-based AI Credits, using the Copilot CLI's ~/.copilot/session-store.db — which it turns out records the answer directly: every assistant_usage_events row carries total_nano_aiu (1e9 nano-AIU = 1 credit = $0.01) and a request_multiplier. No reverse-engineering needed for CLI usage; #946 reads this table.

Findings, against 2,398 real rows / 24 sessions:

  • GitHub prices AI Credits at the models' API list rates, exactly. Joining codeburn's computed per-session cost against sum(total_nano_aiu)/1e9 × $0.01: 21 of 24 sessions match to floating-point precision (ratio 1.000000 across GPT-5.5, GPT-5.6 Terra, Opus 4, Opus 5 single-model sessions). Token classes align with the docs (input / output / cached; no separate reasoning class — reasoning is inside output).
  • Charges are continuously token-metered, not request-quantized: every row has a distinct charge; request_multiplier is model-fixed metadata (e.g. Opus 15, Sonnet 1, Haiku 0.33, Gemini 3.6 Flash 14), not a rounding bucket.
  • The 3 non-exact sessions expose codeburn pricing-table gaps, not rate mismatches: claude-haiku-4.5 copilot rows price at $0 in codeburn (271 real calls on this machine), and a Sonnet 4.6-heavy session ran 0.72× GitHub's charge — both look like model-name/pricing-table entries worth fixing.
  • Hard parity ceiling for disk-based accounting: decomposing one month's dashboard total (43,103.2 credits = $431.03) against every on-disk source: $281.19 CLI (credit-exact, store proven complete — no NULLs, no pruning, gapless rowids), $45.32 VS Code chat (token-priced journals), and $104.52 (~24%) with no disk trace at all — completions/code review/github.com/agent-child requests (VS Code journals persist only the top-level request). Enterprise/Business accounts can't pull the itemized billing export, so that remainder is not locally attributable even in principle.

Implication for the calibration ask upthread: for Copilot CLI usage the store's recorded credits ARE billing truth and could be surfaced per #890 (persist reported alongside computed).

kelchm avatar Aug 12 '26 22:08 kelchm