diff --git a/litellm/llms/anthropic/experimental_pass_through/responses_adapters/transformation.py b/litellm/llms/anthropic/experimental_pass_through/responses_adapters/transformation.py index dae7044a5bc..e3d70093c60 100644 --- a/litellm/llms/anthropic/experimental_pass_through/responses_adapters/transformation.py +++ b/litellm/llms/anthropic/experimental_pass_through/responses_adapters/transformation.py @@ -8,6 +8,8 @@ path used for OpenAI and Azure models. import json from typing import Any, Dict, List, Optional, Union, cast +import litellm + from litellm.llms.anthropic.experimental_pass_through.utils import ( is_reasoning_auto_summary_enabled, ) @@ -384,7 +386,8 @@ class LiteLLMAnthropicToResponsesAPIAdapter: # metadata user_id -> user metadata = anthropic_request.get("metadata") if isinstance(metadata, dict) and "user_id" in metadata: - responses_kwargs["user"] = str(metadata["user_id"])[:64] + if not litellm.drop_params: + responses_kwargs["user"] = str(metadata["user_id"])[:64] return responses_kwargs diff --git a/tests/test_litellm/llms/anthropic/experimental_pass_through/responses_adapters/test_responses_adapters_transformation.py b/tests/test_litellm/llms/anthropic/experimental_pass_through/responses_adapters/test_responses_adapters_transformation.py index 02b817cd334..449c25fa8b9 100644 --- a/tests/test_litellm/llms/anthropic/experimental_pass_through/responses_adapters/test_responses_adapters_transformation.py +++ b/tests/test_litellm/llms/anthropic/experimental_pass_through/responses_adapters/test_responses_adapters_transformation.py @@ -1042,4 +1042,51 @@ class TestTranslateResponse: assert "thinking" in types assert "text" in types assert "tool_use" in types - assert result["stop_reason"] == "tool_use" + + +# --------------------------------------------------------------------------- +# drop_params: metadata.user_id -> user field +# --------------------------------------------------------------------------- + + +class TestDropParamsMetadataUserId: + """litellm.drop_params must suppress the user field mapped from metadata.user_id.""" + + def test_user_field_set_when_drop_params_false(self): + """user is included when drop_params is False (default).""" + import litellm + + req = _make_request(metadata={"user_id": "alice"}) + original = litellm.drop_params + try: + litellm.drop_params = False + kwargs = _ADAPTER.translate_request(req) + finally: + litellm.drop_params = original + assert kwargs.get("user") == "alice" + + def test_user_field_omitted_when_drop_params_true(self): + """user is omitted when drop_params is True (issue #26241).""" + import litellm + + req = _make_request(metadata={"user_id": "alice"}) + original = litellm.drop_params + try: + litellm.drop_params = True + kwargs = _ADAPTER.translate_request(req) + finally: + litellm.drop_params = original + assert "user" not in kwargs + + def test_no_metadata_no_user_field(self): + """No metadata means no user field regardless of drop_params.""" + import litellm + + req = _make_request() + original = litellm.drop_params + try: + litellm.drop_params = False + kwargs = _ADAPTER.translate_request(req) + finally: + litellm.drop_params = original + assert "user" not in kwargs