Skip to content

test(params): fence proxy metadata keys out of provider bodies - #43368

Open
shrey-berri wants to merge 1 commit into
mainfrom
litellm_fence_proxy_metadata
Open

shrey-berri wants to merge 1 commit into
mainfrom
litellm_fence_proxy_metadata

Conversation

@shrey-berri

@shrey-berri shrey-berri commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

This adds one more check to the test that makes sure LiteLLM's internal settings never end up in the request we send to a provider. The test now also passes the kind of key the proxy puts in metadata and fails if that key reaches any of the six providers we cover. It also writes down the naming rule for internal settings so new code keeps them out of provider requests by default

Details

TLDR

The last two items of the internal-params depth item, after #43221 and #43222

Problem this solves:

  • The fence test never checked proxy keys inside metadata
  • The _litellm_* naming rule was not written down anywhere

How it solves it:

  • Fence test sends metadata={"user_api_key_hash": "h"} to all 6 providers
  • It asserts user_api_key_hash never appears in any request body
  • AGENTS.md now states the _litellm_* rule and bans internal state in metadata

Linear ticket

Resolves LIT-8316

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. uv run pytest tests/unit/<your_test_file>.py -v. Leave the suites (make test-unit-*, make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or more
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • Every automated review on my PR's latest commit has finished, and I have addressed or replied to each of its findings before requesting a maintainer review

Delays in PR merge?

If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).

Screenshots / Proof of Fix

This PR only touches a test and AGENTS.md, so nothing a user sees changes and there is no live proxy run to show. The thing worth proving is that the new line catches a real leak, so each side runs the test twice. The first run uses default settings, which is all CI ever runs and passes on both sides. The second run deliberately breaks LiteLLM by turning on litellm.enable_preview_features, which makes it copy metadata into the OpenAI request body. A useful assertion has to go red there

Both runs use PYTHONPATH=tests:. from the repo root

Before (f3d53a9)

Default settings

  1. pytest tests/integration/providers/test_internal_params_wire.py -q
24 passed in 4.93s

Metadata forwarding turned on by hand

  1. python -c "import litellm, pytest, sys; litellm.enable_preview_features = True; sys.exit(pytest.main(['tests/integration/providers/test_internal_params_wire.py', '-q']))"
24 passed in 2.39s

The old test stays green even though OpenAI now receives user_api_key_hash

After (91c3bf4)

Default settings

  1. pytest tests/integration/providers/test_internal_params_wire.py -q
24 passed in 4.35s

Metadata forwarding turned on by hand

  1. python -c "import litellm, pytest, sys; litellm.enable_preview_features = True; sys.exit(pytest.main(['tests/integration/providers/test_internal_params_wire.py', '-q']))"
FAILED tests/integration/providers/test_internal_params_wire.py::test_internal_params_never_reach_provider_body[False-False-openai]
FAILED tests/integration/providers/test_internal_params_wire.py::test_internal_params_never_reach_provider_body[False-True-openai]
FAILED tests/integration/providers/test_internal_params_wire.py::test_internal_params_never_reach_provider_body[True-False-openai]
FAILED tests/integration/providers/test_internal_params_wire.py::test_internal_params_never_reach_provider_body[True-True-openai]
4 failed, 20 passed in 2.18s

The new assertion catches the broken build on every OpenAI case

Type

✅ Test
📖 Documentation

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

@shrey-berri
shrey-berri requested a review from a team September 26, 2026 23:20
@greptile-apps

greptile-apps Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Low risk] Documents internal parameter naming and adds test coverage.

The PR appears safe to merge.

Summary

This PR documents the internal-kwarg naming convention and extends the provider wire test to check that user_api_key_hash inside request metadata does not appear in provider bodies.

  • The assertion covers the existing six-provider, sync/async, and streaming/non-streaming matrix.
  • No production behavior changes.

Reviews (1) · Last reviewed commit: "test(params): fence proxy metadata keys ..."

@codecov

codecov Bot commented Sep 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

The fence test now sends metadata={"user_api_key_hash": "h"} and asserts the key reaches none of the six providers. AGENTS.md now states the _litellm_* naming rule for internal kwargs and that internal state never goes into metadata
@shrey-berri
shrey-berri force-pushed the litellm_fence_proxy_metadata branch from f3cf654 to 91c3bf4 Compare October 23, 2026 22:17

This branch has not been deployed

No deployments
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.

1 participant