Skip to content

Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.

gateway: MiniMax M3.1-Flash is sent its effort in output_config (shin4 on plugins#316)

yetone226551d0d889
diff --git a/docs/subsystems/gateway-routing.md b/docs/subsystems/gateway-routing.md
index a03beb3b0..cac121363 100644
--- a/docs/subsystems/gateway-routing.md
+++ b/docs/subsystems/gateway-routing.md
@@ -171,6 +171,7 @@ recorded as a prediction failure (`noPrediction`).
- In models.dev, entries from `deepseek`, `kimi-code-plan-cn` and `kimi-code-plan-global` gain `none` only when they have both a `toggle` and effort levels; the DeepSeek and Kimi APIs accepted that value in [#1098](https://github.com/yetone/magpie/issues/1098). Other providers keep their listed levels because their APIs may reject `none`; toggle-only entries remain level-less ([`mdModel.efforts`](../../internal/catalog/catalog.go)).
- Gemini's OpenAI-compatible API (AI Studio's, or a proxy in front of Gemini on this computer or the LAN: `geminiCompat`) is asked for the model's thoughts in `extra_body.google.thinking_config`. A 400 or 422 whose error names `extra_body`, `include_thoughts` or thinking at all (`refusesThinkingConfig`) marks the provider unfit for the field (`thinking_config`), and it is asked again with `reasoning_effort` alone. Gemini 3 can't stop thinking, so reasoning turned off goes at `minimal`, its least, or at the model's lowest level where it has no `minimal` (`geminiLevels`: those of the model's levels it hasn't turned away, or of Gemini 3's where its own aren't known or none is left). Gemini 3 turns away a level the model hasn't with a 400 that names the level (`geminiRefusedLevel`): AI Studio's "Thinking level MINIMAL is not supported for this model. Please retry with other thinking level." for gemini-3.8-flash, Vertex AI's "Thinking level is unsupported: THINKING_LEVEL_MINIMAL". It names thinking too, but isn't the field turned away. The level is marked refused for that model (`levelRefused`), and the model is asked again at the nearest level it has left, still for its thoughts, and at that level from then on. A level turned away again, with none left, is the client's 400. Passed through, a Chat client's own `none` or `minimal` that Gemini turns away this way is asked again at the model's lowest level (`onEffort`), and that level goes at the lowest from then on (`turnedAway`); the other still goes as sent, as AI Studio takes `none` from gemini-3.8-flash. A refusal that names the levels the model takes (`effortLevelsNamed`, Command Code's for Qoder's `none`) marks reasoning off as a whole (`offRefused`): both go at the lowest from then on; one that lists the other among the levels taken (`otherOffNamed`, quoted, OpenAI's for gpt-5.1's `minimal`) marks only the level turned away. Both routes read and write the same marks. Vertex AI's OpenAI-compatible API marks each streamed chunk of thoughts in the delta's `extra_content.google.thought`, and such a chunk is read as thinking.
- A Claude that thinks only adaptively (`adaptiveOnly` in [`anthropic.go`](../../internal/gateway/anthropic.go): Opus, Sonnet and Haiku from 4.6 on, Fable and Mythos 5 and 5.1, read by `claudeVersion` however a relay spells them) is never sent a thinking budget, which they answer with 400. magpie's own request from a Chat or Responses client (`buildAnthropic`) goes as `thinking: {type: "adaptive", display: "summarized"}` with the effort in `output_config.effort`, so the client sees the reasoning Opus 4.7 and later otherwise leave out (display `omitted` by default), and a relay that refuses `display` is asked again without it (`refuseShapes`), as is one that refuses auto mode's `safeguards` (Copilot's Messages API: 400 "safeguards: Extra inputs are not permitted" on claude-opus-5.5, #1756; `shapeSafeguards`, `TestSafeguardsRefusedLeftOut`), and neither is sent it again while magpie runs; a client's `thinking: {type: "enabled", budget_tokens}` is turned into the same in `forwardOnce` (`adaptiveThinking`), the budget as its nearest effort, above `high` as `max`, and `display: "summarized"` unless the client named its own display, so the thinking that enabled shows stays shown (the refused shapes are taken out after it, and `refuseShapes` reads the display as it is sent); and Pi, dsh and omp are written to ask it adaptively (`AdaptiveThinking`: `forceAdaptiveThinking`, omp's `anthropic-adaptive`; #1470). A client's `xhigh` goes as `xhigh`, except to Opus and Sonnet 4.6, which have no `xhigh` and are asked `max` (`noXhigh`, #1471).
+- A vendor's model that takes its level in `output_config.effort` beside thinking on (`effortInOutputConfig` in [`anthropic.go`](../../internal/gateway/anthropic.go): Z.ai's GLM-5.2 and GLM-5.3, and MiniMax's MiniMax-M3.1-Flash and its -Preview) is sent the effort there next to the budget: built from a Chat or Responses client's effort (`buildAnthropic`, when it sends a budget), or added to an Anthropic client's request from its budget's nearest level, fitted to the model's levels (`withOutputEffort`, in `passthrough`). A budget alone left GLM at its default, and under an 8192 cap gave MiniMax's medium to max one budget, 7168 (shin4 on plugins#316). Every other model, Claude and MiniMax-M3 included, gets the budget alone. `TestGLMEffortInOutputConfig`, `TestMiniMaxPluginGetsTheNativeEffort`, `TestNativeEffortLeavesOthersAlone`.
- A request to an Anthropic endpoint that turns thinking off is sent as the model takes it (`thinkingOffAsTaken`, in `forwardOnce`, so relayed requests, count_tokens, magpie's own thinking-off and retries all get it; the model is read as the vendor names it, from the body, or from the path for Bedrock and Vertex). Claude Sonnet 5.5 refuses `thinking: {type: "disabled"}` and is sent `{type: "between_tools"}` alone, at effort `high` at most. Opus 5.5, Fable 5 and Mythos 5 refuse it at every effort and are sent no thinking, at effort `low` unless one was asked, with `classifierRoom` added to a reply limit below it, as Claude Code does. Opus 5 and Haiku 5.5 take it only up to `high`, so `xhigh` and `max` are asked as `high`. `between_tools` sent to any other Claude goes as `disabled`, or as none where that is refused too. Other vendors' models, older Claudes and later lines than these go as they came (#1454). A Sonnet 5.5 by a name these rules can't read, answering 400 that asks for `between_tools` (`asksBetweenTools`), is asked again with it, once; a refusal of `disabled` at any effort (`thinkingOffRefused`) is asked again with thinking left to the model, as `alwaysThinks` is. So is a relay that reads `disabled` as reasoning effort `none` and turns that level away naming the ones it takes (Sub2API's gpt-6.1-sol, "does not support reasoning effort \"none\"; use low, medium, high, xhigh or max", #1465); `refusesThinkingOff` is the one list of these refusals for both routes. A relayed request refused so marks the model (`markUnfit(offRefused)`), and its later requests go with thinking left to the model at once until magpie restarts, as auto mode's classifier asks on every action.
- A Chat or Responses client's reasoning turned off (`none`, `ThinkOff`), translated to an Anthropic endpoint (`buildAnthropic`), goes as `thinking: {type: "disabled"}`; it went as thinking at a 4096-token budget before (#1636). A model that refuses it (`refusesThinkingOff`: `alwaysThinks`, `mandatoryReasoning`, `thinkingOffRefused`, or `none` turned away naming the levels taken) is asked again at its least (`thinkingBackOn`), and `markUnfit(offRefused)` sends it so at once until magpie restarts. A translated request's level can differ from the one asked: `none` and `minimal` go as `low` where the model's levels don't say it stops (`effortOf`). The route keeps the level asked; the try, the usage log and Routing's "went" say the one built (`noteWireEffort`, `wireEffort` in [`wire_effort.go`](../../internal/gateway/wire_effort.go)). Gemini's builders say theirs their own way and are logged as asked.
- A model the user ticked no levels of (`ModelReasonless` in [settings](../../internal/settings/settings.go), `SetModelReasonless`; the provider editor's Names & levels, or `magpie model efforts <provider/model> off`) is sent no reasoning field on any route, whatever the agent asks: the candidate loop strips the body with `withoutAnyReasoning` ([`quiet.go`](../../internal/gateway/quiet.go): Chat's `reasoning_effort`, `reasoning`, `thinking`, `enable_thinking` and `include`'s `reasoning.encrypted_content`, Responses' `reasoning`, Anthropic's `thinking` of any type and `output_config.effort`, Gemini's `thinkingConfig`), the Anthropic relay doesn't add `thinking:{type:disabled}` for it, and `forwardTranslated` clears `Effort`, `ThinkOff` and `Thinking` for its other callers. It offers no levels (`Efforts`, `entryFor`), is `Quiet`, and as a routing-group member doesn't take the group's levels away. The learned refusals above cover only reasoning *off* and Gemini levels; a vendor that answers a plain `reasoning_effort` with 422 (yuexian7 on Discord) is not learned, so this is the user's switch. `TestReasonlessModelSentNoReasoning`, `TestReasonlessAnthropicRelay`, `TestGroupReasonlessMemberKeepsLevels`, `model-reasonless.test.cjs`.
diff --git a/internal/gateway/anthropic.go b/internal/gateway/anthropic.go
index 3d0f242ad..53a281c35 100644
--- a/internal/gateway/anthropic.go
+++ b/internal/gateway/anthropic.go
@@ -759,8 +759,12 @@ func AdaptiveThinking(model string) bool { return adaptiveOnly(model) }
// effortInOutputConfig is a model that takes how hard it thinks from
// output_config.effort, beside thinking turned on, as ZCode asks it: Z.ai's
// GLM-5.2 and GLM-5.3 on their Anthropic endpoints. A budget alone leaves
-// them at their own default.
-var effortInOutputConfig = regexp.MustCompile(`(?i)glm-5\.[23](?:$|[-.:/\[])`)
+// them at their own default. MiniMax's MiniMax-M3.1-Flash and its
+// -Preview, which think at low…max (MiniMax Code's catalog: forced_on),
+// are asked the same way as MiniMax Code asks them: a budget alone gave
+// medium to max one budget under an 8192 cap, so the level was lost
+// (shin4 on plugins#316).
+var effortInOutputConfig = regexp.MustCompile(`(?i)glm-5\.[23](?:$|[-.:/\[])|minimax-m3\.1-flash(?:$|[-.:/\[])`)
// withOutputEffort is body asking, in output_config.effort, for the level
// of levels nearest the reasoning it asks for; body when it asks for none.
diff --git a/internal/gateway/minimax_effort_test.go b/internal/gateway/minimax_effort_test.go
new file mode 100644
index 000000000..88af0d217
--- /dev/null
+++ b/internal/gateway/minimax_effort_test.go
@@ -0,0 +1,84 @@
+package gateway
+
+import (
+ "encoding/json"
+ "net/http/httptest"
+ "testing"
+
+ "github.com/yetone/magpie/internal/provider"
+)
+
+// shin4 on plugins#316: an OpenAI client's effort for MiniMax Code's
+// M3.1-Flash reached the plugin as a thinking budget alone, and under an
+// 8192 cap medium to max were all budget 7168, so the level was lost. It
+// goes in output_config.effort too, from Responses, Chat and an Anthropic
+// client's budget, on both MiniMax Code providers. The requests are the
+// reporter's, with the effort and the model's provider swapped in.
+func TestMiniMaxPluginGetsTheNativeEffort(t *testing.T) {
+ t.Setenv("FAKE_MINIMAX", "1")
+ for _, id := range []string{"minimax-code", "minimax-code-global"} {
+ t.Run(id, func(t *testing.T) {
+ up := &adaptiveVendor{}
+ pid := besideFake(t, id, up)
+ for _, model := range []string{"MiniMax-M3.1-Flash", "MiniMax-M3.1-Flash-Preview"} {
+ for _, c := range []struct {
+ effort string
+ budget float64
+ }{{"low", 4096}, {"medium", 7168}, {"high", 7168}, {"xhigh", 7168}, {"max", 7168}} {
+ for _, ask := range []struct{ path, body string }{
+ {"/v1/responses", `{"model":"` + pid + `/` + model + `","input":"Reply exactly OK.","reasoning":{"effort":"` + c.effort + `"},"max_output_tokens":8192,"stream":false}`},
+ {"/v1/chat/completions", `{"model":"` + pid + `/` + model + `","messages":[{"role":"user","content":"Reply exactly OK."}],"reasoning_effort":"` + c.effort + `","max_tokens":8192,"stream":false}`},
+ } {
+ postProto(t, New(), ask.path, ask.body)
+ got := up.last()
+ oc, _ := got["output_config"].(map[string]any)
+ th, _ := got["thinking"].(map[string]any)
+ if oc["effort"] != c.effort {
+ t.Errorf("%s %s %s: output_config %v, thinking %v", ask.path, model, c.effort, got["output_config"], th)
+ }
+ if th["type"] != "enabled" || th["budget_tokens"] != c.budget {
+ t.Errorf("%s %s %s: thinking %v, want a budget of %v beside the effort", ask.path, model, c.effort, th, c.budget)
+ }
+ }
+ }
+ }
+ // an Anthropic client's budget, as Claude Code sends medium
+ postProto(t, New(), "/v1/messages", `{"model":"`+pid+`/MiniMax-M3.1-Flash","max_tokens":32000,"thinking":{"type":"enabled","budget_tokens":10000},"messages":[{"role":"user","content":"Reply exactly OK."}]}`)
+ if oc, _ := up.last()["output_config"].(map[string]any); oc["effort"] != "medium" {
+ t.Errorf("/v1/messages budget 10000: output_config %v", up.last()["output_config"])
+ }
+ // M3, which thinks or doesn't and has no levels of its own,
+ // keeps the budget alone
+ postProto(t, New(), "/v1/responses", `{"model":"`+pid+`/MiniMax-M3","input":"Reply exactly OK.","reasoning":{"effort":"high"},"max_output_tokens":8192,"stream":false}`)
+ if got := up.last(); got["output_config"] != nil {
+ t.Errorf("MiniMax-M3 asked output_config %v", got["output_config"])
+ }
+ })
+ }
+}
+
+// What goes to a Claude and to another vendor's model on an Anthropic
+// endpoint is as before: the budget alone, no output_config.
+func TestNativeEffortLeavesOthersAlone(t *testing.T) {
+ fresh(t)
+ up := &adaptiveVendor{}
+ srv := httptest.NewServer(up)
+ t.Cleanup(srv.Close)
+ if err := provider.Save(provider.Provider{ID: "relay", Name: "Relay", Key: "k", Anthropic: srv.URL,
+ Models: []string{"claude-sonnet-4-5", "kimi-k3", "MiniMax-M3"}}); err != nil {
+ t.Fatal(err)
+ }
+ for _, model := range []string{"claude-sonnet-4-5", "kimi-k3", "MiniMax-M3"} {
+ for _, ask := range []struct{ path, body string }{
+ {"/v1/responses", `{"model":"relay/` + model + `","input":"Reply exactly OK.","reasoning":{"effort":"high"},"max_output_tokens":8192,"stream":false}`},
+ {"/v1/chat/completions", `{"model":"relay/` + model + `","messages":[{"role":"user","content":"Reply exactly OK."}],"reasoning_effort":"high","max_tokens":8192,"stream":false}`},
+ } {
+ postProto(t, New(), ask.path, ask.body)
+ got := up.last()
+ b, _ := json.Marshal(map[string]any{"thinking": got["thinking"], "output_config": got["output_config"]})
+ if want := `{"output_config":null,"thinking":{"budget_tokens":7168,"type":"enabled"}}`; string(b) != want {
+ t.Errorf("%s %s: %s", ask.path, model, b)
+ }
+ }
+ }
+}
diff --git a/internal/plugin/testdata/fake/index.js b/internal/plugin/testdata/fake/index.js
index 5a4933442..f4b0ecb16 100644
--- a/internal/plugin/testdata/fake/index.js
+++ b/internal/plugin/testdata/fake/index.js
@@ -93,6 +93,16 @@ export const FakePlugin = async ({ client }) => ({
// Cline sends glm-5.3-flash through OpenRouter, not Vercel's gateway
cfg.provider[ID].models["glm-5.3-flash"] = { name: "GLM 5.3 Flash", limit: { context: 1000, output: 100 } }
}
+ // $FAKE_MINIMAX: MiniMax Code's models as its plugin (minimax 0.1.4)
+ // gives them, on Anthropic's API: M3.1-Flash and its -Preview always
+ // think at an effort, M3 thinks or doesn't (plugins#316)
+ if (process.env.FAKE_MINIMAX) {
+ const efforts = Object.fromEntries(["low", "medium", "high", "xhigh", "max"].map((e) => [e, { thinking: { type: "adaptive" }, effort: e }]))
+ const mm = { provider: { npm: "@ai-sdk/anthropic" }, reasoning: true, limit: { context: 1048576, output: 524288 } }
+ cfg.provider[ID].models["MiniMax-M3.1-Flash"] = { ...mm, name: "M3.1-Flash", variants: efforts }
+ cfg.provider[ID].models["MiniMax-M3.1-Flash-Preview"] = { ...mm, name: "M3.1-Flash-Preview", variants: efforts }
+ cfg.provider[ID].models["MiniMax-M3"] = { ...mm, name: "MiniMax-M3", variants: { none: { thinking: { type: "disabled" } }, high: { thinking: { type: "adaptive" } } } }
+ }
// $FAKE_SEARCHES: the provider's upstream searches by itself (#2027),
// as a plugin in front of Claude's API says
if (process.env.FAKE_SEARCHES) cfg.provider[ID].searches = true