From f6e7214af78491227abc18b741fbbc76e6ddb4ec Mon Sep 17 00:00:00 2001 From: yetone Date: Thu, 29 Oct 2026 00:53:43 +0800 Subject: [PATCH] minimax: api.minimax.cn is MiniMax China, for the usage card and the thinking sent back MiniMax moved its China API host to api.minimax.cn (MiniMax-AI/cli 8746d48f, 2026-09-28: mmx agent setup now writes it into Claude Code, Codex, OpenCode and pi). api.minimaxi.com still answers, but a provider pointed at the new host got no usage card, because the plan-quota source knew only api.minimaxi.com and api.minimax.io. Chat requests to it also lost the block MiniMax wants back on the turns after. Every place in magpie that matches MiniMax by host is covered: - planquota.go: api.minimax.cn reads /v1/token_plan/remains on its own host. Probed without a key, api.minimax.cn answers this path with the same base_resp 1004 as api.minimaxi.com. - gateway/chat.go: inlineThink also matches minimax.cn. Pricing and the catalog go by the provider's Catalog id ("minimax"), not by host, so nothing changes there. The presets keep api.minimaxi.com. Tests: a TestPlanQuotaSource case and a TestMiniMaxThinkingGoesBackInTags case for api.minimax.cn. Both are red on the old code (code reverted by hand, test kept; mote-run) and green with the fix. Run on mote (mote-run): - At 96bfdd57c (base 11c427eaa): gofmt -l on the changed files prints nothing; GOOS=linux go vet -tags nogui ./... ok; GOOS=windows go vet ./... ok; go test -count=1 -timeout 45m ./...: 76 packages ok (internal/gateway 1073s, internal/provider 490s). internal/gui timed out at 45m, with TestRestartHandsTheGatewayOver stuck 43m in gateway stopAccepting during the handover at load ~110. That is not this change: filed as #4107 with the stacks. - Rebased onto 425a61322 and run again at this head: TestPlanQuotaSource and TestMiniMaxThinkingGoesBackInTags pass; ./internal/provider ok; go vet (darwin), linux -tags nogui and windows vet ok; TestRestartHandsTheGatewayOver -count=5 ok. Not tried: a real Coding Plan key against api.minimax.cn (I have none), so the card on that host is checked only by the shape of the no-key reply. --- internal/gateway/chat.go | 3 ++- internal/gateway/minimax_think_test.go | 1 + internal/provider/planquota.go | 7 +++++-- internal/provider/planquota_test.go | 2 ++ 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/internal/gateway/chat.go b/internal/gateway/chat.go index 3a0759b82..7edff257c 100644 --- a/internal/gateway/chat.go +++ b/internal/gateway/chat.go @@ -331,7 +331,8 @@ func buildChat(r *Request, model, host string, rejectTemp bool) []byte { // interleaved thinking): the decoder takes it out as thinking (#1267), // so it goes back in where it came from. A relay serving MiniMax's // models may give the thinking apart and take it back otherwise. - inlineThink := strings.HasSuffix(host, "minimax.io") || strings.HasSuffix(host, "minimaxi.com") + // api.minimax.cn is MiniMax China's host beside api.minimaxi.com. + inlineThink := strings.HasSuffix(host, "minimax.io") || strings.HasSuffix(host, "minimaxi.com") || strings.HasSuffix(host, "minimax.cn") // Gemini wants each step's thought signature back on its first call // (#687), and one it can't check for a step it didn't sign gemini := geminiCompat(host, model) diff --git a/internal/gateway/minimax_think_test.go b/internal/gateway/minimax_think_test.go index f6875a9cf..e1eacc50a 100644 --- a/internal/gateway/minimax_think_test.go +++ b/internal/gateway/minimax_think_test.go @@ -88,6 +88,7 @@ func TestMiniMaxThinkingGoesBackInTags(t *testing.T) { for _, c := range []struct{ model, host, want string }{ {"MiniMax-M2.7", "api.minimax.io", "\nThe user greets me.\n\n\nHello!"}, {"MiniMax-M2.7", "api.minimaxi.com", "\nThe user greets me.\n\n\nHello!"}, + {"MiniMax-M2.7", "api.minimax.cn", "\nThe user greets me.\n\n\nHello!"}, {"minimax/minimax-m3", "openrouter.ai", "Hello!"}, {"kimi-k3", "api.moonshot.cn", "Hello!"}, } { diff --git a/internal/provider/planquota.go b/internal/provider/planquota.go index ea512a32f..edb6c9689 100644 --- a/internal/provider/planquota.go +++ b/internal/provider/planquota.go @@ -57,9 +57,12 @@ func planQuotaSourceOf(p Provider) (planQuotaSource, bool) { // preset too, and is told the plan's 5-hour and weekly windows; // a pay-as-you-go key has none, and no card return planQuotaSource{"https://api.commandcode.ai/alpha/billing/credits", true, readCommandCodePlan, false}, true - case "api.minimaxi.com", "api.minimax.io": + case "api.minimaxi.com", "api.minimax.cn", "api.minimax.io": // a Coding Plan key (sk-cp-…) is told its windows; a - // pay-as-you-go key isn't, and gets no card (#387) + // pay-as-you-go key isn't, and gets no card (#387). + // api.minimax.cn is MiniMax China's host since mmx-cli + // 8746d48f (2026-09-28), beside api.minimaxi.com, and + // answers the same query return planQuotaSource{"https://" + hostOf(base) + "/v1/token_plan/remains", true, readMiniMaxPlan, false}, true case "ollama.com": // Ollama Cloud's included allowance (#1888); a key with none diff --git a/internal/provider/planquota_test.go b/internal/provider/planquota_test.go index 42ed88a2c..d3ade2a4d 100644 --- a/internal/provider/planquota_test.go +++ b/internal/provider/planquota_test.go @@ -40,6 +40,8 @@ func TestPlanQuotaSource(t *testing.T) { {Provider{Chat: "https://api.commandcode.ai/provider/v1", Anthropic: "https://api.commandcode.ai/provider"}, "https://api.commandcode.ai/alpha/billing/credits", true, false}, {Provider{Chat: "https://api.minimaxi.com/v1", Anthropic: "https://api.minimaxi.com/anthropic"}, "https://api.minimaxi.com/v1/token_plan/remains", true, false}, {Provider{Anthropic: "https://api.minimax.io/anthropic"}, "https://api.minimax.io/v1/token_plan/remains", true, false}, + // MiniMax China's host since mmx-cli 8746d48f + {Provider{Chat: "https://api.minimax.cn/v1", Anthropic: "https://api.minimax.cn/anthropic"}, "https://api.minimax.cn/v1/token_plan/remains", true, false}, {Provider{Chat: "https://api.deepseek.com"}, "", false, false}, {Provider{Chat: "https://ollama.com/v1", Anthropic: "https://ollama.com"}, "https://ollama.com/api/balance", true, false}, {Provider{Chat: "http://localhost:11434/v1"}, "", false, false}, // a local Ollama