Skip to content

Add usage and billing metrics docs page#1720

Open
andyfeller wants to merge 1 commit into
mainfrom
af/usage-and-billing
Open

Add usage and billing metrics docs page#1720
andyfeller wants to merge 1 commit into
mainfrom
af/usage-and-billing

Conversation

@andyfeller

Copy link
Copy Markdown
Contributor

Summary

Adds a new feature guide, docs/features/usage-and-billing.md, showing how Copilot SDK integrators read usage and billing signals from their applications, and links it from the features index.

The page covers the full set of usage/billing surfaces:

Signal API
Per-call token counts assistant.usage event
Context-window utilization (live) session.usage_info event
Context-window breakdown (on demand) session.metadata.contextInfo
Accumulated AI credit and token totals session.usage.getMetrics
Per-model AI credit pricing models.list
Account quota and premium interactions account.getQuota

Details

  • Examples are provided for TypeScript, Python, Go, .NET, Java, and Rust, matching the multi-language house standard used by other feature docs.
  • Compiled snippets (TypeScript, Python, Go, .NET) pass the docs-validation harness; Java blocks use docs-validate: skip and Rust is shown illustratively, consistent with existing docs.
  • Field tables are intentionally scoped to the fields used in each example, with links to Streaming events and the generated SDK types as the always-current source of truth, to limit staleness.
  • Experimental RPCs (session.usage.getMetrics, session.metadata.contextInfo) are flagged as experimental, including the .NET GHCP001 diagnostic suppression.
  • Billing semantics (the totalNanoAiu field and premium-request accounting) are attributed to GitHub Copilot billing documentation rather than asserted by the SDK.

Testing

  • npm run extract then validate:ts, validate:py, validate:go, validate:cs from scripts/docs-validation/ — all passing (TypeScript 183/183, Python 63/63, Go 52/52, C# 53/53).
Document how SDK integrators read token counts, context-window
utilization, AI credit cost, and account quota via session events and
RPC methods (assistant.usage, session.usage_info,
session.metadata.contextInfo, session.usage.getMetrics, models.list,
account.getQuota).

Examples are provided for TypeScript, Python, Go, .NET, Java, and Rust,
and the compiled snippets pass the docs-validation harness. Adds a link
to the features index.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 18, 2026 15:43
@andyfeller andyfeller requested a review from a team as a code owner June 18, 2026 15:43

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

Adds a new feature guide documenting how Copilot SDK integrators can read usage and billing-related signals (per-call tokens, context-window utilization/breakdowns, accumulated session metrics, model pricing, and account quota) across all supported languages, and links it from the features index.

Changes:

  • Added docs/features/usage-and-billing.md with multi-language examples for session events and RPC surfaces related to usage/billing.
  • Linked the new guide from docs/features/README.md so it appears in the Features list.
Show a summary per file
File Description
docs/features/usage-and-billing.md New feature guide covering usage/billing signals with TypeScript/Python/Go/.NET/Java/Rust examples.
docs/features/README.md Adds the “Usage and Billing” entry to the features index table.

Copilot's findings

  • Files reviewed: 2/2 changed files
  • Comments generated: 5
Comment on lines +140 to +147
in, out := int64(0), int64(0)
if d.InputTokens != nil {
in = *d.InputTokens
}
if d.OutputTokens != nil {
out = *d.OutputTokens
}
fmt.Printf("%s: in=%d out=%d\n", d.Model, in, out)
Comment on lines +160 to +167
in, out := int64(0), int64(0)
if d.InputTokens != nil {
in = *d.InputTokens
}
if d.OutputTokens != nil {
out = *d.OutputTokens
}
fmt.Printf("%s: in=%d out=%d\n", d.Model, in, out)
Comment on lines +208 to +213
session.on(AssistantUsageEvent.class, event -> {
var data = event.getData();
long in = data.inputTokens() != null ? data.inputTokens() : 0;
long out = data.outputTokens() != null ? data.outputTokens() : 0;
System.out.printf("%s: in=%d out=%d%n", data.model(), in, out);
});
Comment on lines +228 to +233
println!(
"{}: in={} out={}",
data.model,
data.input_tokens.unwrap_or(0),
data.output_tokens.unwrap_or(0),
);

### On-demand breakdown with `session.metadata.contextInfo`

Events only fire when the context changes. To read the current breakdown at any moment—for example, right after resuming a session—call `session.metadata.contextInfo`. Pass `0` for the token limits to use the model's defaults.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants