From af175185e147420f70e93e156ff61b38dedca207 Mon Sep 17 00:00:00 2001 From: mateo-berri <277851410+mateo-berri@users.noreply.github.com> Date: Wed, 4 Nov 2026 21:02:53 -0800 Subject: [PATCH] fix(anthropic): skip non-string anthropic-beta list entries instead of raising --- litellm/llms/anthropic/common_utils.py | 2 +- .../anthropic/test_anthropic_common_utils.py | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/litellm/llms/anthropic/common_utils.py b/litellm/llms/anthropic/common_utils.py index b3d29be36a5..646e0387d9e 100644 --- a/litellm/llms/anthropic/common_utils.py +++ b/litellm/llms/anthropic/common_utils.py @@ -517,7 +517,7 @@ def merge_anthropic_beta_headers(existing: str | Sequence[str] | None, new_beta: return ",".join(sorted(betas)) -_HEADER_VALUE_LIST: Final = TypeAdapter(tuple[JsonValue, ...]) +_HEADER_VALUE_LIST: Final = TypeAdapter(tuple[object, ...]) def _header_strings(value: object) -> tuple[str, ...]: diff --git a/tests/unit/llms/anthropic/test_anthropic_common_utils.py b/tests/unit/llms/anthropic/test_anthropic_common_utils.py index cf0b8a39865..aa0aebaa9c9 100644 --- a/tests/unit/llms/anthropic/test_anthropic_common_utils.py +++ b/tests/unit/llms/anthropic/test_anthropic_common_utils.py @@ -26,7 +26,12 @@ import pytest import respx import litellm -from litellm.llms.anthropic.common_utils import ToolsWithoutStrict, is_claude_tool_target, tools_without_strict +from litellm.llms.anthropic.common_utils import ( + ToolsWithoutStrict, + is_claude_tool_target, + merge_header_sources, + tools_without_strict, +) from litellm.llms.custom_httpx.http_handler import HTTPHandler sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../../.."))) @@ -4728,3 +4733,15 @@ def test_tools_without_strict_drops_only_the_strict_key_and_counts_the_strict_to assert tools_without_strict(tools) == ToolsWithoutStrict( tools=({"name": "a"}, {"name": "b"}, {"name": "c"}), dropped_count=1 ) + + +def test_merge_header_sources_keeps_only_the_string_betas_of_a_mixed_list() -> None: + merged: Final = merge_header_sources( + {"anthropic-beta": ["context-1m-2025-08-07", b"bytes-beta", ("nested",), object(), 3]}, + {"Anthropic-Beta": "message-threads-2026-08-12", "x-other": "kept"}, + ) + + assert dict(merged) == { + "anthropic-beta": "context-1m-2025-08-07,message-threads-2026-08-12", + "x-other": "kept", + }