litellm/tests/unit/llms/deepseek
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
..
chat fix(mcp): drop hosted MCP tool_choice under drop_params and honor drop_params in Bedrock batch rows (#53697) 2026-11-23 08:51:59 -08:00
count_tokens fix(token_counter): count an Anthropic fallback block as zero on every count route (#54006) 2026-11-24 03:32:34 -08:00
messages fix(deepseek): forward output_config.effort and thinking as sent on /v1/messages (#51317) 2026-11-24 01:36:57 +00:00
search feat(search): add DeepSeek as a /v1/search provider (#47401) 2026-10-19 20:35:04 +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_deepseek_common_utils.py fix(proxy): count tokens with the thinking, effort, and tool_choice that inference sends (#51079) 2026-11-14 02:29:16 +00:00
test_deepseek_cost_calculator.py test(llms): annotate local_model_cost_map fixtures in phase 6 tests 2026-09-20 07:50:30 +00:00