copilot-credit-usage
Pi extension that tracks GitHub Copilot AI credit usage by session and project.
Package details
Install copilot-credit-usage from npm and Pi will load the resources declared by the package manifest.
$ pi install npm:copilot-credit-usage- Package
copilot-credit-usage- Version
0.1.0- Published
- Jun 4, 2026
- Downloads
- 158/mo · 9/wk
- Author
- jpballares
- License
- MIT
- Types
- extension
- Size
- 27.4 KB
- Dependencies
- 0 dependencies · 3 peers
Pi manifest JSON
{
"extensions": [
"./src/index.ts"
]
}Security note
Pi packages can execute code and influence agent behavior. Review the source before installing third-party packages.
README
copilot-credit-usage
A Pi extension that monitors GitHub Copilot AI credit usage.
It provides:
- A footer/status-line indicator for Copilot usage in the current Pi session.
- A
/copilot-creditscommand that shows Copilot usage grouped by local project, plus a total across all projects. - Optional authoritative GitHub Billing API totals for the month.
- A
copilot_credit_usagetool so the assistant can answer usage questions directly.
What it measures
GitHub documents Copilot usage as GitHub AI Credits, where 1 AI credit = $0.01 USD. This extension uses that conversion in two places:
Local Copilot session estimate: Pi stores provider, model, token, and cost metadata on assistant messages. The extension includes only messages whose
provider,api, ormodelmatchescopilot|github-copilot. If Pi records a non-zero USD cost, the extension converts that cost to AI credits. If Pi records$0, the extension estimates cost from GitHub's published per-token Copilot model pricing and groups it by session/project.GitHub Billing API total: When credentials are available, the extension calls GitHub's AI credit usage endpoint for the signed-in user:
GET /users/{username}/settings/billing/ai_credit/usage?year=YYYY&month=M
The GitHub API total is account-level. It does not include your local Pi working directory, so per-project breakdown comes from Copilot-filtered local Pi sessions.
The local per-project report is still an estimate because GitHub's Billing API is account-level and does not expose local working directories. The GitHub Billing API section is the authoritative account total when available.
Install
From this directory:
pi install .
Or add this package to your Pi package list if you manage packages manually.
Usage
Footer/status line
After the extension loads, the bottom status area shows current Copilot session usage:
Copilot 12.3cr · 450.2ktok
If you set a plan or allowance, it also shows the monthly allowance:
export PI_COPILOT_PLAN=pro # pro, pro+, max
# or
export PI_COPILOT_CREDIT_ALLOWANCE=1500
Status example:
Copilot 12.3cr/1,500cr · 450.2ktok
Monthly report command
/copilot-credits
/copilot-credits 2026-06
/copilot-credits --month 2026-06 --no-github
/copilot-credits --github-only --user monalisa
/copilot-credits --json
Options:
--month YYYY-MM Month to report. Default: current month.
--local-only Show local Copilot session estimate only.
--github-only Show GitHub billing API total only.
--no-github Skip GitHub billing API lookup.
--user LOGIN GitHub username for billing endpoint.
--json Emit JSON details.
GitHub API authentication
For official GitHub Billing API totals, use either:
export GITHUB_TOKEN=github_pat_...
or authenticate the GitHub CLI:
gh auth login
The token must be a fine-grained token with Plan: read user permission for user billing endpoints.
If credentials are missing or the account is not billed as an individual Copilot account, the extension still shows Copilot-filtered local Pi session estimates and prints the GitHub API error.
Notes and limits
- Local project totals are estimates based on Pi-recorded Copilot provider/model usage only.
- When Pi records
$0for a Copilot message, the extension estimates cost from GitHub's published per-token pricing for supported Copilot models. - Override the local Copilot filter with
PI_COPILOT_PROVIDER_PATTERNorCOPILOT_PROVIDER_PATTERNif your provider name differs. - GitHub Billing API totals are authoritative but account-level.
- Code completions and next-edit suggestions are not billed in Copilot AI credits for paid plans, per GitHub docs.
- Local monthly grouping uses calendar month (
YYYY-MM). Your GitHub billing cycle may start on a different day. - Project rows are capped at 100 to avoid huge command output.