litellm/tests/unit/llms/bedrock/passthrough
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
..
guardrail_translation fix(guardrails): apply guardrail masks to Bedrock InvokeModel Claude requests and replies (#49947) 2026-11-04 23:12:50 +00: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_passthrough_transformation.py fix(bedrock): preserve native Llama streaming usage and finish reasons (#55890) 2026-12-02 18:52:08 -08:00