feat(anthropic): add metadata support to Anthropic Messages passthrough

This commit is contained in:
samearth17 2026-08-14 02:25:10 +05:30
parent 6a919aec6a
commit ad761ad899
2 changed files with 51 additions and 2 deletions

View file

@ -68,8 +68,8 @@ class AnthropicMessagesConfig(BaseAnthropicMessagesConfig):
"speed",
"output_config",
"reasoning_effort",
# TODO: Add Anthropic `metadata` support
# "metadata",
"metadata",
]
def _remove_scope_from_cache_control(self, anthropic_messages_request: dict) -> None:

View file

@ -0,0 +1,49 @@
"""
Tests for Anthropic Messages passthrough metadata support.
Related issue: https://github.com/BerriAI/litellm/issues/30663
"""
import pytest
from litellm.llms.anthropic.experimental_pass_through.messages.transformation import (
AnthropicMessagesConfig,
)
class TestAnthropicMessagesMetadataSupport:
"""Test that metadata is properly supported in Anthropic Messages passthrough."""
def setup_method(self):
self.config = AnthropicMessagesConfig()
def test_metadata_in_supported_params(self):
"""Verify 'metadata' is listed in supported Anthropic Messages params."""
supported_params = self.config.get_supported_anthropic_messages_params(
model="claude-sonnet-4-20250514"
)
assert "metadata" in supported_params, (
"'metadata' should be in supported params for Anthropic Messages passthrough"
)
def test_metadata_appears_exactly_once(self):
"""Verify 'metadata' is not duplicated in the supported params list."""
supported_params = self.config.get_supported_anthropic_messages_params(
model="claude-sonnet-4-20250514"
)
assert supported_params.count("metadata") == 1
def test_core_params_still_present(self):
"""Regression: ensure adding metadata did not remove existing params."""
supported_params = self.config.get_supported_anthropic_messages_params(
model="claude-sonnet-4-20250514"
)
expected_core_params = [
"messages",
"model",
"system",
"max_tokens",
"temperature",
]
for param in expected_core_params:
assert param in supported_params