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]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix: Include hidden params in chat response to responses api response transformation (#20084)
Nate Tessmand7997db912b3
diff --git a/litellm/responses/litellm_completion_transformation/transformation.py b/litellm/responses/litellm_completion_transformation/transformation.pyindex 74cc87713da..df298f7c448 100644--- a/litellm/responses/litellm_completion_transformation/transformation.py+++ b/litellm/responses/litellm_completion_transformation/transformation.py@@ -1413,6 +1413,7 @@ class LiteLLMCompletionResponsesConfig:),user=getattr(chat_completion_response, "user", None),)+ responses_api_response._hidden_params = getattr(chat_completion_response, "_hidden_params", {})return responses_api_response@staticmethoddiff --git a/tests/test_litellm/responses/litellm_completion_transformation/test_litellm_completion_responses.py b/tests/test_litellm/responses/litellm_completion_transformation/test_litellm_completion_responses.pyindex f7a1984d32f..5074bbf4397 100644--- a/tests/test_litellm/responses/litellm_completion_transformation/test_litellm_completion_responses.py+++ b/tests/test_litellm/responses/litellm_completion_transformation/test_litellm_completion_responses.py@@ -468,6 +468,77 @@ class TestLiteLLMCompletionResponsesConfig:]assert item.status != "stop"+ def test_transform_chat_completion_response_preserves_hidden_params(self):+ """Test that _hidden_params from chat completion response are preserved in responses API response"""+ # Setup+ chat_completion_response = ModelResponse(+ id="test-response-id",+ created=1234567890,+ model="test-model",+ object="chat.completion",+ choices=[+ Choices(+ finish_reason="stop",+ index=0,+ message=Message(+ content="Test response",+ role="assistant",+ ),+ )+ ],+ )+ # Set hidden params on the chat completion response+ chat_completion_response._hidden_params = {+ "model_id": "abc123",+ "cache_key": "some-cache-key",+ "custom_llm_provider": "openai",+ }++ # Execute+ responses_api_response = LiteLLMCompletionResponsesConfig.transform_chat_completion_response_to_responses_api_response(+ request_input="Test",+ responses_api_request={},+ chat_completion_response=chat_completion_response,+ )++ # Assert+ assert hasattr(responses_api_response, "_hidden_params")+ assert responses_api_response._hidden_params == {+ "model_id": "abc123",+ "cache_key": "some-cache-key",+ "custom_llm_provider": "openai",+ }++ def test_transform_chat_completion_response_handles_missing_hidden_params(self):+ """Test that missing _hidden_params defaults to empty dict"""+ # Setup - no _hidden_params set+ chat_completion_response = ModelResponse(+ id="test-response-id",+ created=1234567890,+ model="test-model",+ object="chat.completion",+ choices=[+ Choices(+ finish_reason="stop",+ index=0,+ message=Message(+ content="Test response",+ role="assistant",+ ),+ )+ ],+ )++ # Execute+ responses_api_response = LiteLLMCompletionResponsesConfig.transform_chat_completion_response_to_responses_api_response(+ request_input="Test",+ responses_api_request={},+ chat_completion_response=chat_completion_response,+ )++ # Assert - should default to empty dict+ assert hasattr(responses_api_response, "_hidden_params")+ assert responses_api_response._hidden_params == {}class TestFunctionCallTransformation:"""Test cases for function_call input transformation"""