feat(gh-copilot): add AI credit usage billing metrics collection#8980
Open
AndreiS-gh wants to merge 1 commit into
Open
feat(gh-copilot): add AI credit usage billing metrics collection#8980AndreiS-gh wants to merge 1 commit into
AndreiS-gh wants to merge 1 commit into
Conversation
- Add enterprise, organization, and user-level AI credit usage models
- Implement collector for GitHub Copilot billing API endpoints
- Implement extractor to route credit usage records to appropriate tables
- Add migration script to create three new billing tables
- Add E2E test snapshots for all three billing levels
- Register new models, subtasks, and migration in plugin initialization
Closes: Related to metrics parity gaps identified in copilot-metrics-roi-toolkit
GitHub Copilot API exposes three billing endpoints:
- /enterprises/{e}/settings/billing/ai_credit/usage
- /organizations/{org}/settings/billing/ai_credit/usage
- /users/{username}/settings/billing/ai_credit/usage
Each endpoint provides per-model AI credit consumption broken down by:
- Time period (year, month, day)
- Model name (gpt-4.1, claude-3, etc.)
- Cost center (enterprise only)
- Usage items with gross/net quantities and pricing
Tables created:
- _tool_copilot_enterprise_ai_credit_usage (with cost center support)
- _tool_copilot_org_ai_credit_usage
- _tool_copilot_user_ai_credit_usage
All records are denormalized (one row per model per entity per time period)
for efficient analytics aggregation.
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.
Summary
Add support for GitHub Copilot AI credit usage billing metrics collection via the GitHub Copilot billing API endpoints.
This PR closes gaps identified in the copilot-metrics-roi-toolkit schema reconciliation, specifically the missing Billing Usage API group (3 endpoints).
Changes
New Models (3 tables)
GhCopilotEnterpriseAiCreditUsage— Enterprise-level AI credit tracking with cost center supportGhCopilotOrgAiCreditUsage— Organization-level AI credit trackingGhCopilotUserAiCreditUsage— Individual user-level AI credit trackingNew Tasks
ai_credit_collector.go) — Routes requests to appropriate GitHub billing API endpoint based on connection type (enterprise/org/user) and filters by date rangeai_credit_extractor.go) — Parses credit usage items and routes records to corresponding tablesNew Migration
20260708_add_ai_credit_usage_metrics.go— Registers all three billing tablesE2E Tests
Technical Details
GitHub Copilot Billing API Endpoints Covered:
GET /enterprises/{enterprise}/settings/billing/ai_credit/usageGET /organizations/{org}/settings/billing/ai_credit/usageGET /users/{username}/settings/billing/ai_credit/usageData Structure (denormalized per model per entity per time period):
Connection Type Routing:
_tool_copilot_enterprise_ai_credit_usage_tool_copilot_org_ai_credit_usage_tool_copilot_user_ai_credit_usageTesting
migrationscripts/register.gomodels.goandmodels_test.goregister.goandsubtasks.goRelated