Expose assistant content token counts in completion notifications (#59041)

## What changed

Add optional `contentTokenCount` metadata to `item/completed` notifications, carrying the producer-supplied token count for each completed assistant message in default and plan modes. Counts include any sampled footer and are `null` when unavailable.

Keep this telemetry separate from stored thread items and omit it from subsequent model requests. Update the protocol schemas and generated TypeScript and Python types.

## Testing

Add coverage for per-message counts, including zero, in default and plan modes; missing and malformed metadata; backward-compatible notification decoding; and exclusion from subsequent model requests.

GitOrigin-RevId: 35973037a42650fa2d7569da8e88cb81215cf971
This commit is contained in:
aojiao-oai
2026-11-03 02:26:29 +00:00
committed by copyberry
parent e839b828fb
commit 16ddd538bd
48 changed files with 443 additions and 39 deletions
@@ -2619,6 +2619,16 @@
"format": "int64",
"type": "integer"
},
"contentTokenCount": {
"default": null,
"description": "Native content tokens for the completed assistant message, including a sampled footer. Null when unavailable. Completion telemetry is not part of the stored thread item.",
"format": "uint64",
"minimum": 0.0,
"type": [
"integer",
"null"
]
},
"item": {
"$ref": "#/definitions/ThreadItem"
},
@@ -14396,6 +14396,16 @@
"format": "int64",
"type": "integer"
},
"contentTokenCount": {
"default": null,
"description": "Native content tokens for the completed assistant message, including a sampled footer. Null when unavailable. Completion telemetry is not part of the stored thread item.",
"format": "uint64",
"minimum": 0.0,
"type": [
"integer",
"null"
]
},
"item": {
"$ref": "#/definitions/v2/ThreadItem"
},
@@ -10357,6 +10357,16 @@
"format": "int64",
"type": "integer"
},
"contentTokenCount": {
"default": null,
"description": "Native content tokens for the completed assistant message, including a sampled footer. Null when unavailable. Completion telemetry is not part of the stored thread item.",
"format": "uint64",
"minimum": 0.0,
"type": [
"integer",
"null"
]
},
"item": {
"$ref": "#/definitions/ThreadItem"
},
@@ -2065,6 +2065,16 @@
"format": "int64",
"type": "integer"
},
"contentTokenCount": {
"default": null,
"description": "Native content tokens for the completed assistant message, including a sampled footer. Null when unavailable. Completion telemetry is not part of the stored thread item.",
"format": "uint64",
"minimum": 0.0,
"type": [
"integer",
"null"
]
},
"item": {
"$ref": "#/definitions/ThreadItem"
},
@@ -4,6 +4,11 @@
import type { ThreadItem } from "./ThreadItem";
export type ItemCompletedNotification = { item: ThreadItem, threadId: string, turnId: string,
/**
* Native content tokens for the completed assistant message, including a sampled footer.
* Null when unavailable. Completion telemetry is not part of the stored thread item.
*/
contentTokenCount?: number | null,
/**
* Unix timestamp (in milliseconds) when this item lifecycle completed.
*/