diff --git a/litellm/responses/litellm_completion_transformation/transformation.py b/litellm/responses/litellm_completion_transformation/transformation.py index 044596676dd..3b3894378f0 100644 --- a/litellm/responses/litellm_completion_transformation/transformation.py +++ b/litellm/responses/litellm_completion_transformation/transformation.py @@ -1563,10 +1563,10 @@ class LiteLLMCompletionResponsesConfig: ChatCompletionToolMessage is used to indicate the output from a tool call """ call_id: Final = tool_call_output.get("call_id") - # If call_id is missing or empty, skip this message - # Empty call_id means we can't create a valid tool message if not call_id: - return [] + # Some clients send tool output without the Responses correlation key. + # Preserve the result with a synthetic ID rather than dropping the turn. + call_id = f"call_synthetic_{uuid.uuid4().hex[:12]}" def _normalize_function_call_output_to_tool_content( output: object, @@ -1645,9 +1645,7 @@ class LiteLLMCompletionResponsesConfig: tool_call_id=str(call_id), ) - _tool_use_definition: Final = TOOL_CALLS_CACHE.get_cache( - key=tool_call_output.get("call_id") or "", - ) + _tool_use_definition: Final = TOOL_CALLS_CACHE.get_cache(key=call_id) if _tool_use_definition: """ Append the tool use definition to the list of messages @@ -2036,7 +2034,7 @@ class LiteLLMCompletionResponsesConfig: if tool_type == "custom": converted: Final = convert_custom_tool_to_function_tool(tool) return ResponsesToolChatForm(chat_tools=() if converted is None else (converted,), web_search_options=None) - if tool_type in ("computer_use", "image_generation", "shell"): + if tool_type in ("computer_use", "image_generation", "shell", "tool_search", "local_shell"): verbose_logger.warning( "Dropping Responses API tool of type '%s': it has no Chat Completions " "equivalent and the target provider would reject the request.", diff --git a/litellm/utils.py b/litellm/utils.py index f2315651a53..391b5bc6e41 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -8895,7 +8895,10 @@ class ProviderConfigManager: elif litellm.LlmProviders.OPENROUTER == provider: return litellm.OpenRouterResponsesAPIConfig() elif litellm.LlmProviders.HOSTED_VLLM == provider: - return litellm.HostedVLLMResponsesAPIConfig() + # vLLM deployments vary in their Responses API fidelity. Default to the + # chat-completions bridge; deployment model_info can opt into native + # /v1/responses via supported_endpoints. + return None elif litellm.LlmProviders.FIREWORKS_AI == provider: return litellm.FireworksAIResponsesAPIConfig() elif litellm.LlmProviders.BEDROCK_MANTLE == provider: diff --git a/tests/llm_responses_api_testing/test_anthropic_tool_result_empty_call_id.py b/tests/llm_responses_api_testing/test_anthropic_tool_result_empty_call_id.py index 28621c6531f..8725f3ee28b 100644 --- a/tests/llm_responses_api_testing/test_anthropic_tool_result_empty_call_id.py +++ b/tests/llm_responses_api_testing/test_anthropic_tool_result_empty_call_id.py @@ -22,10 +22,10 @@ from litellm.responses.litellm_completion_transformation.transformation import ( from litellm.llms.anthropic.chat.transformation import AnthropicConfig -def test_empty_tool_call_id_is_skipped(): +def test_empty_tool_call_id_is_synthesized(): """ - Test that tool messages with empty tool_call_id are skipped - when transforming function_call_output to chat completion messages. + Test that tool output with an empty tool_call_id is preserved as a tool message + instead of being silently dropped by the Responses -> Chat Completions bridge. """ # Simulate a function_call_output with empty call_id (the bug scenario) tool_call_output_empty = { @@ -34,15 +34,14 @@ def test_empty_tool_call_id_is_skipped(): "output": '{"output":"test output","metadata":{"exit_code":0}}', } - # Transform should return empty list (skip the message) result = LiteLLMCompletionResponsesConfig._transform_responses_api_tool_call_output_to_chat_completion_message( tool_call_output_empty ) - assert ( - result == [] - ), "Tool messages with empty call_id should be skipped, not created" - print("[OK] Empty call_id messages are correctly skipped") + assert len(result) == 1 + assert result[0]["role"] == "tool" + assert result[0]["tool_call_id"].startswith("call_synthetic_") + print("[OK] Empty call_id messages get a synthetic tool_call_id") def test_empty_tool_call_id_in_messages_list_is_removed(): diff --git a/tests/test_litellm/llms/hosted_vllm/responses/test_hosted_vllm_responses.py b/tests/test_litellm/llms/hosted_vllm/responses/test_hosted_vllm_responses.py index e81bf0c4f1f..9dcfe048ff6 100644 --- a/tests/test_litellm/llms/hosted_vllm/responses/test_hosted_vllm_responses.py +++ b/tests/test_litellm/llms/hosted_vllm/responses/test_hosted_vllm_responses.py @@ -7,93 +7,23 @@ when extra_body=None was passed through the responses→completion pipeline for hosted_vllm (and any OpenAI-compatible provider using add_provider_specific_params_to_optional_params). """ -import json -from unittest.mock import MagicMock, patch +from unittest.mock import MagicMock import pytest - -import litellm from litellm.llms.hosted_vllm.responses.transformation import ( HostedVLLMResponsesAPIConfig, ) +from litellm.llms.openai_like.responses.transformation import OpenAILikeResponsesConfig +from litellm.responses.litellm_completion_transformation.transformation import ( + LiteLLMCompletionResponsesConfig, +) +from litellm.responses.main import _resolve_responses_api_provider_config from litellm.types.router import GenericLiteLLMParams from litellm.types.utils import LlmProviders from litellm.utils import ProviderConfigManager -def _make_mock_responses_api_response(content: str = "Hello! I'm doing well.") -> dict: - return { - "id": "resp-test123", - "object": "response", - "created_at": 1234567890, - "model": "Qwen/Qwen3-8B", - "output": [ - { - "type": "message", - "id": "msg-test123", - "status": "completed", - "role": "assistant", - "content": [ - { - "type": "output_text", - "text": content, - "annotations": [], - } - ], - } - ], - "status": "completed", - "usage": { - "input_tokens": 10, - "output_tokens": 20, - "total_tokens": 30, - }, - } - - -def _make_mock_http_client(response_body: dict) -> MagicMock: - mock_client = MagicMock() - mock_response = MagicMock() - mock_response.status_code = 200 - mock_response.headers = {"content-type": "application/json"} - mock_response.json.return_value = response_body - mock_response.text = json.dumps(response_body) - mock_client.post.return_value = mock_response - return mock_client - - -def test_hosted_vllm_responses_create_with_string_input(): - """ - Test that hosted_vllm routes directly to the native /v1/responses endpoint - when the Responses API config is registered, and correctly parses the response. - """ - mock_client = _make_mock_http_client( - _make_mock_responses_api_response("I'm doing well, thanks!") - ) - - with patch( - "litellm.llms.custom_httpx.llm_http_handler._get_httpx_client", - return_value=mock_client, - ): - response = litellm.responses( - model="hosted_vllm/Qwen/Qwen3-8B", - input="Hello, how are you?", - api_base="https://test-vllm.example.com/v1", - api_key="test-key", - ) - - from litellm.types.llms.openai import ResponsesAPIResponse - - assert response is not None - assert isinstance(response, ResponsesAPIResponse) - assert len(response.output) > 0 - output_message = response.output[0] - assert output_message.role == "assistant" # type: ignore[union-attr] - assert len(output_message.content) > 0 # type: ignore[union-attr] - assert "well" in output_message.content[0].text # type: ignore[union-attr] - - def test_hosted_vllm_responses_create_with_explicit_none_extra_body(): """ Directly verify the fix in add_provider_specific_params_to_optional_params: @@ -115,16 +45,52 @@ def test_hosted_vllm_responses_create_with_explicit_none_extra_body(): ) -def test_hosted_vllm_provider_config_registration(): - """Test that ProviderConfigManager returns HostedVLLMResponsesAPIConfig for hosted_vllm.""" +def test_hosted_vllm_provider_defaults_to_chat_completions_bridge(): + """Hosted vLLM backends vary in Responses API fidelity, so default to the bridge. + + A deployment may explicitly opt into native /v1/responses via model_info. + """ config = ProviderConfigManager.get_provider_responses_api_config( model="hosted_vllm/Qwen/Qwen3-8B", provider=LlmProviders.HOSTED_VLLM, ) - assert config is not None - assert isinstance(config, HostedVLLMResponsesAPIConfig) - assert config.custom_llm_provider == LlmProviders.HOSTED_VLLM + assert config is None + + +def test_hosted_vllm_provider_supports_deployment_opt_in(): + config = _resolve_responses_api_provider_config( + "Qwen/Qwen3-8B", + "hosted_vllm", + {"supported_endpoints": ["/v1/responses"]}, + ) + + assert isinstance(config, OpenAILikeResponsesConfig) + + +@pytest.mark.parametrize("tool_type", ["tool_search", "local_shell"]) +def test_hosted_vllm_bridge_drops_unsupported_server_tools(tool_type): + """Codex sends these server-side tools to every Responses backend. + + Hosted vLLM's chat completions schema only accepts function tools, so + passing them through turns a valid agent turn into a 400 request. + """ + tools, web_search_options = ( + LiteLLMCompletionResponsesConfig.transform_responses_api_tools_to_chat_completion_tools( + [ + { + "type": "function", + "name": "get_weather", + "description": "Get weather", + "parameters": {"type": "object", "properties": {}}, + }, + {"type": tool_type}, + ] + ) + ) + + assert [tool["function"]["name"] for tool in tools] == ["get_weather"] + assert web_search_options is None def test_hosted_vllm_responses_api_url():