Skip to content

fix(litellm): use allowlist for span metadata - #578

Merged
Abhijeet Prasad (AbhiPrasad) merged 1 commit into
mainfrom
litellm-call-arg-metadata
Jul 16, 2026
Merged

Abhijeet Prasad (AbhiPrasad) merged 1 commit into
mainfrom
litellm-call-arg-metadata

Conversation

@AbhiPrasad

Copy link
Copy Markdown
Member

LiteLLM accepts provider credentials and transport headers directly on instrumented calls. For example:

litellm.completion(
    model="openai/example-model",
    messages=[{"role": "user", "content": "Hello"}],
    api_key=os.environ["OPENAI_API_KEY"],
    extra_headers={"Authorization": f"Bearer {token}"},
)

Cloud-provider credentials can also be supplied as kwargs:

litellm.completion(
    model="azure/example-deployment",
    messages=[...],
    azure_ad_token=os.environ["AZURE_AD_TOKEN"],
)

Previously, every kwarg other than the selected input and model flowed into span metadata and then into the logs upload:

litellm.completion kwargs
├── messages --------------------------> span.input
├── model -----------------------------> span.metadata.model
└── api_key / headers / cloud secrets -> span.metadata -> POST /logs3

Build LiteLLM span metadata from an_SAFE_METADATA_KEYS. _SAFE_METADATA_KEYS has a lot of keys, but I kept this because it maintains existing behaviour in case folks are using the other metadata keys for stuff.

call kwargs -> safe metadata allowlist -> span.metadata -> POST /logs3
                  └── credentials and unknown kwargs dropped

LiteLLM accepts provider credentials and transport headers directly on
instrumented calls. For example:

```python
litellm.completion(
    model="openai/example-model",
    messages=[{"role": "user", "content": "Hello"}],
    api_key=os.environ["OPENAI_API_KEY"],
    extra_headers={"Authorization": f"Bearer {token}"},
)
```

Cloud-provider credentials can also be supplied as kwargs:

```python
litellm.completion(
    model="azure/example-deployment",
    messages=[...],
    azure_ad_token=os.environ["AZURE_AD_TOKEN"],
)
```

Previously, every kwarg other than the selected input and model flowed
into span metadata and then into the logs upload:

```text
litellm.completion kwargs
├── messages --------------------------> span.input
├── model -----------------------------> span.metadata.model
└── api_key / headers / cloud secrets -> span.metadata -> POST /logs3
```

Build LiteLLM span metadata from an allowlist of known-safe request
parameters instead. Credentials, transport headers, and unknown future
kwargs now fall outside the logging boundary:

```text
call kwargs -> safe metadata allowlist -> span.metadata -> POST /logs3
                  └── credentials and unknown kwargs dropped
```

Apply the same metadata builder to completion, rerank, and transcription
payloads. Extend the cassette-backed OpenRouter regression coverage to
verify that `api_key` is absent while only displaying metadata key names
on assertion failure.

Validation:
- nox -s "test_litellm(latest)" "test_litellm(1.74.0)"
- make lint
@AbhiPrasad Abhijeet Prasad (AbhiPrasad) changed the title fix(litellm): omit credentials from span metadata fix(litellm): use allowlist for span metadata Jul 16, 2026
@AbhiPrasad
Abhijeet Prasad (AbhiPrasad) merged commit 1f6d89c into main Jul 16, 2026
82 checks passed
@AbhiPrasad
Abhijeet Prasad (AbhiPrasad) deleted the litellm-call-arg-metadata branch July 16, 2026 13:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants