From c7522a29d1b3b1ec4860fb1376e31f006d3cb813 Mon Sep 17 00:00:00 2001 From: Tai An Date: Tue, 21 Apr 2026 06:13:45 -0700 Subject: [PATCH] fix: coerce server_tool_use dict to ServerToolUse in stream_chunk_builder When streaming Anthropic responses with web_search_options, stream_chunk_builder reconstructs usage.server_tool_use as a dict rather than a ServerToolUse pydantic object. This causes AttributeError when completion_cost() accesses .web_search_requests on the dict. Apply the same dict-to-object coercion pattern already used for prompt_tokens_details. Fixes #26153 --- litellm/litellm_core_utils/streaming_chunk_builder_utils.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/litellm/litellm_core_utils/streaming_chunk_builder_utils.py b/litellm/litellm_core_utils/streaming_chunk_builder_utils.py index c808cfca457..d58ded11385 100644 --- a/litellm/litellm_core_utils/streaming_chunk_builder_utils.py +++ b/litellm/litellm_core_utils/streaming_chunk_builder_utils.py @@ -587,7 +587,10 @@ class ChunkProcessor: hasattr(usage_chunk, "server_tool_use") and usage_chunk.server_tool_use is not None ): - server_tool_use = usage_chunk.server_tool_use + _stu = usage_chunk.server_tool_use + server_tool_use = ( + ServerToolUse(**_stu) if isinstance(_stu, dict) else _stu + ) if ( usage_chunk_dict["prompt_tokens_details"] is not None and getattr(