anthropic: store cache ttl details on usage metadata (#31393)

This commit is contained in:
ccurme 2025-05-28 13:52:37 -04:00 committed by GitHub
parent 0aec05bde5
commit 0e3f35effe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -2129,6 +2129,13 @@ def _create_usage_metadata(anthropic_usage: BaseModel) -> UsageMetadata:
"cache_read": getattr(anthropic_usage, "cache_read_input_tokens", None),
"cache_creation": getattr(anthropic_usage, "cache_creation_input_tokens", None),
}
# Add (beta) cache TTL information if available
cache_creation = getattr(anthropic_usage, "cache_creation", None)
if cache_creation:
for k in ["ephemeral_1h_input_tokens", "ephemeral_5m_input_tokens"]:
v = getattr(cache_creation, k, None)
if v:
input_token_details[k] = v
# Anthropic input_tokens exclude cached token counts.
input_tokens = (