From 31feab70fac8e556a331c1c05743556301ca4106 Mon Sep 17 00:00:00 2001 From: mateo-berri <277851410+mateo-berri@users.noreply.github.com> Date: Tue, 3 Nov 2026 03:35:38 -0800 Subject: [PATCH] fix(anthropic): name the marker's accepted ttl values in the malformed prompt_cache_breakpoint 400 --- .../litellm_core_utils/prompt_templates/common_utils.py | 3 ++- .../anthropic/chat/test_anthropic_chat_transformation.py | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/litellm/litellm_core_utils/prompt_templates/common_utils.py b/litellm/litellm_core_utils/prompt_templates/common_utils.py index a3e31c4a9b7..6ecab166dcd 100644 --- a/litellm/litellm_core_utils/prompt_templates/common_utils.py +++ b/litellm/litellm_core_utils/prompt_templates/common_utils.py @@ -2290,7 +2290,8 @@ def _cache_control_for_prompt_cache_breakpoint(marker: object, drop_params: bool if not drop_params: raise UnsupportedParamsError( message=( - f"prompt_cache_breakpoint must be {{'mode': 'explicit'}}, got {marker!r}. Fix the marker, or " + f"prompt_cache_breakpoint must be {{'mode': 'explicit'}} with an optional ttl of '30m' or '12h', got " + f"{marker!r}. Fix the marker, or " f"{PROMPT_CACHE_BREAKPOINT_DROP_PARAMS_HINT} to drop it." ), status_code=400, diff --git a/tests/unit/llms/anthropic/chat/test_anthropic_chat_transformation.py b/tests/unit/llms/anthropic/chat/test_anthropic_chat_transformation.py index 54c1b5937bf..fc873832956 100644 --- a/tests/unit/llms/anthropic/chat/test_anthropic_chat_transformation.py +++ b/tests/unit/llms/anthropic/chat/test_anthropic_chat_transformation.py @@ -4486,6 +4486,15 @@ def test_transform_request_prompt_cache_breakpoint_without_claude_equivalent(mar assert body["messages"] == [{"role": "user", "content": [expected_block]}] +def test_transform_request_names_the_marker_ttl_rule_for_a_ttl_only_claude_takes(): + messages: Final = [ + {"role": "user", "content": [{"type": "text", "text": "Hello", "prompt_cache_breakpoint": {"mode": "explicit", "ttl": "1h"}}]} + ] + + with pytest.raises(litellm.utils.UnsupportedParamsError, match="optional ttl of '30m' or '12h'"): + _anthropic_body(messages) + + def test_transform_request_keeps_the_first_and_last_prompt_cache_breakpoints_within_the_cap(): client_marked_part: Final = {"type": "text", "text": "part 0", "cache_control": {"type": "ephemeral"}} marked_parts: Final = [