feat(core+web): store raw usage data on streams (and visualize properly in ADE) (#6452)

* feat(core): store raw usage data on streams

* fix(web): various fixes to deal w/ hardcoding against openai
This commit is contained in:
Charles Packer
2025-11-29 13:45:15 -08:00
committed by Caren Thomas
parent 88a3743cc8
commit 4af6465226
4 changed files with 49 additions and 1 deletions

View File

@@ -98,6 +98,9 @@ class SimpleAnthropicStreamingInterface:
self.cache_read_tokens = 0
self.cache_creation_tokens = 0
# Raw usage from provider (for transparent logging in provider trace)
self.raw_usage: dict | None = None
# reasoning object trackers
self.reasoning_messages = []
@@ -474,6 +477,13 @@ class SimpleAnthropicStreamingInterface:
if hasattr(usage, "cache_creation_input_tokens") and usage.cache_creation_input_tokens:
self.cache_creation_tokens += usage.cache_creation_input_tokens
# Store raw usage for transparent provider trace logging
try:
self.raw_usage = usage.model_dump(exclude_none=True)
except Exception as e:
logger.error(f"Failed to capture raw_usage from Anthropic: {e}")
self.raw_usage = None
elif isinstance(event, BetaRawMessageDeltaEvent):
self.output_tokens += event.usage.output_tokens