@@ -75,12 +75,12 @@ def _capture_exception(exc: "Any") -> None:
7575def _get_token_usage (result : "Messages" ) -> "tuple[int, int, int, int]" :
7676 """
7777 Get token usage from the Anthropic response.
78- Returns: (input_tokens, output_tokens, cache_read_input_tokens, cache_creation_input_tokens )
78+ Returns: (input_tokens, output_tokens, cache_read_input_tokens, cache_write_input_tokens )
7979 """
8080 input_tokens = 0
8181 output_tokens = 0
8282 cache_read_input_tokens = 0
83- cache_creation_input_tokens = 0
83+ cache_write_input_tokens = 0
8484 if hasattr (result , "usage" ):
8585 usage = result .usage
8686 if hasattr (usage , "input_tokens" ) and isinstance (usage .input_tokens , int ):
@@ -90,9 +90,9 @@ def _get_token_usage(result: "Messages") -> "tuple[int, int, int, int]":
9090 if hasattr (usage , "cache_read_input_tokens" ) and isinstance (usage .cache_read_input_tokens , int ):
9191 cache_read_input_tokens = usage .cache_read_input_tokens
9292 if hasattr (usage , "cache_creation_input_tokens" ) and isinstance (usage .cache_creation_input_tokens , int ):
93- cache_creation_input_tokens = usage .cache_creation_input_tokens
93+ cache_write_input_tokens = usage .cache_creation_input_tokens
9494
95- return input_tokens , output_tokens , cache_read_input_tokens , cache_creation_input_tokens
95+ return input_tokens , output_tokens , cache_read_input_tokens , cache_write_input_tokens
9696
9797
9898def _collect_ai_data (
@@ -102,7 +102,7 @@ def _collect_ai_data(
102102 output_tokens : int ,
103103 content_blocks : "list[str]" ,
104104 cache_read_input_tokens : int ,
105- cache_creation_input_tokens : int ,
105+ cache_write_input_tokens : int ,
106106) -> "tuple[str | None, int, int, list[str], int, int]" :
107107 """
108108 Collect model information, token usage, and collect content blocks from the AI streaming response.
@@ -116,7 +116,7 @@ def _collect_ai_data(
116116 if hasattr (usage , "cache_read_input_tokens" ) and isinstance (usage .cache_read_input_tokens , int ):
117117 cache_read_input_tokens += usage .cache_read_input_tokens
118118 if hasattr (usage , "cache_creation_input_tokens" ) and isinstance (usage .cache_creation_input_tokens , int ):
119- cache_creation_input_tokens += usage .cache_creation_input_tokens
119+ cache_write_input_tokens += usage .cache_creation_input_tokens
120120 model = event .message .model or model
121121 elif event .type == "content_block_start" :
122122 pass
@@ -130,7 +130,7 @@ def _collect_ai_data(
130130 elif event .type == "message_delta" :
131131 output_tokens += event .usage .output_tokens
132132
133- return model , input_tokens , output_tokens , content_blocks , cache_read_input_tokens , cache_creation_input_tokens
133+ return model , input_tokens , output_tokens , content_blocks , cache_read_input_tokens , cache_write_input_tokens
134134
135135
136136def _set_input_data (
@@ -235,7 +235,7 @@ def _set_output_data(
235235 content_blocks : "list[Any]" ,
236236 finish_span : bool = False ,
237237 cache_read_input_tokens : "int | None" = None ,
238- cache_creation_input_tokens : "int | None" = None ,
238+ cache_write_input_tokens : "int | None" = None ,
239239) -> None :
240240 """
241241 Set output data for the span based on the AI response."""
@@ -270,7 +270,7 @@ def _set_output_data(
270270 input_tokens = input_tokens ,
271271 output_tokens = output_tokens ,
272272 input_tokens_cached = cache_read_input_tokens ,
273- input_tokens_cache_write = cache_creation_input_tokens ,
273+ input_tokens_cache_write = cache_write_input_tokens ,
274274 )
275275
276276 if finish_span :
@@ -305,7 +305,7 @@ def _sentry_patched_create_common(f: "Any", *args: "Any", **kwargs: "Any") -> "A
305305
306306 with capture_internal_exceptions ():
307307 if hasattr (result , "content" ):
308- input_tokens , output_tokens , cache_read_input_tokens , cache_creation_input_tokens = _get_token_usage (result )
308+ input_tokens , output_tokens , cache_read_input_tokens , cache_write_input_tokens = _get_token_usage (result )
309309
310310 content_blocks = []
311311 for content_block in result .content :
@@ -325,7 +325,7 @@ def _sentry_patched_create_common(f: "Any", *args: "Any", **kwargs: "Any") -> "A
325325 content_blocks = content_blocks ,
326326 finish_span = True ,
327327 cache_read_input_tokens = cache_read_input_tokens ,
328- cache_creation_input_tokens = cache_creation_input_tokens ,
328+ cache_write_input_tokens = cache_write_input_tokens ,
329329 )
330330
331331 # Streaming response
@@ -338,12 +338,12 @@ def new_iterator() -> "Iterator[MessageStreamEvent]":
338338 output_tokens = 0
339339 content_blocks : "list[str]" = []
340340 cache_read_input_tokens = 0
341- cache_creation_input_tokens = 0
341+ cache_write_input_tokens = 0
342342
343343 for event in old_iterator :
344- model , input_tokens , output_tokens , content_blocks , cache_read_input_tokens , cache_creation_input_tokens = (
344+ model , input_tokens , output_tokens , content_blocks , cache_read_input_tokens , cache_write_input_tokens = (
345345 _collect_ai_data (
346- event , model , input_tokens , output_tokens , content_blocks , cache_read_input_tokens , cache_creation_input_tokens
346+ event , model , input_tokens , output_tokens , content_blocks , cache_read_input_tokens , cache_write_input_tokens
347347 )
348348 )
349349 yield event
@@ -357,7 +357,7 @@ def new_iterator() -> "Iterator[MessageStreamEvent]":
357357 content_blocks = [{"text" : "" .join (content_blocks ), "type" : "text" }],
358358 finish_span = True ,
359359 cache_read_input_tokens = cache_read_input_tokens ,
360- cache_creation_input_tokens = cache_creation_input_tokens ,
360+ cache_write_input_tokens = cache_write_input_tokens ,
361361 )
362362
363363 async def new_iterator_async () -> "AsyncIterator[MessageStreamEvent]" :
@@ -366,12 +366,12 @@ async def new_iterator_async() -> "AsyncIterator[MessageStreamEvent]":
366366 output_tokens = 0
367367 content_blocks : "list[str]" = []
368368 cache_read_input_tokens = 0
369- cache_creation_input_tokens = 0
369+ cache_write_input_tokens = 0
370370
371371 async for event in old_iterator :
372- model , input_tokens , output_tokens , content_blocks , cache_read_input_tokens , cache_creation_input_tokens = (
372+ model , input_tokens , output_tokens , content_blocks , cache_read_input_tokens , cache_write_input_tokens = (
373373 _collect_ai_data (
374- event , model , input_tokens , output_tokens , content_blocks , cache_read_input_tokens , cache_creation_input_tokens
374+ event , model , input_tokens , output_tokens , content_blocks , cache_read_input_tokens , cache_write_input_tokens
375375 )
376376 )
377377 yield event
@@ -385,7 +385,7 @@ async def new_iterator_async() -> "AsyncIterator[MessageStreamEvent]":
385385 content_blocks = [{"text" : "" .join (content_blocks ), "type" : "text" }],
386386 finish_span = True ,
387387 cache_read_input_tokens = cache_read_input_tokens ,
388- cache_creation_input_tokens = cache_creation_input_tokens ,
388+ cache_write_input_tokens = cache_write_input_tokens ,
389389 )
390390
391391 if str (type (result ._iterator )) == "<class 'async_generator'>" :
0 commit comments