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:
Eric Traut authored and copyberry committed 2026-07-16 00:22:53 +00:00
1 parent 78d4a563f9
commit 2edad72de3
46 files changed
+207 -31

No files matched your search

+5
View File
@@ -607,6 +607,11 @@ fn emit_token_usage_metrics(context: &MemoryStartupContext, token_usage: &TokenU
token_usage.cached_input(),
&[("token_type", "cached_input")],
);
context.histogram(
MEMORY_PHASE_TWO_TOKEN_USAGE,
token_usage.cache_write_input_tokens.max(0),
&[("token_type", "cache_write_input")],
);
context.histogram(
MEMORY_PHASE_TWO_TOKEN_USAGE,
token_usage.output_tokens.max(0),