[Rust Frontend] Report reasoning tokens in chat completion usage (#54883)

Signed-off-by: Bugen Zhao <i@bugenzhao.com>
This commit is contained in:
Bugen Zhao
2026-09-03 16:47:24 -07:00
committed by GitHub
parent 579aef4e8d
commit d6bce42983
15 changed files with 735 additions and 88 deletions
@@ -5,7 +5,7 @@
Verifies that reasoning content is included by default and suppressed
when ``include_reasoning=False``, for both streaming and non-streaming
Chat Completions.
Chat Completions, while reasoning tokens remain represented in usage.
"""
import openai
@@ -77,6 +77,22 @@ async def test_include_reasoning_false_non_streaming(client: openai.AsyncOpenAI)
assert msg.content, "Expected content in response even without reasoning"
@pytest.mark.asyncio
async def test_reasoning_tokens_in_usage(client: openai.AsyncOpenAI):
"""Hidden reasoning still contributes to terminal usage details."""
response = await client.chat.completions.create(
model=MODEL_NAME,
messages=MESSAGES,
max_tokens=64,
extra_body={"include_reasoning": False},
)
assert response.usage is not None
details = response.usage.completion_tokens_details
assert details is not None
assert details.reasoning_tokens > 0
@pytest.mark.asyncio
async def test_include_reasoning_true_streaming(client: openai.AsyncOpenAI):
"""Default: reasoning deltas appear in streaming response."""
@@ -736,7 +736,8 @@ async def test_chat_per_request_metrics_follow_server_flag():
request_metadata=RequestResponseMetadata(request_id="chatcmpl-test-id"),
)
assert disabled_response.metrics is None
assert disabled_response.usage.completion_tokens_details is None
details = disabled_response.usage.completion_tokens_details
assert details is None or details.reasoning_tokens == 0
enabled_serving = _build_minimal_metrics_serving_chat(
enable_per_request_metrics=True