mirror of
https://github.com/openai/codex.git
synced 2026-10-19 17:28:46 +00:00
Track prompt cache write token usage (#33454)
## What changed - Parse `cache_write_tokens` from response input token details and carry it through token usage aggregation. - Expose `cache_write_input_tokens` in protocol, app-server, exec, and TypeScript SDK usage events, defaulting it to zero for compatibility with older payloads. - Report cache-write usage in analytics, metrics, traces, and rollout data alongside existing cache-read usage. ## Testing - Add coverage for response parsing, usage event output, aggregation, analytics, metrics, and telemetry fields. GitOrigin-RevId: 634e4fbe3086a8923c0ee13b622573e7d9d221bd
This commit is contained in:
@@ -121,6 +121,7 @@ impl EventProcessorWithJsonOutput {
|
||||
Usage {
|
||||
input_tokens: usage.total.input_tokens,
|
||||
cached_input_tokens: usage.total.cached_input_tokens,
|
||||
cache_write_input_tokens: usage.total.cache_write_input_tokens,
|
||||
output_tokens: usage.total.output_tokens,
|
||||
reasoning_output_tokens: usage.total.reasoning_output_tokens,
|
||||
}
|
||||
|
||||
@@ -63,6 +63,9 @@ pub struct Usage {
|
||||
pub input_tokens: i64,
|
||||
/// The number of cached input tokens used during the turn.
|
||||
pub cached_input_tokens: i64,
|
||||
/// The number of input tokens written to the prompt cache during the turn.
|
||||
#[serde(default)]
|
||||
pub cache_write_input_tokens: i64,
|
||||
/// The number of output tokens used during the turn.
|
||||
pub output_tokens: i64,
|
||||
/// The number of reasoning output tokens used during the turn.
|
||||
|
||||
@@ -1231,6 +1231,7 @@ fn token_usage_update_is_emitted_on_turn_completion() {
|
||||
total_tokens: 42,
|
||||
input_tokens: 10,
|
||||
cached_input_tokens: 3,
|
||||
cache_write_input_tokens: 4,
|
||||
output_tokens: 29,
|
||||
reasoning_output_tokens: 7,
|
||||
},
|
||||
@@ -1238,6 +1239,7 @@ fn token_usage_update_is_emitted_on_turn_completion() {
|
||||
total_tokens: 42,
|
||||
input_tokens: 10,
|
||||
cached_input_tokens: 3,
|
||||
cache_write_input_tokens: 4,
|
||||
output_tokens: 29,
|
||||
reasoning_output_tokens: 7,
|
||||
},
|
||||
@@ -1275,6 +1277,7 @@ fn token_usage_update_is_emitted_on_turn_completion() {
|
||||
usage: Usage {
|
||||
input_tokens: 10,
|
||||
cached_input_tokens: 3,
|
||||
cache_write_input_tokens: 4,
|
||||
output_tokens: 29,
|
||||
reasoning_output_tokens: 7,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user