Repository navigation
fix(models): merge http_options.extra_body into the constructor's extra_body in LiteLlm - #8506
Open
RobertWei3 wants to merge 1 commit into
Open
RobertWei3 wants to merge 1 commit into
RobertWei3 wants to merge 1 commit into
Conversation
…ra_body in LiteLlm A per-request http_options.extra_body used to replace the extra_body passed to the LiteLlm constructor, silently dropping fields such as LiteLLM proxy metadata. Merge the two the same way extra_headers is merged: request keys win, and the constructor's dict is not mutated.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Please ensure you have read the contribution guide before creating a pull request.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
http_options.extra_bodyreplaces the constructor'sextra_bodyinstead of merging with it #8505Problem:
When a
LiteLlmmodel is created withextra_body=...and a request also setshttp_options.extra_body(directly, throughRunConfig(http_options=...), or in abefore_model_callback), the request's dict replaces the constructor's dict. Constructor fields such as LiteLLM proxymetadata/tags, Qwenenable_thinking, vLLMchat_template_kwargsor DeepSeekthinkingare silently dropped for that request.Solution:
Merge the request-level
extra_bodyinto the constructor'sextra_body, the same wayhttp_opts.headersis merged intoextra_headersa few lines above:Testing Plan
Unit Tests:
Added
test_generate_content_async_merges_http_options_extra_body_with_constructorintests/unittests/models/test_litellm.py. It checks that constructor keys are kept, request keys win on conflict, and the constructor's dict is not mutated. The test fails onmainand passes with this change.Manual End-to-End (E2E) Tests:
Ran the reproduction script from #8505, which sends a real request through
LiteLlm-> litellm -> a local fake OpenAI-compatible server and prints the request body the server received. The constructor setsextra_body={"metadata": {"team": "a"}}and the request setshttp_options.extra_body={"priority": "high"}.Before (
main):After (this PR):
Checklist
Additional context
PR #8331 changes the
num_retrieslines just above this block. The two changes do not overlap, and I checked that this patch still applies cleanly on top of #8331.pyinkandisortpass on both changed files.