diff --git a/backend/internal/service/openai_gateway_request_body.go b/backend/internal/service/openai_gateway_request_body.go index e5906c2c66..6267c405c8 100644 --- a/backend/internal/service/openai_gateway_request_body.go +++ b/backend/internal/service/openai_gateway_request_body.go @@ -82,20 +82,11 @@ func shouldPreserveOpenAIResponsesNoneReasoningEffort(account *Account) bool { return baseURL == "" || isOfficialOpenAIModelsBaseURL(baseURL) } -// K3.1 treats none as an explicit unsupported request, not a catalog -// placeholder. Preserve it after resolving aliases so upstream can reject it. -func isKimiK31RequestModel(account *Account, model string) bool { - if account != nil { - model = account.GetMappedModel(model) - } - return isKimiK31Model(model) -} - // Codex 0.149.0 needs a single advertised effort to directly select a visible // non-reasoning model. Treat that catalog-only "none" value as omission for // compatible upstreams, while preserving official OpenAI request semantics. func filterOpenAIResponsesNoneReasoningEffortForAccount(account *Account, body []byte) ([]byte, error) { - if len(body) == 0 || shouldPreserveOpenAIResponsesNoneReasoningEffort(account) || isKimiK31RequestModel(account, gjson.GetBytes(body, "model").String()) { + if len(body) == 0 || shouldPreserveOpenAIResponsesNoneReasoningEffort(account) { return body, nil } @@ -125,9 +116,6 @@ func deleteOpenAIResponsesNoneReasoningEffortFromObject(account *Account, body m if body == nil || shouldPreserveOpenAIResponsesNoneReasoningEffort(account) { return } - if model, _ := body["model"].(string); isKimiK31RequestModel(account, model) { - return - } if effort, ok := body["reasoning_effort"].(string); ok && strings.EqualFold(strings.TrimSpace(effort), "none") { delete(body, "reasoning_effort") } diff --git a/backend/internal/service/openai_kimi_k31_compat_test.go b/backend/internal/service/openai_kimi_k31_compat_test.go index f90d9e4993..77d37b5578 100644 --- a/backend/internal/service/openai_kimi_k31_compat_test.go +++ b/backend/internal/service/openai_kimi_k31_compat_test.go @@ -17,9 +17,10 @@ import ( ) // Exercise the gateway boundaries, not just the effort normalizer: model -// mapping must happen before model-specific effort handling. The fixture -// accepts none so this test can verify that disabled thinking reaches upstream -// unchanged; real K3.1 accounts reject it rather than silently enabling it. +// mapping must happen before model-specific effort handling. On the Responses +// path none is the Codex catalog placeholder and is stripped for compatible +// upstreams, exactly like every other Kimi model, so clients that still hold +// the previous none-only catalog keep working with K3.1's default effort. func TestKimiK31MappedReasoningAcrossProtocols(t *testing.T) { for _, model := range []string{"k3.1-pro", "k3.1-pro-highspeed"} { for _, protocol := range []string{"responses", "chat/completions", "messages"} { @@ -66,6 +67,10 @@ func TestKimiK31MappedReasoningAcrossProtocols(t *testing.T) { require.NotNil(t, upstream.lastReq) require.Equal(t, "/v1/responses", upstream.lastReq.URL.Path) require.Equal(t, model, gjson.GetBytes(upstream.lastBody, "model").String()) + if protocol == "responses" && effort == "none" { + require.False(t, gjson.GetBytes(upstream.lastBody, "reasoning.effort").Exists()) + return + } require.Equal(t, effort, gjson.GetBytes(upstream.lastBody, "reasoning.effort").String()) }) } @@ -73,7 +78,7 @@ func TestKimiK31MappedReasoningAcrossProtocols(t *testing.T) { } } -func TestKimiK31NoneSurvivesBothRequestFilters(t *testing.T) { +func TestKimiK31NoneFollowsCompatibleUpstreamFilters(t *testing.T) { for _, model := range []string{"k3.1-pro", "k3.1-pro-highspeed"} { for _, requested := range []string{model, "public-kimi"} { t.Run(model+"/"+requested, func(t *testing.T) { @@ -83,11 +88,9 @@ func TestKimiK31NoneSurvivesBothRequestFilters(t *testing.T) { require.NoError(t, err) filtered, err := filterOpenAIResponsesNoneReasoningEffortForAccount(account, payload) require.NoError(t, err) - require.JSONEq(t, string(payload), string(filtered)) + require.JSONEq(t, `{"model":"`+requested+`"}`, string(filtered)) deleteOpenAIResponsesNoneReasoningEffortFromObject(account, body) - filtered, err = json.Marshal(body) - require.NoError(t, err) - require.JSONEq(t, string(payload), string(filtered)) + require.Equal(t, map[string]any{"model": requested}, body) }) } }