Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

Merge remote-tracking branch 'origin/litellm_internal_staging' into litellm_fix_responses_reasoning_drop_params

mateo-berri77ca1a3b318b
diff --cc tests/test_litellm/llms/openai/responses/test_openai_responses_transformation.py
index 66d22cf8fb0,1a90db7c1fe..b3d43e0d19b
--- a/tests/test_litellm/llms/openai/responses/test_openai_responses_transformation.py
+++ b/tests/test_litellm/llms/openai/responses/test_openai_responses_transformation.py
@@@ -1628,47 -1629,190 +1629,236 @@@ class TestResponsesSurfaceSharesTheEffo
assert ("temperature" in mapped) is temperature_survives
+ class TestFlattenToolSchemaCombinatorsWiring:
+ """Regression tests for MCP tools with a top-level anyOf schema (Codex Desktop).
+
+ OpenAI's /v1/responses rejects function tool parameters carrying
+ 'oneOf'/'anyOf'/'allOf'/'enum'/'const'/'not' at the top level, while the
+ ChatGPT backend Codex uses natively accepts them, so those tools 400'd
+ through the proxy with "Invalid schema for function ...".
+ """
+
+ def _anyof_parameters(self):
+ return {
+ "type": "object",
+ "anyOf": [
+ {
+ "properties": {"id": {"type": "string"}, "enabled": {"type": "boolean"}},
+ "required": ["id", "enabled"],
+ },
+ {
+ "properties": {"id": {"type": "string"}, "schedule": {"type": "string"}},
+ "required": ["id", "schedule"],
+ },
+ ],
+ "properties": {"id": {"type": "string"}},
+ "required": ["id"],
+ }
+
+ def _flat_function_tool(self):
+ return {
+ "type": "function",
+ "name": "mcp__codex_app__automation_update",
+ "description": "Update an automation",
+ "parameters": self._anyof_parameters(),
+ "strict": False,
+ }
+
+ def _codex_namespace_tool(self):
+ return {
+ "type": "namespace",
+ "name": "mcp__codex_app",
+ "tools": [
+ {
+ "name": "automation_update",
+ "description": "Update an automation",
+ "parameters": self._anyof_parameters(),
+ "strict": False,
+ }
+ ],
+ }
+
+ def test_openai_flattens_top_level_anyof_on_flat_function_tool(self):
+ result = OpenAIResponsesAPIConfig().transform_responses_api_request(
+ model="gpt-4o",
+ input="hi",
+ response_api_optional_request_params={"tools": [self._flat_function_tool()]},
+ litellm_params=GenericLiteLLMParams(),
+ headers={},
+ )
+
+ parameters = result["tools"][0]["parameters"]
+ assert "anyOf" not in parameters
+ assert parameters["type"] == "object"
+ assert set(parameters["properties"]) == {"id", "enabled", "schedule"}
+ assert parameters["required"] == ["id"]
+ assert json.loads(json.dumps(result["tools"])) == result["tools"]
+
+ def test_openai_flattens_anyof_inside_codex_namespace_tools(self):
+ result = OpenAIResponsesAPIConfig().transform_responses_api_request(
+ model="gpt-4o",
+ input="hi",
+ response_api_optional_request_params={"tools": [self._codex_namespace_tool()]},
+ litellm_params=GenericLiteLLMParams(),
+ headers={},
+ )
+
+ nested_parameters = result["tools"][0]["tools"][0]["parameters"]
+ assert "anyOf" not in nested_parameters
+ assert set(nested_parameters["properties"]) == {"id", "enabled", "schedule"}
+ assert json.loads(json.dumps(result["tools"])) == result["tools"]
+
+ def test_openai_compact_request_flattens_top_level_anyof(self):
+ _, data = OpenAIResponsesAPIConfig().transform_compact_response_api_request(
+ model="gpt-4o",
+ input="hi",
+ response_api_optional_request_params={"tools": [self._flat_function_tool()]},
+ api_base="https://api.openai.com/v1/responses",
+ litellm_params=GenericLiteLLMParams(),
+ headers={},
+ )
+
+ assert "anyOf" not in data["tools"][0]["parameters"]
+
+ def test_openai_leaves_tools_without_rejected_keys_alone(self):
+ clean_tool = {
+ "type": "function",
+ "name": "get_weather",
+ "parameters": {"type": "object", "properties": {"city": {"type": "string"}}},
+ }
+
+ result = OpenAIResponsesAPIConfig().transform_responses_api_request(
+ model="gpt-4o",
+ input="hi",
+ response_api_optional_request_params={"tools": [clean_tool]},
+ litellm_params=GenericLiteLLMParams(),
+ headers={},
+ )
+
+ assert result["tools"][0]["parameters"] == {"type": "object", "properties": {"city": {"type": "string"}}}
+
+ def test_openai_does_not_mutate_caller_tool_dicts(self):
+ tool = self._flat_function_tool()
+
+ OpenAIResponsesAPIConfig().transform_responses_api_request(
+ model="gpt-4o",
+ input="hi",
+ response_api_optional_request_params={"tools": [tool]},
+ litellm_params=GenericLiteLLMParams(),
+ headers={},
+ )
+
+ assert "anyOf" in tool["parameters"]
+
+ def test_non_openai_subclass_does_not_flatten(self):
+ from litellm.llms.hosted_vllm.responses.transformation import HostedVLLMResponsesAPIConfig
+
+ result = HostedVLLMResponsesAPIConfig().transform_responses_api_request(
+ model="hosted_vllm/qwen",
+ input="hi",
+ response_api_optional_request_params={"tools": [self._flat_function_tool()]},
+ litellm_params=GenericLiteLLMParams(),
+ headers={},
+ )
+
+ assert "anyOf" in result["tools"][0]["parameters"]
+
+ @pytest.mark.parametrize(
+ "model",
+ [
+ "gpt-4o",
+ "gpt-4.1-mini",
+ "gpt-4-turbo",
+ "o1",
+ "o3-pro",
+ "o4-mini",
+ "openai/gpt-4o",
+ "ft:gpt-4o-2024-08-06:org::abc",
+ ],
+ )
+ def test_openai_flattens_for_models_whose_validator_rejects_combinators(self, model):
+ result = OpenAIResponsesAPIConfig().transform_responses_api_request(
+ model=model,
+ input="hi",
+ response_api_optional_request_params={"tools": [self._flat_function_tool()]},
+ litellm_params=GenericLiteLLMParams(),
+ headers={},
+ )
+
+ assert "anyOf" not in result["tools"][0]["parameters"]
+
+ @pytest.mark.parametrize(
+ "model", ["gpt-5", "gpt-5-nano", "gpt-5.4-mini", "gpt-5.4-codex", "gpt-5.5", "openai/gpt-5.2"]
+ )
+ def test_openai_keeps_combinators_for_models_that_accept_them(self, model):
+ tool = self._flat_function_tool()
+
+ result = OpenAIResponsesAPIConfig().transform_responses_api_request(
+ model=model,
+ input="hi",
+ response_api_optional_request_params={"tools": [tool]},
+ litellm_params=GenericLiteLLMParams(),
+ headers={},
+ )
+
+ assert result["tools"][0] is tool
+
+ def test_openai_leaves_non_dict_tool_entries_alone(self):
+ opaque_tool = SimpleNamespace(type="function", name="automation_update")
+
+ result = OpenAIResponsesAPIConfig().transform_responses_api_request(
+ model="gpt-4o",
+ input="hi",
+ response_api_optional_request_params={"tools": [opaque_tool, self._flat_function_tool()]},
+ litellm_params=GenericLiteLLMParams(),
+ headers={},
+ )
+
+ assert result["tools"][0] is opaque_tool
+ assert "anyOf" not in result["tools"][1]["parameters"]
++
++
+class TestReasoningFollowsModelSupport:
+ """Responses API clients like Codex send `reasoning` on every request, and OpenAI 400s it
+ on non-reasoning models like gpt-4o. drop_params must strip it there, the same way the
+ chat completions surface already strips reasoning_effort for those models.
+ """
+
+ @pytest.mark.parametrize(
+ "model, reasoning_survives",
+ [
+ ("gpt-4o", False),
+ ("gpt-4.1", False),
+ ("gpt-4o-mini", False),
+ ("gpt-5.6", True),
+ ("o3", True),
+ ("o3-deep-research", True),
+ ("codex-mini-latest", True),
+ ("computer-use-preview", True),
+ ],
+ )
+ def test_drop_params_strips_reasoning_by_model(self, local_model_cost_map, model, reasoning_survives):
+ mapped = OpenAIResponsesAPIConfig().map_openai_params(
+ response_api_optional_params={"reasoning": {"effort": "medium", "summary": "auto"}},
+ model=model,
+ drop_params=True,
+ )
+ assert ("reasoning" in mapped) is reasoning_survives
+
+ def test_without_drop_params_the_error_is_litellms_400(self, local_model_cost_map, monkeypatch):
+ monkeypatch.setattr(litellm, "drop_params", False)
+ with pytest.raises(litellm.UnsupportedParamsError) as excinfo:
+ OpenAIResponsesAPIConfig().map_openai_params(
+ response_api_optional_params={"reasoning": {"effort": "medium"}},
+ model="gpt-4o",
+ drop_params=False,
+ )
+ assert excinfo.value.status_code == 400
+
+ def test_azure_deployments_keep_reasoning(self, local_model_cost_map):
+ mapped = AzureOpenAIResponsesAPIConfig().map_openai_params(
+ response_api_optional_params={"reasoning": {"effort": "medium"}},
+ model="my-o3-deployment",
+ drop_params=True,
+ )
+ assert mapped["reasoning"] == {"effort": "medium"}