feat(gh-copilot): add AI credit usage billing metrics collection#8980
feat(gh-copilot): add AI credit usage billing metrics collection#8980AndreiS-gh wants to merge 6 commits intoapache:mainapache/devlake:mainfrom AndreiS-gh:feature/add-ai-credit-usage-metricsAndreiS-gh/devlake:feature/add-ai-credit-usage-metricsCopy head branch name to clipboard
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.
|
Thanks for taking this on @AndreiS-gh ! Duplicate of #8965 and fixes #8961. Mind fixing tests? |
There was a problem hiding this comment.
Pull request overview
This PR extends the gh-copilot plugin’s tool-layer schema and task pipeline to ingest GitHub Copilot AI credit usage billing metrics (enterprise/org/user levels), adding new tables, migration support, subtasks, and E2E snapshot fixtures.
Changes:
- Added new tool-layer models + migration for AI credit usage billing tables (enterprise/org/user).
- Registered new collection/extraction subtasks for AI credit usage.
- Added E2E snapshot CSVs for the three new tables.
Show a summary per file
| File | Description |
|---|---|
| backend/plugins/gh-copilot/tasks/subtasks.go | Registers new collector/extractor subtasks for AI credit usage. |
| backend/plugins/gh-copilot/tasks/register.go | Adds new AI credit subtasks to the plugin subtask list. |
| backend/plugins/gh-copilot/tasks/ai_credit_collector.go | New collector intended to call GitHub billing usage endpoints and persist raw usage items. |
| backend/plugins/gh-copilot/tasks/ai_credit_extractor.go | New extractor intended to map raw items into enterprise/org/user billing tables. |
| backend/plugins/gh-copilot/models/enterprise_ai_credit_usage.go | Adds enterprise-level AI credit usage tool model/table. |
| backend/plugins/gh-copilot/models/org_ai_credit_usage.go | Adds org-level AI credit usage tool model/table. |
| backend/plugins/gh-copilot/models/user_ai_credit_usage.go | Adds user-level AI credit usage tool model/table. |
| backend/plugins/gh-copilot/models/models.go | Registers the three new models in GetTablesInfo(). |
| backend/plugins/gh-copilot/models/models_test.go | Updates tables-info test coverage for the new tables. |
| backend/plugins/gh-copilot/models/migrationscripts/register.go | Registers the new migration script in All(). |
| backend/plugins/gh-copilot/models/migrationscripts/20260708_add_ai_credit_usage_metrics.go | Auto-migrates the three new AI credit usage tables. |
| backend/plugins/gh-copilot/e2e/metrics/snapshot_tables/_tool_copilot_user_ai_credit_usage.csv | Adds user-level snapshot fixtures. |
| backend/plugins/gh-copilot/e2e/metrics/snapshot_tables/_tool_copilot_org_ai_credit_usage.csv | Adds org-level snapshot fixtures. |
| backend/plugins/gh-copilot/e2e/metrics/snapshot_tables/_tool_copilot_enterprise_ai_credit_usage.csv | Adds enterprise-level snapshot fixtures. |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 14/14 changed files
- Comments generated: 14
- Review effort level: Low
can we rerun the pipeliens now ? |
…ge.go modified: backend/plugins/gh-copilot/models/org_ai_credit_usage.go modified: backend/plugins/gh-copilot/models/user_ai_credit_usage.go modified: backend/plugins/gh-copilot/tasks/ai_credit_collector.go modified: backend/plugins/gh-copilot/tasks/ai_credit_extractor.go
Hello @ewega |
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