Skip to content

test(integration): fence internal params out of provider bodies and denylist stream_chunk_size - #42529

Closed
devin-ai-integration[bot] wants to merge 2 commits into
mainfrom
litellm_leak_1_fence
Closed

devin-ai-integration[bot] wants to merge 2 commits into
mainfrom
litellm_leak_1_fence

Conversation

@devin-ai-integration

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

  • stream_chunk_size leaked into OpenAI, Azure, Anthropic and Bedrock Converse request bodies
  • No test fenced internal-only kwargs out of provider bodies
  • Denylisting the key alone silently broke Bedrock Converse streaming chunk size

How it solves it:

  • Add stream_chunk_size to all_litellm_params so it is stripped from provider bodies
  • Add a 24-case wire test (6 providers x stream/nonstream x sync/async) using the scripted upstream
  • Forward stream_chunk_size to Bedrock Converse through litellm_params instead of optional_params

User Flow

Before: a developer who sets stream_chunk_size on a streaming call gets a 400 back from the provider because the key ends up in the request body

  1. They call litellm.completion(model="openai/gpt-5", messages=[...], stream=True, stream_chunk_size=1024)
  2. OpenAI rejects the request with a 400 naming an unrecognized stream_chunk_size parameter (same for Anthropic and Azure)
  3. On Bedrock Converse the key lands in additionalModelRequestFields and the request fails the same way

After: the same call succeeds and the provider body only carries the fields the provider knows

  1. They call litellm.completion(model="openai/gpt-5", messages=[...], stream=True, stream_chunk_size=1024)
  2. The request goes out without stream_chunk_size in the body and streams back normally
  3. On Bedrock Converse the body is clean and the stream is read in 1024 byte chunks as requested

Relevant issues

Related to #17357 (Bedrock Converse stream_chunk_size plumbing)

Affected release

Linear ticket

Resolves LIT-8316 for PR 1

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/test_litellm/<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
  • I have received a Greptile Confidence Score of at least 4/5 before requesting a maintainer review (Greptile reviews automatically once the PR is opened; only comment @greptileai to re-request a review after pushing changes)

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

The change is a request-body fence, so the proof is a mutation run against the scripted upstream in tests/integration/_support/upstream.py, which returns 400 whenever an internal field appears in a body. Run from the repo root with LITELLM_LOCAL_MODEL_COST_MAP=True uv run --no-sync pytest. Full log at /home/ubuntu/leak1_proof.txt on the author box

Before (e0c2cbf, denylist entry removed)

Wire fence

  1. sed -i '/^ "stream_chunk_size",$/d' litellm/types/utils.py
  2. pytest tests/integration/providers/test_internal_params_wire.py -q
  3. Output: 16 failed, 8 passed, 15 warnings in 4.43s, every failure reads internal fields reached the provider body [stream_chunk_size] for openai, azure, anthropic and bedrock_converse x nonstream/stream x sync/async

Bedrock Converse plumbing

  1. Revert FORWARDED_KWARGS_KEYS in litellm/litellm_core_utils/get_litellm_params.py to AWS_CREDENTIAL_KWARGS_KEYS
  2. pytest tests/unit/llms/chat/test_converse_handler.py tests/test_litellm/litellm_core_utils/test_get_litellm_params.py -k stream_chunk_size -q
  3. Output: 2 failed, 1 passed, 55 deselected (test_completion_plumbs_stream_chunk_size_through_converse, test_get_litellm_params_forwards_stream_chunk_size_only_when_passed)

After (d6a4fb9)

Wire fence

  1. git checkout litellm/types/utils.py
  2. pytest tests/integration/providers/test_internal_params_wire.py -q
  3. Output: 24 passed, 15 warnings in 4.90s

Bedrock Converse plumbing

  1. pytest tests/unit/llms/chat/test_converse_handler.py -k stream_chunk_size -q -> 2 passed, 14 deselected
  2. pytest tests/test_litellm/litellm_core_utils/test_get_litellm_params.py -k stream_chunk_size -q -> 1 passed
  3. pytest tests/unit/llms/bedrock/chat/invoke_transformations/test_base_invoke_transformation.py tests/test_litellm/llms/bedrock/chat/test_invoke_handler.py -q -k stream_chunk_size -> 6 passed, 36 deselected
  4. make check -> check: PASS (Python lint, test-tree lint and dashboard API-type sync ran; e2e and dashboard lint skipped as out of scope)

Type

🐛 Bug Fix
✅ Test

Caveats (if any)

Low

  • Scope deviation: two litellm/ files beyond the denylist line changed
    • get_litellm_params.py forwards stream_chunk_size into litellm_params
    • converse_handler.py reads it from litellm_params instead of popping optional_params
    • Needed because the denylist strips the key before the old pop ran, so Converse streaming lost the feature
  • Test lives in tests/integration/providers/ though it needs no proxy, Postgres or Redis
    • tests/integration/README.md says such cases belong in the sdk shard
    • Placement follows the parent spec; move to tests/integration/sdk/ if preferred
  • bedrock_invoke and gemini cases are a wire fence only, not a plumbing test
    • Bedrock Invoke already pops stream_chunk_size and drops it before make_call / make_sync_call
    • Honouring it needs litellm_params passed into the custom stream wrapper hooks (base plus seven overrides), left for a later PR in this stack
  • Anthropic and Bedrock Converse nest extra_body keys as {"extra_body": {...}} in the body
    • The test records current behaviour with a TODO rather than asserting it is correct
  • ruff format --check flags pre-existing lines in upstream.py and test_get_litellm_params.py
    • Outside the lint gate, informational only

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

Link to Devin session: https://app.devin.ai/sessions/748b43f48ad746409070956e132a8fd9
Open in Devin Desktop: https://app.devin.ai/desktop/session/748b43f48ad746409070956e132a8fd9?variant=devin
Requested by: @shreshth-berri

… denylist does not break converse streaming

Adding stream_chunk_size to all_litellm_params made get_non_default_completion_params strip it from optional_params, so converse_handler always popped None. Forward it through get_litellm_params' FORWARDED_KWARGS_KEYS and read it from litellm_params instead
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

🔍 Devin Review: 1 flag

Not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)

Devin Review

@CLAassistant

CLAassistant commented Oct 24, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@mateo-berri

Copy link
Copy Markdown
Contributor

Main already keeps stream_chunk_size out of provider request bodies and keeps Bedrock streaming working since #42664, so closing this. Reopen if something is missing

@mateo-berri mateo-berri closed this Nov 9, 2026
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.

3 participants