mirror of
https://github.com/openai/codex.git
synced 2026-11-15 21:50: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:
@@ -395,6 +395,7 @@ pub(crate) struct CompactionAnalyticsDetails {
|
||||
pub(crate) retained_image_count: Option<usize>,
|
||||
pub(crate) compaction_summary_tokens: Option<i64>,
|
||||
pub(crate) cached_input_tokens: Option<i64>,
|
||||
pub(crate) cache_write_input_tokens: Option<i64>,
|
||||
}
|
||||
|
||||
impl CompactionAnalyticsAttempt {
|
||||
@@ -432,6 +433,7 @@ impl CompactionAnalyticsAttempt {
|
||||
retained_image_count,
|
||||
compaction_summary_tokens,
|
||||
cached_input_tokens,
|
||||
cache_write_input_tokens,
|
||||
} = details;
|
||||
let active_context_tokens_before =
|
||||
active_context_tokens_before.unwrap_or(self.active_context_tokens_before);
|
||||
@@ -455,6 +457,7 @@ impl CompactionAnalyticsAttempt {
|
||||
retained_image_count,
|
||||
compaction_summary_tokens,
|
||||
cached_input_tokens,
|
||||
cache_write_input_tokens,
|
||||
started_at: self.started_at,
|
||||
completed_at: now_unix_seconds(),
|
||||
duration_ms: Some(
|
||||
|
||||
Reference in New Issue
Block a user