From bc2c0c86efb28e77677a3cfb8687e976914a313a Mon Sep 17 00:00:00 2001 From: Csrayz Date: Fri, 13 Mar 2026 11:33:04 +0800 Subject: [PATCH] [Frontend] Fix usage incorrectly returned with empty stream_options` (#36379) Signed-off-by: Csrayz <33659823+Csrayz@users.noreply.github.com> --- tests/v1/entrypoints/openai/test_completion.py | 12 ++++++++++++ vllm/entrypoints/openai/engine/protocol.py | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/v1/entrypoints/openai/test_completion.py b/tests/v1/entrypoints/openai/test_completion.py index ddab006d0d..7faf25220b 100644 --- a/tests/v1/entrypoints/openai/test_completion.py +++ b/tests/v1/entrypoints/openai/test_completion.py @@ -457,6 +457,18 @@ async def test_completion_stream_options(client: openai.AsyncOpenAI, model_name: ) assert final_chunk.choices == [] + # Test stream=True, stream_options={} + stream = await client.completions.create( + model=model_name, + prompt=prompt, + max_tokens=5, + temperature=0.0, + stream=True, + stream_options={}, + ) + async for chunk in stream: + assert chunk.usage is None + # Test stream=False, stream_options= # {"include_usage": None} with pytest.raises(BadRequestError): diff --git a/vllm/entrypoints/openai/engine/protocol.py b/vllm/entrypoints/openai/engine/protocol.py index ced89691f7..02dad6c1fc 100644 --- a/vllm/entrypoints/openai/engine/protocol.py +++ b/vllm/entrypoints/openai/engine/protocol.py @@ -159,7 +159,7 @@ AnyResponseFormat: TypeAlias = ( class StreamOptions(OpenAIBaseModel): - include_usage: bool | None = True + include_usage: bool | None = False continuous_usage_stats: bool | None = False