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:
Chenglun Hu 2026-08-27 06:03:06 +08:00
parent f0a122d35f
commit d792af887b
2 changed files with 237 additions and 428 deletions

View file

@ -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