diff --git a/litellm/llms/bedrock/common_utils.py b/litellm/llms/bedrock/common_utils.py index 37dee8690c4..6344a5a41b5 100644 --- a/litellm/llms/bedrock/common_utils.py +++ b/litellm/llms/bedrock/common_utils.py @@ -1554,10 +1554,10 @@ def _bedrock_serves_responses(model: str) -> bool: def bedrock_responses_bridge_optional_params(optional_params: Mapping[str, object]) -> Mapping[str, object]: - if optional_params.get("store") is not None: - return optional_params extra_body: Final = optional_params.get("extra_body") extra_body_params: Final = _EXTRA_BODY_ADAPTER.validate_python(extra_body) if isinstance(extra_body, dict) else {} + if extra_body_params.get("store", optional_params.get("store")) is True: + return optional_params include: Final = extra_body_params.get("include", optional_params.get("include")) requested: Final = _INCLUDE_ADAPTER.validate_python(include or ()) return { diff --git a/tests/unit/llms/bedrock/chat/chat_completions/test_bedrock_chat_completions_transformation.py b/tests/unit/llms/bedrock/chat/chat_completions/test_bedrock_chat_completions_transformation.py index 97e709a1bb3..e91b0e6d0ef 100644 --- a/tests/unit/llms/bedrock/chat/chat_completions/test_bedrock_chat_completions_transformation.py +++ b/tests/unit/llms/bedrock/chat/chat_completions/test_bedrock_chat_completions_transformation.py @@ -1253,15 +1253,16 @@ async def test_a_provider_specific_param_keeps_converse_and_reaches_the_model(lo assert json.loads(requests[0].content)["additionalModelRequestFields"]["foo_bar"] == 1 -async def test_tools_with_reasoning_bridge_stores_only_when_the_caller_asks(local_cost_map, fake_aws_env): +@pytest.mark.parametrize("store_param", [{"store": True}, {"extra_body": {"store": True}}]) +async def test_tools_with_reasoning_bridge_stores_only_when_the_caller_asks(local_cost_map, fake_aws_env, store_param): requests, client = _async_recording_client(json={**RESPONSES_TOOL_CALL_JSON, "model": "global.openai.gpt-6-sol"}) await litellm.acompletion( model="bedrock/global.openai.gpt-6-sol", messages=[{"role": "user", "content": "weather in Paris"}], tools=[GET_WEATHER_TOOL], reasoning_effort="low", - store=True, client=client, + **store_param, ) body = json.loads(requests[0].content) @@ -1269,6 +1270,28 @@ async def test_tools_with_reasoning_bridge_stores_only_when_the_caller_asks(loca assert "include" not in body +@pytest.mark.parametrize( + "store_param", + [{}, {"store": False}, {"extra_body": {"store": False}}, {"store": True, "extra_body": {"store": False}}], +) +async def test_tools_with_reasoning_bridge_asks_for_encrypted_reasoning_whenever_store_is_off( + local_cost_map, fake_aws_env, store_param +): + requests, client = _async_recording_client(json={**RESPONSES_TOOL_CALL_JSON, "model": "global.openai.gpt-6-sol"}) + await litellm.acompletion( + model="bedrock/global.openai.gpt-6-sol", + messages=[{"role": "user", "content": "weather in Paris"}], + tools=[GET_WEATHER_TOOL], + reasoning_effort="low", + client=client, + **store_param, + ) + + body = json.loads(requests[0].content) + assert body["store"] is False + assert body["include"] == ["reasoning.encrypted_content"] + + @pytest.mark.parametrize( "include_param", [