Skip to content

Commit 689c887

Browse files
docs: fix assistant.usage cost field in Go/Java/Rust examples; clarify contextInfo token limit semantics
- Add cost field (with nil/Option guard) to Go, Java, and Rust assistant.usage snippets so all six languages match the documented field table and the 'functionally equivalent' claim in the intro - Correct the description of session.metadata.contextInfo parameters: promptTokenLimit passes 0 to use the runtime default, while outputTokenLimit passes 0 when the value is unknown (per generated types) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 1dcd380 commit 689c887

1 file changed

Lines changed: 15 additions & 7 deletions

File tree

docs/features/usage-and-billing.md

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,17 @@ func main() {
137137
if !ok {
138138
return
139139
}
140-
in, out := int64(0), int64(0)
140+
in, out, cost := int64(0), int64(0), float64(0)
141141
if d.InputTokens != nil {
142142
in = *d.InputTokens
143143
}
144144
if d.OutputTokens != nil {
145145
out = *d.OutputTokens
146146
}
147-
fmt.Printf("%s: in=%d out=%d\n", d.Model, in, out)
147+
if d.Cost != nil {
148+
cost = *d.Cost
149+
}
150+
fmt.Printf("%s: in=%d out=%d cost=%g\n", d.Model, in, out, cost)
148151
})
149152
_ = session
150153
}
@@ -157,14 +160,17 @@ session.On(func(event copilot.SessionEvent) {
157160
if !ok {
158161
return
159162
}
160-
in, out := int64(0), int64(0)
163+
in, out, cost := int64(0), int64(0), float64(0)
161164
if d.InputTokens != nil {
162165
in = *d.InputTokens
163166
}
164167
if d.OutputTokens != nil {
165168
out = *d.OutputTokens
166169
}
167-
fmt.Printf("%s: in=%d out=%d\n", d.Model, in, out)
170+
if d.Cost != nil {
171+
cost = *d.Cost
172+
}
173+
fmt.Printf("%s: in=%d out=%d cost=%g\n", d.Model, in, out, cost)
168174
})
169175
```
170176

@@ -209,7 +215,8 @@ session.on(AssistantUsageEvent.class, event -> {
209215
var data = event.getData();
210216
long in = data.inputTokens() != null ? data.inputTokens() : 0;
211217
long out = data.outputTokens() != null ? data.outputTokens() : 0;
212-
System.out.printf("%s: in=%d out=%d%n", data.model(), in, out);
218+
double cost = data.cost() != null ? data.cost() : 0.0;
219+
System.out.printf("%s: in=%d out=%d cost=%s%n", data.model(), in, out, cost);
213220
});
214221
```
215222

@@ -226,10 +233,11 @@ while let Ok(event) = events.recv().await {
226233
if event.event_type == "assistant.usage" {
227234
if let Some(data) = event.typed_data::<AssistantUsageData>() {
228235
println!(
229-
"{}: in={} out={}",
236+
"{}: in={} out={} cost={}",
230237
data.model,
231238
data.input_tokens.unwrap_or(0),
232239
data.output_tokens.unwrap_or(0),
240+
data.cost.unwrap_or(0.0),
233241
);
234242
}
235243
}
@@ -428,7 +436,7 @@ while let Ok(event) = events.recv().await {
428436

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

431-
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.
439+
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 `promptTokenLimit` to use the runtime default; pass `0` for `outputTokenLimit` if the value is unknown.
432440

433441
The result's `contextInfo` is `null` until the session has been initialized (the system prompt and tool metadata have been cached). It breaks the total down into `systemTokens`, `conversationTokens`, and `toolDefinitionsTokens`, alongside the `promptTokenLimit`.
434442

0 commit comments

Comments
 (0)