mirror of
https://github.com/BerriAI/litellm.git
synced 2026-08-28 05:25:59 +00:00
fix(minimax): attach MINIMAX_API_KEY on anthropic messages requests
This commit is contained in:
parent
ace28fd97a
commit
74263bcb23
2 changed files with 51 additions and 1 deletions
|
|
@ -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 signature
|
||||
|
||||
import litellm
|
||||
from 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,
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue