mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-06 02:48:13 +00:00
fix(messages): copy metadata dict to prevent raw_request leak to Anthropic API
LiteLLM's logging layer injects raw_request into the metadata dict via a shared reference with litellm_params. Without a copy, this extra key reaches the Anthropic API and triggers "Extra inputs are not permitted". PR #24661 fixed the same issue for the chat/completions path by stripping non-user_id keys. Here we use a shallow copy to break the shared reference before the request is sent.
This commit is contained in:
parent
26fcbc93e5
commit
daeb9292a4
1 changed files with 6 additions and 0 deletions
|
|
@ -222,6 +222,12 @@ class AnthropicMessagesConfig(BaseAnthropicMessagesConfig):
|
|||
optional_params=anthropic_messages_optional_request_params,
|
||||
)
|
||||
|
||||
# Break metadata shared reference with litellm_params so that
|
||||
# pre_call's raw_request injection doesn't leak into the API request.
|
||||
metadata = anthropic_messages_optional_request_params.get("metadata")
|
||||
if isinstance(metadata, dict):
|
||||
anthropic_messages_optional_request_params["metadata"] = dict(metadata)
|
||||
|
||||
# Filter out x-anthropic-billing-header from system messages
|
||||
system_param = anthropic_messages_optional_request_params.get("system")
|
||||
if system_param is not None:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue