Skip to content

Commit 68932a9

Browse files
committed
feat: add minimax-api-key-cn option for China API endpoint
- Add 'minimax-api-key-cn' auth choice for Chinese users - Reuse existing --minimax-api-key CLI option - Support custom baseUrl parameter (default: https://api.minimaxi.com/anthropic) - Similar to how moonshot supports moonshot-api-key-cn Tested: build ✅, check ✅, test ✅
1 parent 9230a2a commit 68932a9

File tree

4 files changed

+51
-3
lines changed

4 files changed

+51
-3
lines changed

src/cli/program/register.onboard.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export function registerOnboardCommand(program: Command) {
5858
.option("--mode <mode>", "Wizard mode: local|remote")
5959
.option(
6060
"--auth-choice <choice>",
61-
"Auth: setup-token|token|chutes|openai-codex|openai-api-key|xai-api-key|qianfan-api-key|openrouter-api-key|litellm-api-key|ai-gateway-api-key|cloudflare-ai-gateway-api-key|moonshot-api-key|moonshot-api-key-cn|kimi-code-api-key|synthetic-api-key|venice-api-key|gemini-api-key|zai-api-key|zai-coding-global|zai-coding-cn|zai-global|zai-cn|xiaomi-api-key|apiKey|minimax-api|minimax-api-lightning|opencode-zen|custom-api-key|skip|together-api-key",
61+
"Auth: setup-token|token|chutes|openai-codex|openai-api-key|xai-api-key|qianfan-api-key|openrouter-api-key|litellm-api-key|ai-gateway-api-key|cloudflare-ai-gateway-api-key|moonshot-api-key|moonshot-api-key-cn|kimi-code-api-key|synthetic-api-key|venice-api-key|gemini-api-key|zai-api-key|zai-coding-global|zai-coding-cn|zai-global|zai-cn|xiaomi-api-key|apiKey|minimax-api|minimax-api-key-cn|minimax-api-lightning|opencode-zen|custom-api-key|skip|together-api-key",
6262
)
6363
.option(
6464
"--token-provider <id>",

src/commands/auth-choice.apply.minimax.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,51 @@ export async function applyAuthChoiceMiniMax(
9797
return { config: nextConfig, agentModelOverride };
9898
}
9999

100+
if (params.authChoice === "minimax-api-key-cn") {
101+
const modelId = "MiniMax-M2.5";
102+
let hasCredential = false;
103+
const envKey = resolveEnvApiKey("minimax");
104+
if (envKey) {
105+
const useExisting = await params.prompter.confirm({
106+
message: `Use existing MINIMAX_API_KEY (${envKey.source}, ${formatApiKeyPreview(envKey.apiKey)})?`,
107+
initialValue: true,
108+
});
109+
if (useExisting) {
110+
await setMinimaxApiKey(envKey.apiKey, params.agentDir);
111+
hasCredential = true;
112+
}
113+
}
114+
if (!hasCredential) {
115+
const key = await params.prompter.text({
116+
message: "Enter MiniMax China API key",
117+
validate: validateApiKeyInput,
118+
});
119+
await setMinimaxApiKey(normalizeApiKeyInput(String(key)), params.agentDir);
120+
}
121+
nextConfig = applyAuthProfileConfig(nextConfig, {
122+
profileId: "minimax:default",
123+
provider: "minimax",
124+
mode: "api_key",
125+
});
126+
{
127+
const modelRef = `minimax/${modelId}`;
128+
const applied = await applyDefaultModelChoice({
129+
config: nextConfig,
130+
setDefaultModel: params.setDefaultModel,
131+
defaultModel: modelRef,
132+
applyDefaultConfig: (config) =>
133+
applyMinimaxApiConfig(config, modelId, "https://api.minimaxi.com/anthropic"),
134+
applyProviderConfig: (config) =>
135+
applyMinimaxApiProviderConfig(config, modelId, "https://api.minimaxi.com/anthropic"),
136+
noteAgentModel,
137+
prompter: params.prompter,
138+
});
139+
nextConfig = applied.config;
140+
agentModelOverride = applied.agentModelOverride ?? agentModelOverride;
141+
}
142+
return { config: nextConfig, agentModelOverride };
143+
}
144+
100145
if (params.authChoice === "minimax") {
101146
const applied = await applyDefaultModelChoice({
102147
config: nextConfig,

src/commands/onboard-auth.config-minimax.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ export function applyMinimaxHostedConfig(
149149
export function applyMinimaxApiProviderConfig(
150150
cfg: OpenClawConfig,
151151
modelId: string = "MiniMax-M2.1",
152+
customBaseUrl?: string,
152153
): OpenClawConfig {
153154
const providers = { ...cfg.models?.providers };
154155
const existingProvider = providers.minimax;
@@ -164,7 +165,7 @@ export function applyMinimaxApiProviderConfig(
164165
const normalizedApiKey = resolvedApiKey?.trim() === "minimax" ? "" : resolvedApiKey;
165166
providers.minimax = {
166167
...existingProviderRest,
167-
baseUrl: MINIMAX_API_BASE_URL,
168+
baseUrl: customBaseUrl ?? MINIMAX_API_BASE_URL,
168169
api: "anthropic-messages",
169170
...(normalizedApiKey?.trim() ? { apiKey: normalizedApiKey } : {}),
170171
models: mergedModels.length > 0 ? mergedModels : [apiModel],
@@ -192,8 +193,9 @@ export function applyMinimaxApiProviderConfig(
192193
export function applyMinimaxApiConfig(
193194
cfg: OpenClawConfig,
194195
modelId: string = "MiniMax-M2.1",
196+
customBaseUrl?: string,
195197
): OpenClawConfig {
196-
const next = applyMinimaxApiProviderConfig(cfg, modelId);
198+
const next = applyMinimaxApiProviderConfig(cfg, modelId, customBaseUrl);
197199
return {
198200
...next,
199201
agents: {

src/commands/onboard-types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export type AuthChoice =
3535
| "minimax-cloud"
3636
| "minimax"
3737
| "minimax-api"
38+
| "minimax-api-key-cn"
3839
| "minimax-api-lightning"
3940
| "minimax-portal"
4041
| "opencode-zen"

0 commit comments

Comments
 (0)