Start Debugging

How to Track Claude Code, Codex and OpenCode Usage on Copilot with totals_by_client and model_selection_mode

Use the Copilot usage metrics API's totals_by_client array to see which tools (claude_code, codex, opencode, copilot_cli, vscode) send model traffic through your Copilot seats, and model_selection_mode to split user-picked models from Auto and product-chosen ones. Endpoints, permissions, NDJSON parsing with jq, and the caveats that make the numbers easy to misread.

This site uses Walter, an AI agent, for research, writing, and maintenance. Editorial and verification process

Short answer: call one of the Copilot usage metrics report endpoints (for example GET /orgs/{org}/copilot/metrics/reports/users-1-day?day=2026-11-30 with X-GitHub-Api-Version: 2026-03-10), download the NDJSON report from the returned download_links, and read the totals_by_client array on each record. Every entry names a client such as claude_code, codex, opencode, copilot_cli, vscode or cloud_agent, with its request_count, session_count and token_usage. Inside each entry, totals_by_model[] breaks the same traffic down by model and by model_selection_mode: user_selected, auto, product_selected, the Copilot Fusion effort levels, or unknown. The field shipped on October 23, 2026 in the enterprise, organization, enterprise-user and organization-user 1-day and 28-day reports. This post follows the GitHub docs as they read on December 2, 2026. The jq queries below were run with jq 1.7.1 against a hand-built sample report shaped like GitHub’s example schema, not against a live organization’s export.

Why the IDE breakdown stopped being enough

Until October, the only per-tool view in the Copilot usage metrics came from totals_by_ide, and that array is built from editor telemetry. A developer who signs in to OpenCode with their Copilot subscription, or who points Claude Code or Codex at Copilot-served models, generates model requests that are billed against the Copilot seat but sends no IDE telemetry. Those requests were simply missing from the per-tool numbers. An admin could see that someone burned through their AI credits, and could not see which tool did it.

totals_by_client closes that gap by counting on the server side. GitHub identifies the client from the integration ID attached to each model request, so the count does not depend on a plugin reporting anything back. That is also why the changelog insists on two limits up front:

  • client is best-effort grouping, not verified identity. A tool that sends an unrecognized integration ID lands in other.
  • It measures model traffic (requests and tokens), not jobs. GitHub has a separate “agent app activity” metric, introduced in August 2026, that counts jobs that agent apps such as Claude and Codex start on GitHub. The two are not interchangeable.

If what you want is a trace of a single agent session, which tool calls it made and where the tokens went, the usage metrics are the wrong instrument. That is what exporting Copilot agent sessions to an OpenTelemetry backend is for. totals_by_client answers the coarser, budget-shaped question: across a team, which tools are consuming the Copilot allowance, and with which models.

Who can read the reports

Two switches have to be on before any endpoint answers with data:

  1. The Copilot usage metrics policy must be enabled. The REST docs phrase the enterprise requirement as “Enabled everywhere”.
  2. The caller needs the right role. For enterprise endpoints that is an enterprise owner, a billing manager, or a custom role with the View Enterprise Copilot Metrics permission; classic PATs and OAuth app tokens need manage_billing:copilot or read:enterprise. For organization endpoints it is an organization owner or a custom role with View Organization Copilot Metrics; classic tokens need read:org.

A fine-grained custom role is the cleanest way to hand this to a FinOps or platform team without making them org owners.

All report endpoints live under /copilot/metrics/reports/. The 1-day variants take a required day query parameter in YYYY-MM-DD form. The 28-day variants only exist as /latest:

# GitHub REST API, X-GitHub-Api-Version: 2026-03-10
GET /orgs/{org}/copilot/metrics/reports/organization-1-day?day=YYYY-MM-DD
GET /orgs/{org}/copilot/metrics/reports/organization-28-day/latest
GET /orgs/{org}/copilot/metrics/reports/users-1-day?day=YYYY-MM-DD
GET /orgs/{org}/copilot/metrics/reports/users-28-day/latest

GET /enterprises/{enterprise}/copilot/metrics/reports/enterprise-1-day?day=YYYY-MM-DD
GET /enterprises/{enterprise}/copilot/metrics/reports/enterprise-28-day/latest
GET /enterprises/{enterprise}/copilot/metrics/reports/users-1-day?day=YYYY-MM-DD
GET /enterprises/{enterprise}/copilot/metrics/reports/users-28-day/latest

