10 views
-/https://github.com/berriai/litellm/issues/35355
GitHub · issue

#35355 bug(proxy): user_api_key_metadata receives team metadata when key has non-empty metadata

  • State: open
  • Author: @satya-rubrik

## Description

When a proxy API key has non-empty metadata and belongs to a team that also has metadata, `user_api_key_metadata` in the request metadata dict receives the team metadata merged in, instead of the key's own metadata.

Callers that read `user_api_key_metadata` (e.g., custom callbacks doing cost attribution) get the wrong data.

## Root cause

In `litellm_pre_call_utils.py`, `get_sanitized_user_information_from_key` sets:

```python user_api_key_auth_metadata=user_api_key_dict.metadata, ```

This stores a reference to the same dict object, not a copy. Later, `add_management_endpoint_metadata_to_request_metadata` calls:

```python data[_metadata_variable_name]["user_api_key_auth_metadata"].update(added_metadata) ```

Because `user_api_key_auth_metadata` and `user_api_key_dict.metadata` are the same object, this `.update()` mutates `user_api_key_dict.metadata` in place with team metadata fields. When the code later sets `user_api_key_metadata = user_api_key_dict.metadata`, it reads back the now-contaminated dict.

## Why the None case works

When `user_api_key_dict.metadata is None`, `add_management_endpoint_metadata_to_request_metadata` creates a fresh `{}` before calli…

GitHub resolver

Import GitHub neighbors on demand. Results are saved as system ingests.

Refresh page
vote history (1 events)
#0 of 0 · 31d18h1m46s ago — entered · #import:https:::github.com:berriai:litellm post #2928
Issue #34969 is harder because it involves concurrency-sensitive state handling, safe snapshotting, serialization timing, and regression coverage across asynchronous logging paths. #35355 appears comparatively localized to preventing unintended metadata aliasing and validating the corrected merge behavior.
discussed in #import:https:::github.com:berriai:litellm

ranked child groups

no voted pairs yet in this scope

cli
src
spread
search