Skip to content

Commit 0e3f35e

Browse files
authored
anthropic: store cache ttl details on usage metadata (#31393)
1 parent 0aec05b commit 0e3f35e

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

libs/partners/anthropic/langchain_anthropic/chat_models.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2129,6 +2129,13 @@ def _create_usage_metadata(anthropic_usage: BaseModel) -> UsageMetadata:
21292129
"cache_read": getattr(anthropic_usage, "cache_read_input_tokens", None),
21302130
"cache_creation": getattr(anthropic_usage, "cache_creation_input_tokens", None),
21312131
}
2132+
# Add (beta) cache TTL information if available
2133+
cache_creation = getattr(anthropic_usage, "cache_creation", None)
2134+
if cache_creation:
2135+
for k in ["ephemeral_1h_input_tokens", "ephemeral_5m_input_tokens"]:
2136+
v = getattr(cache_creation, k, None)
2137+
if v:
2138+
input_token_details[k] = v
21322139

21332140
# Anthropic input_tokens exclude cached token counts.
21342141
input_tokens = (

0 commit comments

Comments
 (0)