fix(anthropic): name the marker's accepted ttl values in the malformed prompt_cache_breakpoint 400

This commit is contained in:
mateo-berri 2026-11-03 03:35:38 -08:00
parent f9241cdb11
commit 31feab70fa
2 changed files with 11 additions and 1 deletions

View file

@ -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,

View file

@ -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 = [