litellm/tests/test_litellm/responses/litellm_completion_transformation
Mateo Wang ee6e8077ae
fix(responses): preserve reasoning_tokens through chat->responses usage translation (#32837)
* fix(responses): preserve reasoning_tokens through chat->responses usage translation

Remove the unconditional else-branch that wrote reasoning_tokens=0 whenever
completion_tokens_details.reasoning_tokens was None or absent. Also change
OutputTokensDetails.reasoning_tokens from int=0 to Optional[int]=None so that
re-instantiation without explicit reasoning_tokens no longer silently zeroes out
the field, and remove the same hardcoded zero from the mock_responses_api_response
initializer.

* test(responses): update assertions to match Optional[int] reasoning_tokens default

* fix(responses): preserve explicit reasoning_tokens=0 in usage translation

Align the reasoning_tokens guard with the is-not-None guards used for
text_tokens and image_tokens: a provider-reported zero passes through
while an absent value stays omitted.

---------

Co-authored-by: Deepanshu <deepanshu.lulla@alpha-sense.com>
2026-07-10 20:15:49 -07:00
..
test_function_call_output_normalization.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_handler.py chore: litellm oss staging 250626 (#31305) 2026-06-25 21:00:28 -07:00
test_image_generation_output.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_litellm_completion_responses.py fix(responses): preserve reasoning_tokens through chat->responses usage translation (#32837) 2026-07-10 20:15:49 -07:00
test_reasoning_content_transformation.py test: update test 2025-10-12 21:58:06 -07:00
test_session_handler.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_session_handler_with_cold_storage.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_tool_call_streaming_transformation.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_tool_output_order_preserved_for_gemini.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00