mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-10 03:28:53 +00:00
fix: support metadata in anthropic /v1/messages pass-through
The metadata param was listed as a TODO in get_supported_anthropic_messages_params() and never forwarded to the Anthropic API. AnthropicMessagesRequest already had the field defined; this change removes the TODO and uncomments the param so it is included in the transformed request body. Adds a unit test verifying the param flows through transform_anthropic_messages_request().
This commit is contained in:
parent
cec3e9e7d4
commit
4e2649ec6e
2 changed files with 26 additions and 2 deletions
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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."""
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue