diff --git a/litellm/proxy/guardrails/guardrail_hooks/headroom/headroom.py b/litellm/proxy/guardrails/guardrail_hooks/headroom/headroom.py index eb62b896784..91327e6409e 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/headroom/headroom.py +++ b/litellm/proxy/guardrails/guardrail_hooks/headroom/headroom.py @@ -891,7 +891,9 @@ class HeadroomGuardrail(CustomGuardrail): if not has_headroom_retrieve_tool(effective.get("tools")): return base_result return { # mutable-ok: the hook contract is a plain dict the router merges into the request kwargs - **effective, + **{ # mutable-ok: removes stream-only options + key: value for key, value in effective.items() if key != "stream_options" + }, "stream": False, HEADROOM_CONVERTED_STREAM_KEY: True, } diff --git a/tests/test_litellm/proxy/guardrails/guardrail_hooks/test_headroom.py b/tests/test_litellm/proxy/guardrails/guardrail_hooks/test_headroom.py index bcecb5b27db..406b5df6c00 100644 --- a/tests/test_litellm/proxy/guardrails/guardrail_hooks/test_headroom.py +++ b/tests/test_litellm/proxy/guardrails/guardrail_hooks/test_headroom.py @@ -2155,7 +2155,7 @@ async def test_pre_call_deployment_hook_converts_stream_only_for_ccr_chat_comple tools: Optional[list], expect_conversion: bool, ): - kwargs = {"model": "gpt-4o", "stream": stream, "tools": tools} + kwargs = {"model": "gpt-4o", "stream": stream, "stream_options": {"include_usage": True}, "tools": tools} result = await guardrail.async_pre_call_deployment_hook(kwargs=kwargs, call_type=call_type) @@ -2163,12 +2163,15 @@ async def test_pre_call_deployment_hook_converts_stream_only_for_ccr_chat_comple assert result is kwargs assert HEADROOM_CONVERTED_STREAM_KEY not in kwargs assert kwargs["stream"] is stream + assert kwargs["stream_options"] == {"include_usage": True} return assert result is not None assert result["stream"] is False + assert "stream_options" not in result assert result[HEADROOM_CONVERTED_STREAM_KEY] is True assert kwargs["stream"] is True + assert kwargs["stream_options"] == {"include_usage": True} @pytest.mark.asyncio @@ -2223,6 +2226,7 @@ async def test_pre_call_deployment_hook_converts_stream_after_deployment_level_c "model": "gpt-4o", "messages": [dict(m) for m in ORIGINAL_MESSAGES], "stream": True, + "stream_options": {"include_usage": True}, "guardrails": ["headroom"], "metadata": {}, } @@ -2238,6 +2242,7 @@ async def test_pre_call_deployment_hook_converts_stream_after_deployment_level_c assert result is not None assert has_headroom_retrieve_tool(result["tools"]) assert result["stream"] is False + assert "stream_options" not in result assert result[HEADROOM_CONVERTED_STREAM_KEY] is True