None of them return the metrics inline. A 1-day call returns download_links (an array of signed URLs with a short expiry) and report_day; a 28-day call returns download_links plus report_start_day and report_end_day. The files behind the links are NDJSON reports, one record per line. A 1-day request for a day with no data can return 204 No Content, and history goes back to October 10, 2025, for up to one year.

Fetching yesterday’s per-user report for an organization looks like this:

# gh 2.x, GitHub REST API version 2026-03-10
ORG=my-org
DAY=$(date -u -v-1d +%F 2>/dev/null || date -u -d yesterday +%F)

gh api \
  -H "Accept: application/vnd.github+json" \
  -H "X-GitHub-Api-Version: 2026-03-10" \
  "/orgs/$ORG/copilot/metrics/reports/users-1-day?day=$DAY" \
  --jq '.download_links[]' |
while read -r url; do
  # Signed URL: do not send the GitHub token to it
  curl -sSL "$url"
done > "users-$DAY.ndjson"

Two details in that script matter. The signed URL carries its own authorization, so a plain curl without the Authorization header is correct; forwarding your token to a storage host is a habit worth not having. And a report can span more than one link, so loop over all of them and concatenate.

What a totals_by_client entry contains

On a per-user record, totals_by_client sits next to user_login, day and the other breakdowns. It is always present and is an empty array when the user sent no model traffic that day. Trimmed to the relevant part, a record looks like this (the shape follows GitHub’s example schema; the numbers are illustrative):

{
  "day": "2026-11-30",
  "user_login": "login1",
  "totals_by_client": [
    {
      "client": "opencode",
      "request_count": 3,
      "session_count": 2,
      "token_usage": {
        "prompt_tokens_sum": 2400,
        "output_tokens_sum": 900,
        "avg_tokens_per_request": 1100.0
      },
      "totals_by_model": [
        {
          "model": "claude-opus-5.5",
          "model_selection_mode": "user_selected",
          "is_custom_enterprise_model": false,
          "request_count": 2,
          "token_usage": { "prompt_tokens_sum": 1800, "output_tokens_sum": 600, "avg_tokens_per_request": 1200.0 }
        },
        {
          "model": "claude-sonnet-5",
          "model_selection_mode": "auto",
          "is_custom_enterprise_model": false,
          "request_count": 1,
          "token_usage": { "prompt_tokens_sum": 600, "output_tokens_sum": 300, "avg_tokens_per_request": 900.0 }
        }
      ]
    }
  ]
}

The client labels the changelog lists are opencode, claude_code, codex, zed, copilot_cli, github_app, cloud_agent, code_review, vscode and jetbrains, plus the other bucket. totals_by_model entries are keyed on the combination of model, model_selection_mode and is_custom_enterprise_model, so the same model name can appear twice under one client: once as the GitHub-hosted model and once as an enterprise custom model with the same name.

In aggregated reports (organization-1-day, enterprise-1-day) the array sits directly on the record. In the 28-day aggregate reports it appears inside each entry of day_totals, one per day, so you sum across days yourself. In aggregates, session_count is de-duplicated across users, which means you cannot rebuild it by adding up the per-user numbers.

Reading model_selection_mode

model_selection_mode is what turns “which model did they use” into “who picked that model”. The values the docs list:

ValueMeaning
user_selectedThe user picked a specific model instead of Auto or Copilot Fusion.
autoAuto chose the model, including its Efficiency and Intelligence tiers.
product_selectedThe product chose the model. Copilot code review and Copilot cloud agent report this.
fusion_standard, fusion_high, fusion_maxCopilot Fusion at that effort level. fusion_standard can also include Auto Balance requests.
fusion_fastFusion Fast, used only by VS Code inline chat; users cannot select it.
unknownThe mode was missing, empty or could not be normalized.
otherSeen in earlier reports, for modes that were not yet reported individually.

For third-party agents this is the interesting column. A row with client: "claude_code" and model_selection_mode: "user_selected" on an expensive model means someone deliberately pinned that model in their tool config, and that is a conversation you can have. A row with auto means the routing made the choice, and the lever is the Auto policy, not the developer. GitHub’s docs are explicit that these are activity metrics: do not infer charges from model_selection_mode, and do not use fusion_standard on its own as a Fusion adoption number, because Auto Balance traffic can land in it.

Turning the report into a per-tool table with jq

Because GitHub’s prose calls the files NDJSON while its examples are drawn as JSON arrays, the first step below uses jq -s 'flatten', which produces one array of records from either form. The queries were run with jq 1.7.1 on macOS against a three-user sample file built from the example schema:

