From c50b027c2233d1d8a5adb1cf0f16bda3ba979421 Mon Sep 17 00:00:00 2001 From: allenliang2022 <98301349+allenliang2022@users.noreply.github.com> Date: Sat, 27 Jun 2026 15:43:32 +0800 Subject: [PATCH] fix: strip codex metadata for copilot responses --- .../responses/transformation.py | 16 ++++++++++++ ...github_copilot_responses_transformation.py | 25 +++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/litellm/llms/github_copilot/responses/transformation.py b/litellm/llms/github_copilot/responses/transformation.py index d9f759e0a05..7abb8bef224 100644 --- a/litellm/llms/github_copilot/responses/transformation.py +++ b/litellm/llms/github_copilot/responses/transformation.py @@ -251,6 +251,22 @@ class GithubCopilotResponsesAPIConfig(OpenAIResponsesAPIConfig): message=str(e), ) + def _validate_input_param( + self, input: Union[str, ResponseInputParam] + ) -> Union[str, ResponseInputParam]: + from litellm.litellm_core_utils.prompt_templates.common_utils import ( + filter_value_from_dict, + ) + + validated_input = super()._validate_input_param(input) + if isinstance(validated_input, list): + for item in validated_input: + if isinstance(item, dict): + filter_value_from_dict( + item, "internal_chat_message_metadata_passthrough" + ) + return validated_input + def get_complete_url( self, api_base: Optional[str], diff --git a/tests/test_litellm/llms/github_copilot/responses/test_github_copilot_responses_transformation.py b/tests/test_litellm/llms/github_copilot/responses/test_github_copilot_responses_transformation.py index 174efceb499..56f547803ca 100644 --- a/tests/test_litellm/llms/github_copilot/responses/test_github_copilot_responses_transformation.py +++ b/tests/test_litellm/llms/github_copilot/responses/test_github_copilot_responses_transformation.py @@ -320,6 +320,31 @@ class TestGithubCopilotResponsesAPITransformation: for param in expected_params: assert param in supported, f"{param} should be in supported params" + def test_transform_request_strips_codex_internal_metadata(self): + config = GithubCopilotResponsesAPIConfig() + transformed = config.transform_responses_api_request( + model="gpt-5.3-codex", + input=[ + { + "role": "user", + "content": "hello", + "internal_chat_message_metadata_passthrough": {"local": True}, + "nested": { + "internal_chat_message_metadata_passthrough": "remove-me", + "keep": "value", + }, + } + ], + response_api_optional_request_params={"max_output_tokens": 16}, + litellm_params={}, + headers={}, + ) + + input_item = transformed["input"][0] + assert "internal_chat_message_metadata_passthrough" not in input_item + assert "internal_chat_message_metadata_passthrough" not in input_item["nested"] + assert input_item["nested"]["keep"] == "value" + def test_handle_reasoning_item_preserves_encrypted_content(self): """Test that _handle_reasoning_item preserves encrypted_content for GitHub Copilot.