mirror of
https://github.com/openai/codex.git
synced 2026-11-05 08:28:29 +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:
1 parent
78d4a563f9
commit
2edad72de3
46 files changed
+207
-31
No files matched your search
@@ -277,6 +277,7 @@ async fn run_remote_compact_task_inner_impl(
|
||||
analytics_details.active_context_tokens_before = Some(token_usage.input_tokens);
|
||||
analytics_details.compaction_summary_tokens = Some(token_usage.output_tokens);
|
||||
analytics_details.cached_input_tokens = Some(token_usage.cached_input_tokens);
|
||||
analytics_details.cache_write_input_tokens = Some(token_usage.cache_write_input_tokens);
|
||||
}
|
||||
let (compacted_history, retained_images) =
|
||||
build_v2_compacted_history(&prompt_input, compaction_output);
|
||||
@@ -835,6 +836,7 @@ mod tests {
|
||||
token_usage: Some(TokenUsage {
|
||||
input_tokens: 123_456,
|
||||
cached_input_tokens: 7_890,
|
||||
cache_write_input_tokens: 0,
|
||||
output_tokens: 42,
|
||||
reasoning_output_tokens: 5,
|
||||
total_tokens: 123_498,
|
||||
@@ -854,6 +856,7 @@ mod tests {
|
||||
Some(TokenUsage {
|
||||
input_tokens: 123_456,
|
||||
cached_input_tokens: 7_890,
|
||||
cache_write_input_tokens: 0,
|
||||
output_tokens: 42,
|
||||
reasoning_output_tokens: 5,
|
||||
total_tokens: 123_498,
|
||||
|
||||
Reference in new issue
Block a user