Skip to content

feat(gh-copilot): add AI credit usage billing metrics collection#8980

Open
AndreiS-gh wants to merge 1 commit into
apache:mainfrom
AndreiS-gh:feature/add-ai-credit-usage-metrics
Open

feat(gh-copilot): add AI credit usage billing metrics collection#8980
AndreiS-gh wants to merge 1 commit into
apache:mainfrom
AndreiS-gh:feature/add-ai-credit-usage-metrics

Conversation

@AndreiS-gh

Copy link
Copy Markdown

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 support
  • GhCopilotOrgAiCreditUsage — Organization-level AI credit tracking
  • GhCopilotUserAiCreditUsage — Individual user-level AI credit tracking

New Tasks

  • Collector (ai_credit_collector.go) — Routes requests to appropriate GitHub billing API endpoint based on connection type (enterprise/org/user) and filters by date range
  • Extractor (ai_credit_extractor.go) — Parses credit usage items and routes records to corresponding tables

New Migration

  • 20260708_add_ai_credit_usage_metrics.go — Registers all three billing tables

E2E Tests

  • Added snapshot tables for all three billing levels with realistic test data

Technical Details

GitHub Copilot Billing API Endpoints Covered:

  • GET /enterprises/{enterprise}/settings/billing/ai_credit/usage
  • GET /organizations/{org}/settings/billing/ai_credit/usage
  • GET /users/{username}/settings/billing/ai_credit/usage

Data Structure (denormalized per model per entity per time period):

  • Time period: year, month, day
  • Model name (e.g., gpt-4.1, claude-3)
  • Cost center (enterprise only)
  • Usage metrics: gross/net quantity, pricing, discounts

Connection Type Routing:

  • Enterprise connections → _tool_copilot_enterprise_ai_credit_usage
  • Organization connections → _tool_copilot_org_ai_credit_usage
  • User-scoped connections → _tool_copilot_user_ai_credit_usage

Testing

  • Migration script registered in migrationscripts/register.go
  • Models registered in models.go and models_test.go
  • Subtasks registered in register.go and subtasks.go
  • E2E snapshot tables added with test data
  • Go formatting verified

Related

- 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.
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.

1 participant