diff --git a/litellm/llms/anthropic/experimental_pass_through/messages/transformation.py b/litellm/llms/anthropic/experimental_pass_through/messages/transformation.py index e9ceea48220..21dcaafb853 100644 --- a/litellm/llms/anthropic/experimental_pass_through/messages/transformation.py +++ b/litellm/llms/anthropic/experimental_pass_through/messages/transformation.py @@ -46,8 +46,7 @@ class AnthropicMessagesConfig(BaseAnthropicMessagesConfig): "inference_geo", "speed", "output_config", - # TODO: Add Anthropic `metadata` support - # "metadata", + "metadata", ] def _remove_scope_from_cache_control( diff --git a/tests/test_litellm/llms/anthropic/experimental_pass_through/messages/test_anthropic_experimental_pass_through_messages_handler.py b/tests/test_litellm/llms/anthropic/experimental_pass_through/messages/test_anthropic_experimental_pass_through_messages_handler.py index 636e84fe796..c58c274c496 100644 --- a/tests/test_litellm/llms/anthropic/experimental_pass_through/messages/test_anthropic_experimental_pass_through_messages_handler.py +++ b/tests/test_litellm/llms/anthropic/experimental_pass_through/messages/test_anthropic_experimental_pass_through_messages_handler.py @@ -190,6 +190,31 @@ def test_openai_model_with_thinking_converts_to_reasoning(): assert "thinking" not in call_kwargs, "thinking should NOT be passed directly to litellm.responses" +def test_anthropic_messages_pass_through_includes_metadata(): + """ + Test that metadata is included in the transformed request body + when passed to the Anthropic messages pass-through. + """ + from litellm.llms.anthropic.experimental_pass_through.messages.transformation import ( + AnthropicMessagesConfig, + ) + from litellm.types.router import GenericLiteLLMParams + + config = AnthropicMessagesConfig() + result = config.transform_anthropic_messages_request( + model="claude-3-5-sonnet-20240620", + messages=[{"role": "user", "content": "Hello"}], + anthropic_messages_optional_request_params={ + "max_tokens": 100, + "metadata": {"user_id": "user-123"}, + }, + litellm_params=GenericLiteLLMParams(), + headers={}, + ) + + assert result.get("metadata") == {"user_id": "user-123"} + + class TestThinkingParameterTransformation: """Core tests for thinking parameter transformation logic."""