Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.
gateway: DeepSeek's own Anthropic endpoint is asked its effort in output_config (#3298 item 4)
yetonee2543575a9b7
diff --git a/internal/gateway/anthropic.go b/internal/gateway/anthropic.goindex ff39514f1..1135c9b0d 100644--- a/internal/gateway/anthropic.go+++ b/internal/gateway/anthropic.go@@ -766,6 +766,30 @@ func AdaptiveThinking(model string) bool { return adaptiveOnly(model) }// (shin4 on plugins#316).var effortInOutputConfig = regexp.MustCompile(`(?i)glm-5\.[23](?:$|[-.:/\[])|minimax-m3\.1-flash(?:$|[-.:/\[])`)+// deepseekHost is DeepSeek's own API, whose Anthropic endpoint+// (api.deepseek.com/anthropic) takes the effort in output_config.+const deepseekHost = "api.deepseek.com"++// deepseekEfforts are the levels DeepSeek's models think at: its thinking+// guide maps minimal to low, medium and xhigh to high, and ultra to max.+// A budget a client sent is fitted to them when the model's own list is+// unknown, so 32000 (max, as budgetOf gives it) asks max, not xhigh,+// which DeepSeek would read as high.+var deepseekEfforts = []string{"low", "high", "max"}++// outputEffortAt is effortInOutputConfig for a model at host: those+// models anywhere, and every model on DeepSeek's own endpoint. DeepSeek's+// Anthropic API docs (api-docs.deepseek.com/guides/anthropic_api, read+// 2026-10-23) list thinking as "Supported (budget_tokens is ignored)" and+// output_config as "Only effort is supported", and its thinking guide+// (guides/thinking_mode) names output_config.effort as the Anthropic+// format's effort control: a budget alone left DSH's low and max at+// DeepSeek's default, high (#3298). Another host serving a DeepSeek model+// is not covered by those docs and goes as it did.+func outputEffortAt(host, model string) bool {+ return host == deepseekHost || effortInOutputConfig.MatchString(model)+}+// 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.func withOutputEffort(body []byte, levels []string) []byte {@@ -813,13 +837,14 @@ const interruptedTool = "[The result of this tool call is unavailable: the turn// buildAnthropic renders a request for an Anthropic-style upstream.func buildAnthropic(r *Request, model string) []byte {- return anthropicBody(r, model, false)+ return anthropicBody(r, model, "", false)}// anthropicBody is buildAnthropic; with replay, for an upstream that wants// a turn's thinking back (anthropicReplaysThinking), thinking with no-// signature goes as its text instead of being left out.-func anthropicBody(r *Request, model string, replay bool) []byte {+// signature goes as its text instead of being left out. host is the+// upstream's (outputEffortAt).+func anthropicBody(r *Request, model, host string, replay bool) []byte {if r.Format != nil && r.Format.schema() == nil {// output_config.format takes a schema only: any JSON object is// asked for in words@@ -945,7 +970,7 @@ func anthropicBody(r *Request, model string, replay bool) []byte {maxTokens = budget + 4096}out["thinking"] = map[string]any{"type": "enabled", "budget_tokens": budget}- if r.Effort != "" && effortInOutputConfig.MatchString(model) {+ if r.Effort != "" && outputEffortAt(host, model) {out["output_config"] = map[string]any{"effort": r.Effort}}} else if r.Temp != nil {diff --git a/internal/gateway/deepseek_output_effort_test.go b/internal/gateway/deepseek_output_effort_test.gonew file mode 100644index 000000000..4ebcf3690--- /dev/null+++ b/internal/gateway/deepseek_output_effort_test.go@@ -0,0 +1,104 @@+package gateway++import (+ "context"+ "encoding/json"+ "net"+ "net/http"+ "net/http/httptest"+ "strings"+ "testing"++ "github.com/yetone/magpie/internal/provider"+)++// sentOutputEffort is the output_config.effort a Messages body asks for.+func sentOutputEffort(t *testing.T, body []byte) string {+ t.Helper()+ var q struct {+ OutputConfig struct {+ Effort string `json:"effort"`+ } `json:"output_config"`+ }+ if err := json.Unmarshal(body, &q); err != nil {+ t.Fatalf("%v: %s", err, body)+ }+ return q.OutputConfig.Effort+}++// DeepSeek's Anthropic endpoint ignores budget_tokens and takes the+// effort in output_config.effort alone (api-docs.deepseek.com,+// guides/anthropic_api and guides/thinking_mode): a client that asks by+// budget, as DSH's magpie-anthropic route does through pi-ai, has its+// level said there too, fitted to DeepSeek's low, high and max (#3298).+// The same model behind another host, and another vendor's model, go as+// they were sent.+func TestDeepSeekAnthropicEffortInOutputConfig(t *testing.T) {+ f := &fake{t: t, ctype: "application/json", reply: anthropicWholeOK}+ setup(t, provider.Anthropic, f)+ up := httptest.NewServer(f)+ t.Cleanup(up.Close)+ for _, p := range []provider.Provider{+ {ID: "deepseek", Name: "DeepSeek", Key: "k", Models: []string{"deepseek-flash", "deepseek-v4-pro"}, Anthropic: "http://api.deepseek.com/anthropic"},+ {ID: "relay", Name: "Relay", Key: "k", Models: []string{"deepseek-flash"}, Anthropic: "http://relay.example.com/anthropic"},+ {ID: "kimi", Name: "Kimi", Key: "k", Models: []string{"kimi-k2.5"}, Anthropic: "http://api.moonshot.ai/anthropic"},+ } {+ if err := provider.Save(p); err != nil {+ t.Fatal(err)+ }+ }+ s := New()+ addr := strings.TrimPrefix(up.URL, "http://")+ s.client = &http.Client{Transport: &http.Transport{DialContext: func(ctx context.Context, network, _ string) (net.Conn, error) {+ return (&net.Dialer{}).DialContext(ctx, network, addr)+ }}}+ const body = `{"model":"%s","max_tokens":64000,"stream":false,"thinking":{"type":"enabled","budget_tokens":%s},"messages":[{"role":"user","content":"hi"}]}`+ for _, c := range []struct{ model, budget, want string }{+ {"deepseek/deepseek-flash", "4096", "low"},+ {"deepseek/deepseek-flash", "10000", "high"},+ {"deepseek/deepseek-v4-pro", "32000", "max"},+ // not DeepSeek's endpoint: its docs say nothing of a relay's+ {"relay/deepseek-flash", "32000", ""},+ // another vendor's model on its own Anthropic endpoint+ {"kimi/kimi-k2.5", "32000", ""},+ } {+ f.got = nil+ req := strings.Replace(strings.Replace(body, "%s", c.model, 1), "%s", c.budget, 1)+ code, reply := postTo(t, s, "/v1/messages", req)+ if code != 200 {+ t.Fatalf("%s: %d %s", c.model, code, reply)+ }+ if got := sentOutputEffort(t, f.got); got != c.want {+ t.Errorf("%s budget %s: output_config.effort %q, want %q: %s", c.model, c.budget, got, c.want, f.got)+ }+ if !strings.Contains(string(f.got), `"budget_tokens":`+c.budget) {+ t.Errorf("%s: the budget was not sent as it came: %s", c.model, f.got)+ }+ }+}++// Translated onto DeepSeek's Anthropic endpoint (a Chat client), the+// client's reasoning_effort goes in output_config beside the budget; the+// same model on another host, and another vendor's model on DeepSeek's+// builder path, get the budget alone as before.+func TestTranslatedDeepSeekAnthropicEffort(t *testing.T) {+ r := &Request{Thinking: true, Effort: "max", Messages: []Message{{Role: "user", Parts: []Part{{Kind: Text, Text: "hi"}}}}}+ for _, c := range []struct{ host, model, want string }{+ {"api.deepseek.com", "deepseek-flash", "max"},+ {"api.deepseek.com", "deepseek-v4-pro", "max"},+ {"relay.example.com", "deepseek-flash", ""},+ {"api.moonshot.ai", "kimi-k2.5", ""},+ {"", "kimi-k2.5", ""},+ } {+ out, err := build(provider.Anthropic, r, c.model, c.host, false)+ if err != nil {+ t.Fatal(err)+ }+ if got := sentOutputEffort(t, out); got != c.want {+ t.Errorf("%s at %q: output_config.effort %q, want %q: %s", c.model, c.host, got, c.want, out)+ }+ if !strings.Contains(string(out), `"budget_tokens":`) {+ t.Errorf("%s at %q: no budget: %s", c.model, c.host, out)+ }+ }+}diff --git a/internal/gateway/gateway.go b/internal/gateway/gateway.goindex 12d2998d9..505cf26f8 100644--- a/internal/gateway/gateway.go+++ b/internal/gateway/gateway.go@@ -4318,8 +4318,12 @@ func (s *Server) passthrough(w http.ResponseWriter, r *http.Request, p provider.// goes as it was sent, safeguards and allbody = autoModeClassifierBody(model, body)}- if effortInOutputConfig.MatchString(model) {- body = withOutputEffort(body, p.Efforts(model))+ if outputEffortAt(p.Host(), model) {+ levels := p.Efforts(model)+ if len(levels) == 0 && p.Host() == deepseekHost {+ levels = deepseekEfforts+ }+ body = withOutputEffort(body, levels)}if !s.fits(p.ID, offRefused(model), proto) {// a model that refused thinking turned off before (below):@@ -6135,7 +6139,7 @@ func build(proto provider.Protocol, r *Request, model, host string, rejectTemp breturn buildGemini(r, model)}replay := anthropicReplaysThinking(host, model)- out := anthropicBody(r, model, replay)+ out := anthropicBody(r, model, host, replay)if replay {// a tool call with no thinking before it, which DeepSeek turns// the whole request away for (#1611)