From ea3d1c62e7eebc8e080a07b65f97facc3cebcb53 Mon Sep 17 00:00:00 2001 From: yetone Date: Thu, 5 Nov 2026 11:41:41 +0800 Subject: [PATCH] gateway, codexcat: Codex's image detail "original" goes as "high" to a relay's Responses API, and only DeepSeek's own API is told it takes it (qiu_eth) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit qiu_eth on Discord, v0.1.2885: the Codex App on opencode-go/deepseek-v4.1-flash got 400 "invalid image detail" / "this feature is not yet supported by atlas" for every screenshot. Where the values come from: - input_modalities ["text","image"]: models.dev lists deepseek-v4.1-flash under opencode-go with input text and image, and 841326709 (v0.1.2343) counts Go's media types as images. Go's own list says the same, so this stays. - supports_image_detail_original true: codexcat set it on every model named deepseek-* on any provider (8acb0d3a7), copied from DeepSeek's own Codex setup for api.deepseek.com. A vendor rule had not been scoped to the vendor. Go serves this model on its Responses API (no npm in models.dev, so every API is open, 7c4a5d114), and Responses to Responses went as it came, so "original" reached Go and was refused. The fix has two parts: - codexcat sets supports_image_detail_original only for a model of DeepSeek's own provider (deepseek/…). The rest of DeepSeek's setup (shell_command, verbosity, summary, agents v2) still applies to every DeepSeek model. - The gateway sends an input_image's detail "original" as "high" to any Responses API but OpenAI's (api.openai.com, chatgpt.com, Azure), DeepSeek's (api.deepseek.com) and a remote magpie, which decides for its own upstream. That covers the class: a Codex that already has the old catalog, a relay's GPT, and any other model whose catalog says original. Chat already did this (chatDetail). A body without "original" isn't parsed. Checked against the class: other opencode-go models with images (Kimi, GLM, MiniMax, Qwen) never had the flag, since it was DeepSeek-only, but the gateway now covers them too. Nothing after v0.1.2885 had changed this. Run on mote (mote-run): - go test ./internal/gateway ./internal/codexcat ./internal/catalog -count=1 -timeout 45m: all three ok (gateway 847s). - gofmt -l: clean. GOOS=linux and GOOS=windows go vet of both packages: ok. Broken by hand: - With the gateway's rewrite turned off, TestOriginalDetailHighOnARelay is red: details ["original" "low" "original"], want ["high" "low" "high"]. - With codexcat back to `e.DetailOriginal = m.Images`, TestCodexCatalogDeepSeekAsDeepSeekSays is red: opencode-go/deepseek-v4.1-flash has supports_image_detail_original true. Not tried: a real OpenCode Go request. The only Go key here answers 401 api_key_expired, so Go's 400 is the reporter's word, not reproduced, and that Go takes "high" rests on the Responses spec, not on a run. --- internal/codexcat/codexcat.go | 5 +- internal/codexcat/deepseek_test.go | 12 ++++- internal/gateway/gateway.go | 4 ++ internal/gateway/image_detail.go | 55 ++++++++++++++++++++++ internal/gateway/image_detail_chat_test.go | 47 ++++++++++++++++++ 5 files changed, 121 insertions(+), 2 deletions(-) create mode 100644 internal/gateway/image_detail.go diff --git a/internal/codexcat/codexcat.go b/internal/codexcat/codexcat.go index 52a53349a..b0e5e83d5 100644 --- a/internal/codexcat/codexcat.go +++ b/internal/codexcat/codexcat.go @@ -456,7 +456,10 @@ func entriesAt(ms []catalog.Model, after int, effort string) []any { if e.MultiAgent == "" { e.MultiAgent = "v2" } - e.DetailOriginal = m.Images + // The original detail only on DeepSeek's own API: a relay's + // may refuse it, as OpenCode Go does with 400 "invalid image + // detail" (qiu_eth) + e.DetailOriginal = m.Images && strings.HasPrefix(m.ID, "deepseek/") } for _, ef := range m.Efforts { e.Efforts = append(e.Efforts, level{Effort: ef}) diff --git a/internal/codexcat/deepseek_test.go b/internal/codexcat/deepseek_test.go index c2d0aac6c..edec234eb 100644 --- a/internal/codexcat/deepseek_test.go +++ b/internal/codexcat/deepseek_test.go @@ -27,11 +27,12 @@ func TestCodexCatalogDeepSeekAsDeepSeekSays(t *testing.T) { {ID: "deepseek/deepseek-v4-pro", Name: "DeepSeek V4 Pro", Context: 1048576, Efforts: []string{"low", "high", "max"}}, {ID: "deepseek/deepseek-flash", Name: "DeepSeek V4.1 Flash", Context: 1048576, Images: true, Efforts: []string{"low", "high", "max"}}, {ID: "relay/deepseek-ai/DeepSeek-V4-Pro-0813", Name: "DeepSeek V4 Pro 0813", Context: 1000000}, + {ID: "opencode-go/deepseek-v4.1-flash", Name: "DeepSeek V4.1 Flash", Context: 1048576, Images: true}, {ID: "moonshot/kimi-k3", Name: "Kimi K3", Context: 262144, Images: true, Efforts: []string{"low", "high"}}, {ID: "zai/glm-5.2", Name: "GLM-5.2", Context: 200000}, {ID: "group/deepseek", Name: "deepseek"}, {ID: "x/deepseek-r1-distill-qwen-32b", Name: "R1 Distill Qwen"}, - }), &got); err != nil || len(got.Models) != 7 { + }), &got); err != nil || len(got.Models) != 8 { t.Fatalf("%v %v", err, got) } by := map[string]map[string]any{} @@ -55,6 +56,15 @@ func TestCodexCatalogDeepSeekAsDeepSeekSays(t *testing.T) { if by["deepseek/deepseek-flash"]["supports_image_detail_original"] != true { t.Error("deepseek-flash takes images: supports_image_detail_original true, as DeepSeek's setup says") } + // A relay's DeepSeek takes images at no detail Codex names: OpenCode + // Go answers 400 "invalid image detail" to "original" (qiu_eth) + if e := by["opencode-go/deepseek-v4.1-flash"]; e["supports_image_detail_original"] != nil || e["shell_type"] != "shell_command" { + t.Errorf("opencode-go/deepseek-v4.1-flash: supports_image_detail_original %v, shell %v; want none, DeepSeek's shell_command", + e["supports_image_detail_original"], e["shell_type"]) + } + if in, _ := by["opencode-go/deepseek-v4.1-flash"]["input_modalities"].([]any); len(in) != 2 { + t.Errorf("opencode-go/deepseek-v4.1-flash input_modalities %v; it takes images", in) + } if v, ok := by["deepseek/deepseek-v4-pro"]["supports_image_detail_original"]; ok { t.Errorf("deepseek-v4-pro takes no images; supports_image_detail_original %v", v) } diff --git a/internal/gateway/gateway.go b/internal/gateway/gateway.go index e08c5041f..9aa1ddd47 100644 --- a/internal/gateway/gateway.go +++ b/internal/gateway/gateway.go @@ -3352,6 +3352,10 @@ func (s *Server) serve(w http.ResponseWriter, r *http.Request, from provider.Pro // again (#4732) attemptBody = webpAsJPEG(from, attemptBody) } + // Codex's detail "original" goes only where it is taken (qiu_eth) + if from == provider.Responses && !takesOriginalDetail(c.p) { + attemptBody = originalAsHigh(attemptBody) + } // a value masking swapped for a placeholder: the model is told to // use it as written (treeMan on Discord). A conversation's values // are masked again on every turn, so once one is, every later diff --git a/internal/gateway/image_detail.go b/internal/gateway/image_detail.go new file mode 100644 index 000000000..536032465 --- /dev/null +++ b/internal/gateway/image_detail.go @@ -0,0 +1,55 @@ +package gateway + +import ( + "bytes" + "encoding/json" + + "github.com/yetone/magpie/internal/provider" +) + +// takesOriginalDetail is whether p's Responses API takes an input_image's +// detail "original", Codex's for a screenshot: OpenAI's own API (a ChatGPT +// account's Codex backend, Azure OpenAI), DeepSeek's own, whose Codex +// setup asks for it, and a remote magpie, which decides for its own +// upstream. A relay's Responses API may not: OpenCode Go answers 400 +// "invalid image detail" for DeepSeek V4.1 Flash, which it serves through +// another vendor (qiu_eth). +func takesOriginalDetail(p provider.Provider) bool { + if p.IsAzure() || p.IsRemoteMagpie() { + return true + } + switch provider.HostOf(p.Base(provider.Responses)) { + case "api.openai.com", "chatgpt.com", "api.deepseek.com": + return true + } + return false +} + +// originalAsHigh is a Responses body with each input_image's detail +// "original" sent as "high", the closest an API without it has, as a Chat +// upstream is sent it (chatDetail); the body as it came when it has none. +func originalAsHigh(body []byte) []byte { + if !bytes.Contains(body, []byte(`"original"`)) { + return body + } + out, err := walkImages(provider.Responses, body, func(im imageAt) (json.RawMessage, error) { + var block map[string]json.RawMessage + if decodeJSON(im.Block, &block) != nil { + return nil, nil + } + var d string + if decodeJSON(block["detail"], &d) != nil || d != "original" { + return nil, nil + } + block["detail"] = json.RawMessage(`"high"`) + b, err := json.Marshal(block) + if err != nil { + return nil, nil + } + return b, nil + }) + if err != nil { + return body + } + return out +} diff --git a/internal/gateway/image_detail_chat_test.go b/internal/gateway/image_detail_chat_test.go index bea85395e..678d9cce8 100644 --- a/internal/gateway/image_detail_chat_test.go +++ b/internal/gateway/image_detail_chat_test.go @@ -2,7 +2,10 @@ package gateway import ( "encoding/json" + "slices" "testing" + + "github.com/yetone/magpie/internal/provider" ) // chatImageDetails is the detail of every image_url in a Chat body, in @@ -95,3 +98,47 @@ func TestChatImageDetailReachesResponses(t *testing.T) { } } } + +// Codex's screenshot, detail "original", goes to a Responses API other +// than OpenAI's or DeepSeek's own as high, the closest it has: OpenCode +// Go answered 400 "invalid image detail" for DeepSeek V4.1 Flash +// (qiu_eth). The rest of the body goes as it came, low and auto too. +func TestOriginalDetailHighOnARelay(t *testing.T) { + sent := toolImageUp(t, provider.Responses) + img := `"image_url":"data:image/png;base64,` + pngA + `"` + postToolImages(t, "/v1/responses", `{"model":"probe/eye","stream":true,"input":[ + {"role":"user","content":[{"type":"input_text","text":"look"}, + {"type":"input_image","detail":"original",`+img+`}, + {"type":"input_image","detail":"low",`+img+`}]}, + {"type":"function_call","call_id":"c1","name":"view_image","arguments":"{}"}, + {"type":"function_call_output","call_id":"c1","output":[{"type":"input_image","detail":"original",`+img+`}]}, + {"role":"user","content":[{"type":"input_text","text":"and now?"}]}]}`) + var got []string + for _, im := range inputImages(t, sent()) { + d, _ := im["detail"].(string) + got = append(got, d) + } + if want := []string{"high", "low", "high"}; !slices.Equal(got, want) { + t.Errorf("details %q, want %q\n%s", got, want, sent()) + } +} + +// OpenAI's own API, a ChatGPT account's and DeepSeek's take "original"; +// a relay's, OpenCode Go's among them, isn't known to. +func TestTakesOriginalDetail(t *testing.T) { + for base, want := range map[string]bool{ + "https://api.openai.com/v1": true, + "https://chatgpt.com/backend-api/codex": true, + "https://api.deepseek.com/v1": true, + "https://opencode.ai/zen/go/v1": false, + "https://openrouter.ai/api/v1": false, + "": false, + } { + if got := takesOriginalDetail(provider.Provider{ID: "x", Responses: base}); got != want { + t.Errorf("%q: %v, want %v", base, got, want) + } + } + if !takesOriginalDetail(provider.Provider{ID: "x", Preset: provider.RemoteMagpiePreset, Responses: "http://10.0.0.2:3425/v1"}) { + t.Error("a remote magpie decides for its own upstream") + } +}