From 0455cb46c5120e8cc1bce15a73ef1935e169118e Mon Sep 17 00:00:00 2001 From: derhornspieler <15236687+derhornspieler@users.noreply.github.com> Date: Sat, 29 Aug 2026 16:03:34 -0400 Subject: [PATCH] test(anthropic): expect the missing-credential error on MiniMax and Tencent messages Upstream e14f485827 makes validate_anthropic_messages_environment raise AuthenticationError when no credential resolves instead of sending the request unauthenticated. The two regression tests that prove MiniMax and Tencent never mint an Anthropic federation token now assert that raise, which a wrongly enabled federation path would still break by attaching a bearer instead. --- ...al_pass_through_messages_transformation.py | 48 +++++++++---------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/tests/test_litellm/llms/anthropic/experimental_pass_through/messages/test_anthropic_experimental_pass_through_messages_transformation.py b/tests/test_litellm/llms/anthropic/experimental_pass_through/messages/test_anthropic_experimental_pass_through_messages_transformation.py index 0db476a8997..768a2834fbe 100644 --- a/tests/test_litellm/llms/anthropic/experimental_pass_through/messages/test_anthropic_experimental_pass_through_messages_transformation.py +++ b/tests/test_litellm/llms/anthropic/experimental_pass_through/messages/test_anthropic_experimental_pass_through_messages_transformation.py @@ -41,26 +41,26 @@ def test_minimax_validate_environment_never_attaches_anthropic_wif_credential( ) -> None: """Regression test: before the fix, an Anthropic-WIF-configured proxy would mint a real Anthropic federation token inside MiniMax's inherited validate_anthropic_messages_environment - and send it as the Authorization header on the MiniMax-routed request.""" + and send it as the Authorization header on the MiniMax-routed request. With no MiniMax + credential of its own the deployment must fail closed on the missing key instead.""" monkeypatch.setenv("ANTHROPIC_FEDERATION_RULE_ID", "fdrl_prod") monkeypatch.setenv("ANTHROPIC_ORGANIZATION_ID", "org-prod-uuid") monkeypatch.delenv("ANTHROPIC_API_KEY", raising=False) monkeypatch.delenv("ANTHROPIC_AUTH_TOKEN", raising=False) + monkeypatch.delenv("MINIMAX_API_KEY", raising=False) token_file = write_token_file(tmp_path, "jwt-assertion-value") litellm_params = {"anthropic_identity_token_file": str(token_file)} - headers, _ = MinimaxMessagesConfig().validate_anthropic_messages_environment( - headers={}, - model="MiniMax-M2.1", - messages=[], - optional_params={}, - litellm_params=litellm_params, - api_key=None, - api_base="https://api.minimax.io/anthropic", - ) - - assert "authorization" not in headers - assert "x-api-key" not in headers + with pytest.raises(litellm.AuthenticationError, match="Missing Anthropic API Key"): + MinimaxMessagesConfig().validate_anthropic_messages_environment( + headers={}, + model="MiniMax-M2.1", + messages=[], + optional_params={}, + litellm_params=litellm_params, + api_key=None, + api_base="https://api.minimax.io/anthropic", + ) def test_tencent_validate_environment_never_attaches_anthropic_wif_credential( @@ -75,18 +75,16 @@ def test_tencent_validate_environment_never_attaches_anthropic_wif_credential( litellm_params = {"anthropic_identity_token_file": str(token_file)} monkeypatch.setattr(litellm, "api_key", None) - headers, _ = TencentAnthropicMessagesConfig().validate_anthropic_messages_environment( - headers={}, - model="deepseek-v4-pro", - messages=[], - optional_params={}, - litellm_params=litellm_params, - api_key=None, - api_base="https://tokenhub-intl.tencentcloudmaas.com", - ) - - assert "authorization" not in headers - assert "x-api-key" not in headers + with pytest.raises(litellm.AuthenticationError, match="Missing Anthropic API Key"): + TencentAnthropicMessagesConfig().validate_anthropic_messages_environment( + headers={}, + model="deepseek-v4-pro", + messages=[], + optional_params={}, + litellm_params=litellm_params, + api_key=None, + api_base="https://tokenhub-intl.tencentcloudmaas.com", + ) def test_wif_token_exchange_reaches_only_anthropic_not_minimax_or_tencent(