litellm/tests/unit/llms/bedrock
paveln83 73bbc8caab
fix(anthropic): drop unsigned thinking blocks before /v1/messages reaches Claude (#51793)
* fix(anthropic): drop unsigned thinking blocks before /v1/messages reaches Claude

A thought another provider served (Gemini through the /v1/messages adapter) comes back from Claude Code with an empty signature. Anthropic, Bedrock, Vertex, Azure AI, Databricks and Bedrock Mantle Claude reject it, so the first attempt 400s and the retry turns thinking off. Drop unsigned and encrypted thinking before the first attempt for backends that check Anthropic signatures, and keep the encrypted-only strip for third-party Anthropic-compatible APIs that replay their own unsigned thinking.

* fix(anthropic): strip unsigned thinking only when the model is Claude

The strip keyed on provider anthropic, so Kimi and other models behind an
Anthropic-compatible api_base lost their own unsigned thinking. Every host
now strips only for a Claude model, which also covers Claude on GitHub
Copilot, and a Bedrock ARN still counts as Claude. Types the new tests.

* fix(anthropic): drop unsigned thinking only where the host checks Claude signatures

Anthropic-compatible hosts such as DeepSeek accept Gemini's unsigned thought and need
it passed back on tool turns, so a Claude model name alone no longer triggers the strip
under anthropic/. Python and Rust now also require an anthropic.com or Azure AI Foundry
host there, while fixed-host providers keep the name check.

Bedrock Converse drops the unsigned thought instead of sending it as reply text, and
count_tokens drops it for Claude targets so it accepts the history /v1/messages accepts.
The Bedrock ARN override is removed, so Bedrock uses the shared name check.

* fix(messages): drop unsigned thinking from Vertex AI and Bedrock count_tokens and test the Rust handler strip

* fix(anthropic): keep unsigned thinking for providers and hosts that do not check Claude signatures

DeepSeek takes deepseek/claude-* names and Anthropic-compatible hosts take
anthropic/claude-* names, and both want the thought back. The strip and
count_tokens now share one gate, a Claude model on a provider or host that
checks Claude signatures. The Bedrock count judges the deployment model,
and a message that is not an object goes to the provider untouched

* fix(bedrock): drop unsigned thinking before Claude Platform on AWS whatever host it names

Claude Platform on AWS inherited the anthropic host check, so an explicit api_base or an ANTHROPIC_BASE_URL that points elsewhere kept another model's unsigned thought and Claude rejected it. It now uses the Bedrock rule, which checks only the model name

Also adds a count_tokens handler test that posts the same thinking history Vertex AI /v1/messages sends

* fix(messages): drop unsigned thinking on azure_ai's rust messages route

Main now serves azure_ai /v1/messages on Rust only, so the Python strip no
longer runs there. The azure_ai Rust config drops thinking blocks with an
empty, missing or non-string signature for a Claude deployment, in parsed
and unparsed messages, before the request goes to Azure AI Foundry.

* fix(messages): drop unsigned thinking on bedrock invoke's rust messages route

* test(messages): use rstest for the new bedrock invoke thinking tests

* fix(messages): drop provider_specific_fields from count_tokens messages

litellm puts provider_specific_fields on a returned content block, such as Gemini's thought signature on a tool_use. /v1/messages already drops it before Claude, but count_tokens sent it on, so Anthropic, Bedrock and Vertex AI answered 400 on a history with a Gemini tool turn

* fix(messages): keep stripping unsigned thinking for Claude behind any gateway

Strip unsigned thinking for every Claude name, as main does, and keep it only for
the providers and hosts known to need it back (DeepSeek, MiniMax, Tencent, z.ai,
BigModel). An anthropic/ deployment behind a custom gateway or forwarder now
strips again, so it makes one call with thinking on instead of a 400 and a retry
that drops all thinking

* test(messages): pass typed litellm params to the DeepSeek unsigned thinking test

Main's DeepSeek messages transform now reads drop_params off litellm_params, so the
plain dict the test passed failed on the merge with main

---------

Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com>
2026-11-24 05:30:55 +00:00
..
batches fix(bedrock): send batch jobs to a configured control-plane endpoint (#47260) 2026-10-20 12:30:16 -07: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(anthropic): drop unsigned thinking blocks before /v1/messages reaches Claude (#51793) 2026-11-24 05:30:55 +00:00
embed fix(bedrock): accept the OpenAI SDK default encoding_format on Nova embeddings (#53755) 2026-11-23 10:00:50 -08:00
files 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
image test: move 81 legacy live tests in pass-through, spend, batches, audio, search, guardrails, image and ocr dirs offline (#45288) 2026-10-08 02:38:12 -07:00
image_edit refactor(rust_bridge): route every Rust-to-Python call through host modules (#50822) 2026-11-11 01:57:54 +00:00
image_generation test: move the unit half of 126 mixed legacy files into tests/unit (#45090) 2026-10-07 14:07:43 -07:00
invoke_agent fix(sagemaker,bedrock): answer 502 when a 200 AWS event stream decodes to no events or ends mid-frame (#53482) 2026-11-22 23:59:32 +00:00
messages fix(bedrock,databricks): forward the server-side-fallback beta and drop it under drop_params where the model lacks it (#53857) 2026-11-24 03:09:16 +00:00
passthrough feat(bedrock): derive STS session tags and session name from caller identity (#52978) 2026-11-19 17:11:09 -08:00
realtime fix(bedrock): treat an empty api_base or runtime endpoint as unset (#51244) 2026-11-24 00:36:07 +00:00
rerank refactor(types): replace Any with proven types in 137 files (#44478) 2026-10-05 11:01:45 -07:00
responses fix(bedrock): send native chat and Responses calls to aws_bedrock_runtime_endpoint like Converse (#50582) 2026-11-19 16:40:23 -08:00
search fix(streaming): keep merged think tags balanced and split SSE lines only on CR/LF (#48755) 2026-10-28 17:00:29 -07:00
vector_stores fix(bedrock): map OpenAI vector store search filters to AWS RetrievalFilter (#51291) 2026-11-14 13:39:43 -05: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
event_loop_probe.py test(bedrock): detect Vault reads on the event-loop thread (#47597) 2026-10-20 10:45:04 -07:00
slow_upstream.py fix(router)!: bound fake-streamed calls by the request timeout, not stream_timeout (#47162) 2026-10-17 22:08:02 +00:00
test_anthropic_beta_support.py refactor(llms): rename model-version transformation files to family names (#48509) 2026-10-26 18:53:16 -07:00
test_base_aws_llm.py fix(bedrock): treat an empty api_base or runtime endpoint as unset (#51244) 2026-11-24 00:36:07 +00:00
test_bedrock_common_utils.py feat(cost-map): turn on Bedrock native structured output for GovCloud Claude rows (#53175) 2026-11-21 00:00:49 +00:00
test_bedrock_model_listing.py feat(bedrock): derive STS session tags and session name from caller identity (#52978) 2026-11-19 17:11:09 -08:00
test_bedrock_ssl_verify.py test: move tests/test_litellm/llms into tests/unit/llms (#43191) 2026-09-25 12:43:23 -07:00
test_claude_platform_provider.py fix(anthropic): drop unsigned thinking blocks before /v1/messages reaches Claude (#51793) 2026-11-24 05:30:55 +00:00
test_converse_context_management.py test: move tests/test_litellm/llms into tests/unit/llms (#43191) 2026-09-25 12:43:23 -07:00
test_cost_calculation.py feat(cost): price Claude token calls, budget holds and auth price checks in Rust (#52484) 2026-11-23 22:00:28 +00:00
test_cross_region_inference_profile_mapping.py feat(bedrock): serve gpt-5.6+ chat completions natively by default, with chat_completions/ opt-in for gpt-oss and grok (#44307) 2026-10-02 19:55:54 -07:00
test_guardrail_attachments.py fix(guardrails): scan or refuse attachments in the bedrock guardrail (#43383) 2026-10-10 16:48:37 -07:00
test_mantle.py feat(messages): serve bedrock mantle messages on rust only (#52328) 2026-11-18 17:36:06 -08:00
test_nova_imported_models.py fix(bedrock): route a Bedrock model id with no Invoke provider to Converse (#43290) 2026-10-30 06:27:59 -07:00
test_request_metadata.py feat(messages): serve bedrock claude_platform messages on rust only (#52681) 2026-11-19 14:34:02 -08:00
test_session_identity.py feat(bedrock): derive STS session tags and session name from caller identity (#52978) 2026-11-19 17:11:09 -08:00
test_web_identity_session_policy.py feat(s3-log): replace the python s3_v2 logger with a rust callback (#51539) 2026-11-14 23:03:58 +00:00