Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Open
AndreiS-gh wants to merge 6 commits into
apache:mainapache/devlake:mainfrom
AndreiS-gh:feature/add-ai-credit-usage-metricsAndreiS-gh/devlake:feature/add-ai-credit-usage-metricsCopy head branch name to clipboard
Open

feat(gh-copilot): add AI credit usage billing metrics collection#8980
AndreiS-gh wants to merge 6 commits into
apache: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

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

ewega commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Thanks for taking this on @AndreiS-gh ! Duplicate of #8965 and fixes #8961. Mind fixing tests?

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread backend/plugins/gh-copilot/tasks/ai_credit_collector.go Outdated
Comment thread backend/plugins/gh-copilot/tasks/ai_credit_collector.go Outdated
Comment thread backend/plugins/gh-copilot/tasks/ai_credit_extractor.go Outdated
Comment thread backend/plugins/gh-copilot/tasks/ai_credit_extractor.go
Comment thread backend/plugins/gh-copilot/tasks/ai_credit_extractor.go Outdated
Comment thread backend/plugins/gh-copilot/models/org_ai_credit_usage.go Outdated
Comment thread backend/plugins/gh-copilot/models/enterprise_ai_credit_usage.go Outdated
Comment thread backend/plugins/gh-copilot/models/enterprise_ai_credit_usage.go Outdated
Comment thread backend/plugins/gh-copilot/tasks/ai_credit_collector.go
Comment thread backend/plugins/gh-copilot/tasks/ai_credit_collector.go Outdated
@AndreiS-gh

Copy link
Copy Markdown
Author

Thanks for taking this on @AndreiS-gh ! Duplicate of #8965 and fixes #8961. Mind fixing tests?

can we rerun the pipeliens now ?

PankajChaudhari-Atos and others added 3 commits July 24, 2026 19:28
…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
@PankajChaudhari-Atos

Copy link
Copy Markdown

Thanks for taking this on @AndreiS-gh ! Duplicate of #8965 and fixes #8961. Mind fixing tests?

Hello @ewega
All the issues reported by the PR review bot, as well as the test failures, have been fixed. Could you please review the changes and proceed with the next steps?

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.

4 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.