litellm/tests/unit/llms/anthropic
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
..
batches
chat fix(anthropic): map /v1/messages fields onto OpenAI Responses equivalents or reject them (#54173) 2026-11-25 19:30:01 +00:00
files
messages fix(streaming): keep OpenRouter chunks that carry only reasoning_details (#48412) 2026-11-25 19:24:55 -08:00
pass_through refactor(anthropic): rename llms/anthropic/pass_through to llms/anthropic/messages (#48510) 2026-10-27 10:08:25 -07:00
__init__.py
anthropic_docs_refusal.py fix(anthropic): keep refusal stop_reason and stop_details on the logged response (#46104) 2026-10-14 14:42:49 -07:00
test_anthropic_common_utils.py fix(anthropic): update rate-limit gauges for streamed /v1/messages and Foundry Claude (#54373) 2026-11-25 18:36:22 -08:00
test_anthropic_count_tokens_transformation.py fix(token_counter): count an Anthropic fallback block as zero on every count route (#54006) 2026-11-24 03:32:34 -08:00
test_anthropic_files_and_batches.py
test_anthropic_output_format_filter.py fix(bedrock): use native structured output on Haiku 5.5 and Sonnet 5.5, and fix Fable 5 and Sonnet 4.6 schema 400s (#46870) 2026-10-16 20:57:23 -07:00
test_anthropic_prompt_cache_prediction.py fix(proxy): resolve admin oidc api_key references on batch cancel, fine-tuning listing, OCR, /v1/messages and cache prediction (#53678) 2026-11-23 10:11:10 -08:00
test_anthropic_prompt_cache_pricing.py
test_anthropic_reasoning_effort.py fix(anthropic): disable optional default thinking for reasoning effort none (#50541) 2026-11-07 12:51:37 -08:00
test_anthropic_schema_filter.py fix(bedrock): use native structured output on Haiku 5.5 and Sonnet 5.5, and fix Fable 5 and Sonnet 4.6 schema 400s (#46870) 2026-10-16 20:57:23 -07:00
test_anthropic_structured_output.py
test_anthropic_wif.py fix(anthropic): exchange Google identity tokens again on refresh and read oidc/ references out of ANTHROPIC_IDENTITY_TOKEN (#50583) 2026-11-07 16:48:48 -08:00
test_azure_ai_cache_pricing.py
test_cost_calculation_dict_safety.py
test_count_tokens_oauth.py fix(count_tokens): count a history that carries a compaction block (#44784) 2026-10-30 00:11:55 -07:00
test_message_sanitization.py fix(bedrock): stop the prefill 400 when the last user message is empty (#50701) 2026-11-18 03:44:11 +00:00
test_messages_http_error_retry_cases.py chore: move workspace packages under litellm (#51000) 2026-11-12 04:19:57 +00:00