mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-07 08:26:10 +00:00
fix(utils): strip include_usage from stream_options for non-streaming requests
include_usage is only meaningful when streaming; OpenAI-compatible backends (e.g. vLLM) return 400 if stream_options.include_usage is sent without stream=True. Strip only that key for non-streaming requests so other keys (e.g. include_obfuscation, used by the /v1/responses bridge) survive. Fixes #29431.
This commit is contained in:
parent
f0a122d35f
commit
d792af887b
2 changed files with 237 additions and 428 deletions
|
|
@ -4115,6 +4115,20 @@ def get_optional_params(
|
|||
model=model,
|
||||
provider_config=provider_config,
|
||||
)
|
||||
# include_usage in stream_options is only meaningful for streaming requests;
|
||||
# OpenAI-compatible backends (e.g. vLLM) reject it with a 400 when stream is
|
||||
# not True. Strip just that key for non-streaming requests (other keys such as
|
||||
# include_obfuscation stay). Fixes #29431.
|
||||
if stream is not True:
|
||||
_stream_options: Final = non_default_params.get("stream_options")
|
||||
if isinstance(_stream_options, dict) and "include_usage" in _stream_options:
|
||||
_without_usage: Final = { # mutable-ok: normalized stream_options for the non-streaming request
|
||||
k: v for k, v in _stream_options.items() if k != "include_usage"
|
||||
}
|
||||
if _without_usage:
|
||||
non_default_params["stream_options"] = _without_usage
|
||||
else:
|
||||
non_default_params.pop("stream_options", None)
|
||||
optional_params = pre_process_optional_params(
|
||||
passed_params=passed_params,
|
||||
non_default_params=non_default_params,
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
Loading…
Add table
Reference in a new issue