Get up and running with Kimi, GLM, MiniMax, DeepSeek, gpt-oss, Qwen, Gemma and other models.
proxy: preserve string content during image fallback (#18002)
Parth Sareenebf200f9521d
diff --git a/internal/proxy/claude_desktop.go b/internal/proxy/claude_desktop.goindex 5f1916978..4f7486bb5 100644--- a/internal/proxy/claude_desktop.go+++ b/internal/proxy/claude_desktop.go@@ -900,6 +900,10 @@ func replaceUnsupportedImages(payload map[string]json.RawMessage) (bool, error)func replaceImagesInContent(content json.RawMessage) (json.RawMessage, bool, error) {var blocks []json.RawMessageif err := json.Unmarshal(content, &blocks); err != nil {+ var text string+ if json.Unmarshal(content, &text) == nil {+ return content, false, nil+ }return content, false, fmt.Errorf("decode Claude content for image fallback: %w", err)}diff --git a/internal/proxy/claude_desktop_test.go b/internal/proxy/claude_desktop_test.goindex a890d2130..27b55d520 100644--- a/internal/proxy/claude_desktop_test.go+++ b/internal/proxy/claude_desktop_test.go@@ -1319,6 +1319,16 @@ func TestGatewayLazilyRetriesUnsupportedVision(t *testing.T) {body: `{"model":"glm-5.2:cloud","messages":[{"role":"user","content":[{"type":"image","source":{"type":"base64","media_type":"image/png","data":"aW1hZ2U="}},{"type":"text","text":"what dis"}]},{"role":"assistant","content":[{"type":"text","text":"I cannot inspect it"}]},{"role":"user","content":[{"type":"text","text":"kk"}]}]}`,preserve: "kk",},+ {+ name: "string message history",+ body: `{"model":"glm-5.2:cloud","messages":[{"role":"user","content":"plain history"},{"role":"user","content":[{"type":"image","source":{"type":"base64","media_type":"image/png","data":"aW1hZ2U="}},{"type":"text","text":"what dis"}]}]}`,+ preserve: "plain history",+ },+ {+ name: "string tool result history",+ body: `{"model":"glm-5.2:cloud","messages":[{"role":"user","content":[{"type":"tool_result","tool_use_id":"tool_1","content":"plain tool output"}]},{"role":"user","content":[{"type":"image","source":{"type":"base64","media_type":"image/png","data":"aW1hZ2U="}},{"type":"text","text":"what dis"}]}]}`,+ preserve: "plain tool output",+ },} {t.Run(test.name, func(t *testing.T) {var upstreamBodies [][]byte@@ -1363,6 +1373,13 @@ func TestGatewayLazilyRetriesUnsupportedVision(t *testing.T) {}}+func TestReplaceImagesInContentRejectsUnsupportedShape(t *testing.T) {+ _, _, err := replaceImagesInContent(json.RawMessage(`{"type":"text","text":"not a content array"}`))+ if err == nil {+ t.Fatal("expected unsupported content shape to fail")+ }+}+func TestGatewayDoesNotSanitizeImagesOnSuccessfulRequest(t *testing.T) {var upstreamBodies [][]byteupstream := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {