litellm/tests/unit/text_completions
Charlie Freeman f6962c2ee8
fix(streaming): keep OpenRouter chunks that carry only reasoning_details (#48412)
* fix(streaming): preserve reasoning_details chunks in stream wrapper and proxy serializer (#48401)

* test(streaming): cover OpenRouter chunks that carry only reasoning_details end to end

Replace the predicate-level test with a stream test in the mapped test file. It feeds
OpenRouter SSE frames through the OpenRouter chunk parser and CustomStreamWrapper, sync
and async, and checks that the signature and encrypted reasoning_details pieces reach the
caller

* fix(anthropic): keep OpenRouter reasoning_details signatures in /v1/messages streams

Keeping reasoning_details-only chunks in the stream let them reach the
/v1/messages adapter, which opened an empty text block before tool calls
and still sent an empty signature_delta

The adapter now reads the signature from reasoning_details into the open
thinking block, and drops reasoning_details-only chunks that carry nothing
it can render, such as Gemini's encrypted reasoning

* fix(anthropic): split bundled reasoning_details signatures from text in /v1/messages streams

A chunk that carries a reasoning_details signature next to answer text or thinking text now splits into separate pieces, so the text block keeps its text and the signature stays in its thinking block

* fix(anthropic): keep /v1/messages streams unchanged by OpenRouter reasoning_details pieces

/v1/messages no longer turns a reasoning_details signature into a signature_delta. The proxy replays thinking blocks to OpenRouter as thinking_blocks, which OpenRouter ignores, so a streamed signature gave no replay benefit and two signed blocks could merge under one signature

A frame that holds only reasoning_details /v1/messages cannot show is skipped, so the stream wrapper fix opens no empty block before a tool call

* fix(streaming): count reasoning_details as sent output for fallback and /v1/completions

A stream that already sent a reasoning_details piece now counts as started for
mid-stream fallback and continuation, the same as reasoning_content, so another
deployment's answer is never spliced in after it. /v1/completions frames carry
the reasoning_details piece the same way they carry reasoning_content, instead
of turning it into an empty text frame.

* fix(anthropic): skip a reasoning_details-only /v1/messages frame only when it has one choice

---------

Co-authored-by: Charlie Freeman <243496084+cf3901646@users.noreply.github.com>
Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com>
2026-11-25 19:24:55 -08:00
..
__init__.py fix(completions): omit stream usage unless requested (#47953) (#48052) 2026-10-23 19:36:20 +00:00
test_streaming_iterator.py fix(streaming): keep OpenRouter chunks that carry only reasoning_details (#48412) 2026-11-25 19:24:55 -08:00