From 38cf66df012dbf225b115bc52b1d94e8b6eb901c Mon Sep 17 00:00:00 2001 From: Sameer Kankute Date: Tue, 23 Dec 2025 17:07:21 +0530 Subject: [PATCH] Add: chat completion transformation for minmax --- litellm/llms/minimax/chat/__init__.py | 4 + litellm/llms/minimax/chat/transformation.py | 83 +++++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 litellm/llms/minimax/chat/__init__.py create mode 100644 litellm/llms/minimax/chat/transformation.py diff --git a/litellm/llms/minimax/chat/__init__.py b/litellm/llms/minimax/chat/__init__.py new file mode 100644 index 0000000000..45bcfd03b4 --- /dev/null +++ b/litellm/llms/minimax/chat/__init__.py @@ -0,0 +1,4 @@ +""" +MiniMax OpenAI-compatible chat API +""" + diff --git a/litellm/llms/minimax/chat/transformation.py b/litellm/llms/minimax/chat/transformation.py new file mode 100644 index 0000000000..ed80ff8aed --- /dev/null +++ b/litellm/llms/minimax/chat/transformation.py @@ -0,0 +1,83 @@ +""" +MiniMax OpenAI transformation config - extends OpenAI chat config for MiniMax's OpenAI-compatible API +""" +from typing import Optional + +import litellm +from litellm.llms.openai.chat.gpt_transformation import OpenAIGPTConfig +from litellm.secret_managers.main import get_secret_str + + +class MinimaxChatConfig(OpenAIGPTConfig): + """ + MiniMax OpenAI configuration that extends OpenAIGPTConfig. + MiniMax provides an OpenAI-compatible API at: + - International: https://api.minimax.io/v1 + - China: https://api.minimaxi.com/v1 + + Supported models: + - MiniMax-M2.1 + - MiniMax-M2.1-lightning + - MiniMax-M2 + """ + + @staticmethod + def get_api_key(api_key: Optional[str] = None) -> Optional[str]: + """ + Get MiniMax API key from environment or parameters. + """ + return ( + api_key + or get_secret_str("MINIMAX_API_KEY") + or litellm.api_key + ) + + @staticmethod + def get_api_base( + api_base: Optional[str] = None, + ) -> str: + """ + Get MiniMax API base URL. + Defaults to international endpoint: https://api.minimax.io/v1 + For China, set to: https://api.minimaxi.com/v1 + """ + return ( + api_base + or get_secret_str("MINIMAX_API_BASE") + or "https://api.minimax.io/v1" + ) + + def get_complete_url( + self, + api_base: Optional[str], + api_key: Optional[str], + model: str, + optional_params: dict, + litellm_params: dict, + stream: Optional[bool] = None, + ) -> str: + """ + Get the complete URL for MiniMax OpenAI API. + Override to ensure we use MiniMax's endpoint. + """ + # Get the base URL (either provided or default MiniMax endpoint) + base_url = self.get_api_base(api_base=api_base) + + # Ensure it ends with /chat/completions + if base_url.endswith("/chat/completions"): + return base_url + elif base_url.endswith("/v1"): + return f"{base_url}/chat/completions" + elif base_url.endswith("/"): + return f"{base_url}v1/chat/completions" + else: + return f"{base_url}/v1/chat/completions" + + def get_supported_openai_params(self, model: str) -> list: + """ + Get supported OpenAI parameters for MiniMax. + Adds reasoning_split to the list of supported params. + """ + base_params = super().get_supported_openai_params(model=model) + return base_params + ["reasoning_split"] +