Add usage and billing metrics docs page#1720
Open
andyfeller wants to merge 1 commit into
Open
Conversation
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>
Contributor
There was a problem hiding this comment.
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.mdwith multi-language examples for session events and RPC surfaces related to usage/billing. - Linked the new guide from
docs/features/README.mdso 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
assistant.usageeventsession.usage_infoeventsession.metadata.contextInfosession.usage.getMetricsmodels.listaccount.getQuotaDetails
docs-validationharness; Java blocks usedocs-validate: skipand Rust is shown illustratively, consistent with existing docs.session.usage.getMetrics,session.metadata.contextInfo) are flagged as experimental, including the .NETGHCP001diagnostic suppression.totalNanoAiufield and premium-request accounting) are attributed to GitHub Copilot billing documentation rather than asserted by the SDK.Testing
npm run extractthenvalidate:ts,validate:py,validate:go,validate:csfromscripts/docs-validation/— all passing (TypeScript 183/183, Python 63/63, Go 52/52, C# 53/53).