The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix(minimax): attach MINIMAX_API_KEY on anthropic messages requests
mateo-berri74263bcb231e
diff --git a/litellm/llms/minimax/messages/transformation.py b/litellm/llms/minimax/messages/transformation.pyindex 095b6c0c4b6..d4c24c65cfa 100644--- a/litellm/llms/minimax/messages/transformation.py+++ b/litellm/llms/minimax/messages/transformation.py@@ -2,7 +2,7 @@MiniMax Anthropic transformation config - extends AnthropicConfig for MiniMax's Anthropic-compatible API"""-from typing import Final+from typing import Any, Final # noqa: TID251 # override below must mirror the legacy base signatureimport litellmfrom litellm.llms.anthropic.experimental_pass_through.messages.transformation import (@@ -49,6 +49,26 @@ class MinimaxMessagesConfig(AnthropicMessagesConfig):"""return api_base or get_secret_str("MINIMAX_API_BASE") or "https://api.minimax.io/anthropic/v1/messages"+ def validate_anthropic_messages_environment(+ self,+ headers: dict, # mutable-ok: mirrors the legacy base override signature+ model: str,+ messages: list[Any], # mutable-ok: mirrors the legacy base override signature+ optional_params: dict, # mutable-ok: mirrors the legacy base override signature+ litellm_params: dict, # mutable-ok: mirrors the legacy base override signature+ api_key: str | None = None,+ api_base: str | None = None,+ ) -> tuple[dict, str | None]: # mutable-ok: mirrors the legacy base override signature+ return super().validate_anthropic_messages_environment(+ headers=headers,+ model=model,+ messages=messages,+ optional_params=optional_params,+ litellm_params=litellm_params,+ api_key=self.get_api_key(api_key=api_key),+ api_base=api_base,+ )+def get_complete_url(self,api_base: str | None,diff --git a/tests/test_litellm/llms/minimax/messages/test_transformation.py b/tests/test_litellm/llms/minimax/messages/test_transformation.pyindex 01d32221fe5..c7435a52890 100644--- a/tests/test_litellm/llms/minimax/messages/test_transformation.py+++ b/tests/test_litellm/llms/minimax/messages/test_transformation.py@@ -142,3 +142,33 @@ if __name__ == "__main__":print("✓ Provider config manager test passed")print("\n✅ All basic tests passed!")+++def test_minimax_messages_env_key_attached(monkeypatch):+ """Regression: an env-only MINIMAX_API_KEY must be attached on /v1/messages validation"""+ monkeypatch.setenv("MINIMAX_API_KEY", "test-minimax-env-key")+ monkeypatch.delenv("ANTHROPIC_API_KEY", raising=False)+ monkeypatch.delenv("ANTHROPIC_AUTH_TOKEN", raising=False)+ config = MinimaxMessagesConfig()+ headers, _ = config.validate_anthropic_messages_environment(+ headers={},+ model="MiniMax-M2.1",+ messages=[{"role": "user", "content": "hi"}],+ optional_params={},+ litellm_params={},+ )+ assert headers["x-api-key"] == "test-minimax-env-key"+++def test_minimax_messages_explicit_key_wins_over_env(monkeypatch):+ monkeypatch.setenv("MINIMAX_API_KEY", "env-key")+ config = MinimaxMessagesConfig()+ headers, _ = config.validate_anthropic_messages_environment(+ headers={},+ model="MiniMax-M2.1",+ messages=[{"role": "user", "content": "hi"}],+ optional_params={},+ litellm_params={},+ api_key="param-key",+ )+ assert headers["x-api-key"] == "param-key"