# jq 1.7.1: one row per user x client, heaviest prompt-token users first
jq -s 'flatten' users-2026-11-30.ndjson | jq -r '
  [ .[] as $u
    | $u.totals_by_client[]
    | { day: $u.day, user: $u.user_login, client,
        requests: .request_count, sessions: .session_count,
        prompt_tokens: .token_usage.prompt_tokens_sum,
        output_tokens: .token_usage.output_tokens_sum } ]
  | sort_by(-.prompt_tokens)
  | .[] | [.day, .user, .client, .requests, .sessions, .prompt_tokens, .output_tokens]
  | @tsv'

On the sample, that printed:

2026-11-30	login2	claude_code	40	3	900000	40000
2026-11-30	login1	opencode	3	2	2400	900
2026-11-30	login1	copilot_cli	2	1	1500	300

The third user in the sample had an empty totals_by_client and correctly produced no row. The second query answers the policy question: for the third-party agent clients only, how many requests came from a model the user picked versus one Auto picked?

# jq 1.7.1: requests by model_selection_mode for third-party agent clients
jq -s 'flatten' users-2026-11-30.ndjson | jq -r '
  [ .[].totals_by_client[]
    | select(.client | IN("claude_code", "codex", "opencode"))
    | .totals_by_model[] ]
  | group_by(.model_selection_mode)
  | map({ mode: .[0].model_selection_mode,
          requests: (map(.request_count) | add) })
  | .[] | "\(.mode)\t\(.requests)"'

Sample output:

auto	1
user_selected	42

Swap the IN(...) list to cover whatever clients your policy cares about. To get the same view from the 28-day aggregate, replace .[].totals_by_client[] with .[].day_totals[].totals_by_client[].

Gotchas that make the numbers easy to misread

request_count is model calls, not prompts. One prompt in an agent can trigger many model requests: planning, tool-call round trips, summarization. The 40 requests in the sample above could be three prompts. Do not compare request_count with user_initiated_interaction_count or any prompt metric, and do not compute “requests per prompt” across clients that loop differently. If your concern is the agent loop itself inflating requests, the fix sits in the tool configuration. The OpenCode with Ollama guide covers the context-size side of that for local models.

Local BYOK traffic is not in this array. Requests that go to a bring-your-own-key model running locally never pass through GitHub, so they show up in totals_by_local_byok, not in totals_by_client. A user who is heavy on Copilot CLI but light in totals_by_client may simply be on a local model.

Code review and cloud agent rows look odd on purpose. code_review reports model: "unknown" with product_selected, and cloud_agent reports product_selected. Filter them out before you rank users by “model choice”, or the product’s own decisions get counted as someone’s preference. Code review billing has its own story; the December 30 code review billing change is the relevant read if that is the bill you are chasing.

Activity is not invoicing. The per-user ai_credits_used field is documented as being for consumption analysis, not for reconciling invoice totals, and the same goes for token sums in totals_by_client. Use the billing usage reports for money, and these metrics to explain where the money went.

other and unknown are signals, not noise. A growing other client bucket usually means a new tool started using Copilot credentials before GitHub added a label for it. That is worth a look, especially if your organization only meant to allow approved clients. Pair it with the MCP side of the same governance work: the enterprise MCP allowlist for Copilot connectors is where tool-level permissions live.

Old days do not gain the field retroactively. The change is additive. Reports for days before the rollout just have no totals_by_client traffic to show, and is_custom_enterprise_model is omitted on days before it existed. Write the jq or pipeline code so a missing key is treated as empty, not as an error.

The 28-day endpoint is always “latest”. There is no day parameter for it. If you need a fixed 28-day window for a monthly report, pull and store the 1-day reports daily and aggregate them yourself; the signed links expire, so a nightly job that downloads the NDJSON into your own storage is the practical setup.

Where this fits next to the other Copilot telemetry

Think of the three layers as different zoom levels. The billing reports answer “how much did we spend”. The usage metrics, now with totals_by_client and model_selection_mode, answer “which tools and which model choices drove that usage, per user and per day”. OpenTelemetry export answers “what happened inside this one session”. If you are building on the Copilot platform rather than administering it, the Copilot SDK overview explains how your own integration ends up identified as a client in the first place.

Sources

Comments

Sign in with GitHub to comment. Reactions and replies thread back to the comments repo.