From 9bb099736be2c7126edb2f93c493f5fd8356e8e9 Mon Sep 17 00:00:00 2001 From: Liu Yuan Date: Fri, 13 Feb 2026 09:32:12 +0800 Subject: [PATCH] feat: add minimax-api-key-cn option for China API endpoint MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add 'minimax-api-key-cn' auth choice for Chinese users - Reuse existing --minimax-api-key CLI option - Use MINIMAX_CN_API_BASE_URL (https://api.minimaxi.com/anthropic) - Similar to how moonshot supports moonshot-api-key-cn Tested: build ✅, check ✅, test ✅ --- src/commands/auth-choice.apply.minimax.ts | 45 +++++++++++++++++++++ src/commands/onboard-auth.config-minimax.ts | 42 ++++++++++++++++--- src/commands/onboard-auth.models.ts | 1 + src/commands/onboard-auth.ts | 3 ++ src/commands/onboard-types.ts | 1 + 5 files changed, 87 insertions(+), 5 deletions(-) diff --git a/src/commands/auth-choice.apply.minimax.ts b/src/commands/auth-choice.apply.minimax.ts index b07f6b53879..6282b482105 100644 --- a/src/commands/auth-choice.apply.minimax.ts +++ b/src/commands/auth-choice.apply.minimax.ts @@ -10,7 +10,9 @@ import { applyDefaultModelChoice } from "./auth-choice.default-model.js"; import { applyAuthProfileConfig, applyMinimaxApiConfig, + applyMinimaxApiConfigCn, applyMinimaxApiProviderConfig, + applyMinimaxApiProviderConfigCn, applyMinimaxConfig, applyMinimaxProviderConfig, setMinimaxApiKey, @@ -97,6 +99,49 @@ export async function applyAuthChoiceMiniMax( return { config: nextConfig, agentModelOverride }; } + if (params.authChoice === "minimax-api-key-cn") { + const modelId = "MiniMax-M2.5"; + let hasCredential = false; + const envKey = resolveEnvApiKey("minimax"); + if (envKey) { + const useExisting = await params.prompter.confirm({ + message: `Use existing MINIMAX_API_KEY (${envKey.source}, ${formatApiKeyPreview(envKey.apiKey)})?`, + initialValue: true, + }); + if (useExisting) { + await setMinimaxApiKey(envKey.apiKey, params.agentDir); + hasCredential = true; + } + } + if (!hasCredential) { + const key = await params.prompter.text({ + message: "Enter MiniMax China API key", + validate: validateApiKeyInput, + }); + await setMinimaxApiKey(normalizeApiKeyInput(String(key)), params.agentDir); + } + nextConfig = applyAuthProfileConfig(nextConfig, { + profileId: "minimax:default", + provider: "minimax", + mode: "api_key", + }); + { + const modelRef = `minimax/${modelId}`; + const applied = await applyDefaultModelChoice({ + config: nextConfig, + setDefaultModel: params.setDefaultModel, + defaultModel: modelRef, + applyDefaultConfig: applyMinimaxApiConfigCn, + applyProviderConfig: applyMinimaxApiProviderConfigCn, + noteAgentModel, + prompter: params.prompter, + }); + nextConfig = applied.config; + agentModelOverride = applied.agentModelOverride ?? agentModelOverride; + } + return { config: nextConfig, agentModelOverride }; + } + if (params.authChoice === "minimax") { const applied = await applyDefaultModelChoice({ config: nextConfig, diff --git a/src/commands/onboard-auth.config-minimax.ts b/src/commands/onboard-auth.config-minimax.ts index 3b8bd11b324..b92eb6360e3 100644 --- a/src/commands/onboard-auth.config-minimax.ts +++ b/src/commands/onboard-auth.config-minimax.ts @@ -6,6 +6,7 @@ import { DEFAULT_MINIMAX_CONTEXT_WINDOW, DEFAULT_MINIMAX_MAX_TOKENS, MINIMAX_API_BASE_URL, + MINIMAX_CN_API_BASE_URL, MINIMAX_HOSTED_COST, MINIMAX_HOSTED_MODEL_ID, MINIMAX_HOSTED_MODEL_REF, @@ -148,7 +149,37 @@ export function applyMinimaxHostedConfig( // MiniMax Anthropic-compatible API (platform.minimax.io/anthropic) export function applyMinimaxApiProviderConfig( cfg: OpenClawConfig, - modelId: string = "MiniMax-M2.1", + modelId: string = "MiniMax-M2.5", +): OpenClawConfig { + return applyMinimaxApiProviderConfigWithBaseUrl(cfg, modelId, MINIMAX_API_BASE_URL); +} + +export function applyMinimaxApiConfig( + cfg: OpenClawConfig, + modelId: string = "MiniMax-M2.5", +): OpenClawConfig { + return applyMinimaxApiConfigWithBaseUrl(cfg, modelId, MINIMAX_API_BASE_URL); +} + +// MiniMax China API (api.minimaxi.com) +export function applyMinimaxApiProviderConfigCn( + cfg: OpenClawConfig, + modelId: string = "MiniMax-M2.5", +): OpenClawConfig { + return applyMinimaxApiProviderConfigWithBaseUrl(cfg, modelId, MINIMAX_CN_API_BASE_URL); +} + +export function applyMinimaxApiConfigCn( + cfg: OpenClawConfig, + modelId: string = "MiniMax-M2.5", +): OpenClawConfig { + return applyMinimaxApiConfigWithBaseUrl(cfg, modelId, MINIMAX_CN_API_BASE_URL); +} + +function applyMinimaxApiProviderConfigWithBaseUrl( + cfg: OpenClawConfig, + modelId: string, + baseUrl: string, ): OpenClawConfig { const providers = { ...cfg.models?.providers }; const existingProvider = providers.minimax; @@ -164,7 +195,7 @@ export function applyMinimaxApiProviderConfig( const normalizedApiKey = resolvedApiKey?.trim() === "minimax" ? "" : resolvedApiKey; providers.minimax = { ...existingProviderRest, - baseUrl: MINIMAX_API_BASE_URL, + baseUrl, api: "anthropic-messages", ...(normalizedApiKey?.trim() ? { apiKey: normalizedApiKey } : {}), models: mergedModels.length > 0 ? mergedModels : [apiModel], @@ -189,11 +220,12 @@ export function applyMinimaxApiProviderConfig( }; } -export function applyMinimaxApiConfig( +function applyMinimaxApiConfigWithBaseUrl( cfg: OpenClawConfig, - modelId: string = "MiniMax-M2.1", + modelId: string, + baseUrl: string, ): OpenClawConfig { - const next = applyMinimaxApiProviderConfig(cfg, modelId); + const next = applyMinimaxApiProviderConfigWithBaseUrl(cfg, modelId, baseUrl); return { ...next, agents: { diff --git a/src/commands/onboard-auth.models.ts b/src/commands/onboard-auth.models.ts index 71af8f69077..26c6107b1c1 100644 --- a/src/commands/onboard-auth.models.ts +++ b/src/commands/onboard-auth.models.ts @@ -3,6 +3,7 @@ import { QIANFAN_BASE_URL, QIANFAN_DEFAULT_MODEL_ID } from "../agents/models-con export const DEFAULT_MINIMAX_BASE_URL = "https://api.minimax.io/v1"; export const MINIMAX_API_BASE_URL = "https://api.minimax.io/anthropic"; +export const MINIMAX_CN_API_BASE_URL = "https://api.minimaxi.com/anthropic"; export const MINIMAX_HOSTED_MODEL_ID = "MiniMax-M2.1"; export const MINIMAX_HOSTED_MODEL_REF = `minimax/${MINIMAX_HOSTED_MODEL_ID}`; export const DEFAULT_MINIMAX_CONTEXT_WINDOW = 200000; diff --git a/src/commands/onboard-auth.ts b/src/commands/onboard-auth.ts index 6be543e472e..a0b83b7570d 100644 --- a/src/commands/onboard-auth.ts +++ b/src/commands/onboard-auth.ts @@ -38,7 +38,9 @@ export { } from "./onboard-auth.config-core.js"; export { applyMinimaxApiConfig, + applyMinimaxApiConfigCn, applyMinimaxApiProviderConfig, + applyMinimaxApiProviderConfigCn, applyMinimaxConfig, applyMinimaxHostedConfig, applyMinimaxHostedProviderConfig, @@ -92,6 +94,7 @@ export { KIMI_CODING_MODEL_ID, KIMI_CODING_MODEL_REF, MINIMAX_API_BASE_URL, + MINIMAX_CN_API_BASE_URL, MINIMAX_HOSTED_MODEL_ID, MINIMAX_HOSTED_MODEL_REF, MOONSHOT_BASE_URL, diff --git a/src/commands/onboard-types.ts b/src/commands/onboard-types.ts index 4aa2e339efa..43a9cde7620 100644 --- a/src/commands/onboard-types.ts +++ b/src/commands/onboard-types.ts @@ -37,6 +37,7 @@ export type AuthChoice = | "minimax-cloud" | "minimax" | "minimax-api" + | "minimax-api-key-cn" | "minimax-api-lightning" | "minimax-portal" | "opencode-zen"