Initialize LLM client with specified provider. Args: api_key: API key for authentication provider: LLM provider (anthropic or openai) api_base: Base URL for the API (default: https://api.minimaxi.com) For MiniMax API, suffix is auto-a
(
self,
api_key: str,
provider: LLMProvider = LLMProvider.ANTHROPIC,
api_base: str = "https://api.minimaxi.com",
model: str = "MiniMax-M2.5",
retry_config: RetryConfig | None = None,
)
| 34 | MINIMAX_DOMAINS = ("api.minimax.io", "api.minimaxi.com") |
| 35 | |
| 36 | def __init__( |
| 37 | self, |
| 38 | api_key: str, |
| 39 | provider: LLMProvider = LLMProvider.ANTHROPIC, |
| 40 | api_base: str = "https://api.minimaxi.com", |
| 41 | model: str = "MiniMax-M2.5", |
| 42 | retry_config: RetryConfig | None = None, |
| 43 | ): |
| 44 | """Initialize LLM client with specified provider. |
| 45 | |
| 46 | Args: |
| 47 | api_key: API key for authentication |
| 48 | provider: LLM provider (anthropic or openai) |
| 49 | api_base: Base URL for the API (default: https://api.minimaxi.com) |
| 50 | For MiniMax API, suffix is auto-appended based on provider. |
| 51 | For third-party APIs (e.g., https://api.siliconflow.cn/v1), used as-is. |
| 52 | model: Model name to use |
| 53 | retry_config: Optional retry configuration |
| 54 | """ |
| 55 | self.provider = provider |
| 56 | self.api_key = api_key |
| 57 | self.model = model |
| 58 | self.retry_config = retry_config or RetryConfig() |
| 59 | |
| 60 | # Normalize api_base (remove trailing slash) |
| 61 | api_base = api_base.rstrip("/") |
| 62 | |
| 63 | # Check if this is a MiniMax API endpoint |
| 64 | is_minimax = any(domain in api_base for domain in self.MINIMAX_DOMAINS) |
| 65 | |
| 66 | if is_minimax: |
| 67 | # For MiniMax API, ensure correct suffix based on provider |
| 68 | # Strip any existing suffix first |
| 69 | api_base = api_base.replace("/anthropic", "").replace("/v1", "") |
| 70 | if provider == LLMProvider.ANTHROPIC: |
| 71 | full_api_base = f"{api_base}/anthropic" |
| 72 | elif provider == LLMProvider.OPENAI: |
| 73 | full_api_base = f"{api_base}/v1" |
| 74 | else: |
| 75 | raise ValueError(f"Unsupported provider: {provider}") |
| 76 | else: |
| 77 | # For third-party APIs, use api_base as-is |
| 78 | full_api_base = api_base |
| 79 | |
| 80 | self.api_base = full_api_base |
| 81 | |
| 82 | # Instantiate the appropriate client |
| 83 | self._client: LLMClientBase |
| 84 | if provider == LLMProvider.ANTHROPIC: |
| 85 | self._client = AnthropicClient( |
| 86 | api_key=api_key, |
| 87 | api_base=full_api_base, |
| 88 | model=model, |
| 89 | retry_config=retry_config, |
| 90 | ) |
| 91 | elif provider == LLMProvider.OPENAI: |
| 92 | self._client = OpenAIClient( |
| 93 | api_key=api_key, |
nothing calls this directly
no test coverage detected