litellm/tests/unit/llms/bedrock/chat
joshua-berri 079f917184
fix(bedrock): preserve native Llama streaming usage and finish reasons (#55890)
* fix(bedrock): keep native Llama stream usage and stop reason

Native Bedrock Llama invoke streams dropped prompt_token_count,
generation_token_count and stop_reason, so passthrough spend logged
0 prompt tokens and a capped stream logged "stop".

The decoder now reports the provider's running counts once a prompt
count has been seen, leaves usage unreported when the counts are
absent so estimation still applies, and maps stop_reason. The Bedrock
passthrough collector places that finish reason on the Llama choice.

Fixes #51456

* fix(bedrock): keep Llama passthrough streams coalesced and stop-only streams unchanged

Per-event Llama usage stopped the passthrough collector from folding text
chunks, so retained chunks grew with the event count. The collector now
keeps only the latest running counts beside the coalesced chunks and
attaches them when the response is built, including for streams cut
before the last event.

The decoder only signals a stop reason that differs from the default
"stop", so stop-only streams behave as before, and passes the raw
generation value through unchanged.

* test(bedrock): read optional stream chunk usage safely in the Llama sequence test

* fix(bedrock): read Llama stream fields through a typed event boundary

---------

Co-authored-by: Joshua Valluru <326636767+joshua-berri@users.noreply.github.com>
2026-12-02 18:52:08 -08:00
..
agentcore fix(streaming)!: fail a stream that ends without a finish reason (#47665) 2026-10-31 11:29:26 -07:00
chat_completions fix(bedrock): preserve native chat content cache checkpoints (#53322) (#53370) 2026-11-21 12:15:03 -08:00
invoke_transformations fix(bedrock): send pass-through calls the model id chat completions sends (#53836) 2026-11-25 18:42:28 -08:00
mantle fix(anthropic)!: send extra_body fields at the top level of the Messages request (#48373) 2026-11-20 06:52:56 -08:00
__init__.py test(unit): make every tests/unit directory a package so pytest collection is unique 2026-09-20 11:50:59 +00:00
test_bedrock_converse_handler.py fix(bedrock): send native chat and Responses calls to aws_bedrock_runtime_endpoint like Converse (#50582) 2026-11-19 16:40:23 -08:00
test_bedrock_gpt_oss.py test: move the unit half of 126 mixed legacy files into tests/unit (#45090) 2026-10-07 14:07:43 -07:00
test_converse_transformation.py fix(cost_map): accept reasoning_effort xhigh on Claude 5+ models newer than the cost map (#55880) 2026-12-03 02:32:41 +00:00
test_converse_transformation_nova_2.py fix(bedrock): drop another model's signed thinking when replaying to a non-Claude Converse target (#50073) 2026-11-06 03:15:49 -08:00
test_invoke_handler.py fix(bedrock): preserve native Llama streaming usage and finish reasons (#55890) 2026-12-02 18:52:08 -08:00
test_mistral_config.py test: migrate tests/llm_translation into unit, integration and e2e tiers (#45759) 2026-10-11 07:58:53 +00:00
test_native_output_fallback.py feat(bedrock): default to native structured output on Opus 5.5, Fable 5.1, Sonnet 5 and Haiku 5.5 (#50221) 2026-11-06 09:38:00 -08:00
test_service_tier.py fix(gateway): serve messages drop, summary and timeout settings like Python (#51236) 2026-11-25 09:26:12 +00:00
test_streaming_choice_index.py refactor: expose core private helpers under public names (#44871) 2026-10-07 00:05:27 +00:00
test_tool_result_images.py fix(bedrock): keep GPT tool-result images beside the tool result (#45579) 2026-10-09 18:02:23 -07:00
test_tool_use_ids.py fix(mistral): map tool call ids to Mistral's 9-char shape on Vertex AI and Bedrock (#53416) 2026-11-22 21:48:55 +00:00
test_writer_palmyra.py test: move tests/test_litellm/llms into tests/unit/llms (#43191) 2026-09-25 12:43:23 -07:00