litellm/tests/unit/completion_extras
izzybn 55d4288821
fix(token_counter): count an Anthropic fallback block as zero on every count route (#54006)
* fix(token_counter): count an Anthropic fallback block as zero on every count route

A client replays the fallback block from a server-side fallback in its history. The API does not render it, so it costs zero tokens, but /utils/token_counter answered 500 and /v1/messages/count_tokens answered 400 on it. The local counter now skips the block, the conversion guard accepts it, and provider counts send the fallback beta those APIs need to accept it.

* fix(deepseek): count a history that echoes a fallback block the same as the history without it

* fix(prompt_templates): leave an echoed fallback block's text out of a flattened content list

* fix(token_counter): skip only fallback blocks when flattening and strip them from Bedrock counts

Restore the old content-list flatten so a malformed part still raises instead of losing its text,
skip a block only when its type is a string naming an unrendered block, and send Bedrock's count
APIs the history without the fallback block, which Bedrock rejects

* fix(token_counter): count the text a fallback block carries like a text block

Restore the flattened content list to main's behavior, so any text a caller
puts on a fallback block is sent and scanned exactly as before. The local
token counter now counts that text like a text block, so what is counted
matches what is sent, while a real fallback block with no text still counts
as zero. The chat to Responses bridge skips a fallback block that carries no
text instead of sending its repr as output text.

* fix(token_counter): count a fallback block's text the way each route sends it

DeepSeek counts send the text a fallback block carries as a text block, Bedrock counts keep a response tool call object they used to send, and the conversion guard still refuses a fallback block that carries text, since both conversions drop it

---------

Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com>
2026-11-24 03:32:34 -08:00
..
litellm_responses_transformation fix(token_counter): count an Anthropic fallback block as zero on every count route (#54006) 2026-11-24 03:32:34 -08:00
__init__.py test: add __init__.py to migrated tests/unit packages 2026-09-20 11:53:49 +00:00
test_litellm_responses_transformation_transformation.py test: migrate wave 1 phase 1 legacy tests to tests/unit 2026-09-20 09:17:57 +00:00
test_responses_bridge_provider_propagation.py fix(responses): honor request cache controls on chat completions bridged to the Responses API (#44676) 2026-10-05 17:52:44 -07:00