fix(openai): default DeepSeek effort to high in the Anthropic bridge

Without a client effort, the Anthropic bridge sends `medium`. DeepSeek's
reasoning scale is low/high/max, as the Codex manifest already declares,
and DeepSeek-V4.1 rejects `medium`. Every Anthropic-format request without
an explicit effort therefore failed on DeepSeek models. The bridge now
sends DeepSeek's default level instead. Explicit efforts, disabled thinking
and other models are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
pood1eandClaude Opus 5.5 committed 2026-11-25 06:40:19 -08:00
1 parent 0f66714571
commit 2945ecf89b
3 files changed
+60 -2

No files matched your search

@@ -455,7 +455,7 @@ func newConfiguredCodexModelDescriptor(modelID string) configuredCodexModelDescr
}
if isDeepSeekCodexModel(modelID) {
defaultReasoningLevel := "high"
defaultReasoningLevel := deepSeekDefaultReasoningEffort
descriptor.DisplayName = deepSeekCodexDisplayName(modelID)
descriptor.Description = "DeepSeek coding and reasoning model routed through Sub2API."
descriptor.DefaultReasoningLevel = &defaultReasoningLevel
@@ -790,6 +790,10 @@ func deepSeekCodexDisplayName(modelID string) string {
}
}
// deepSeekDefaultReasoningEffort is the default level of DeepSeek's
// low/high/max reasoning scale.
const deepSeekDefaultReasoningEffort = "high"
func isDeepSeekCodexModel(modelID string) bool {
return strings.HasPrefix(strings.ToLower(strings.TrimSpace(modelID)), "deepseek-")
}
@@ -135,7 +135,15 @@ func openAICompatAnthropicReasoningEffort(req *apicompat.AnthropicRequest, upstr
if convertedEffort == "none" {
return convertedEffort
}
if req == nil || req.OutputConfig == nil || !strings.EqualFold(strings.TrimSpace(req.OutputConfig.Effort), "max") {
if req == nil || req.OutputConfig == nil || strings.TrimSpace(req.OutputConfig.Effort) == "" {
// Without a client preference the bridge sends medium. DeepSeek's scale
// is low/high/max and has no medium, so send DeepSeek's default instead.
if convertedEffort == "medium" && isDeepSeekCodexModel(upstreamModel) {
return deepSeekDefaultReasoningEffort
}
return convertedEffort
}
if !strings.EqualFold(strings.TrimSpace(req.OutputConfig.Effort), "max") {
return convertedEffort
}
if normalized := normalizeOpenAIReasoningEffortForModel(req.OutputConfig.Effort, upstreamModel); normalized != "" {
@@ -153,6 +153,52 @@ func TestMessagesEffortPolicyHTTP(t *testing.T) {
}
}
func TestMessagesDeepSeekDefaultEffort(t *testing.T) {
gin.SetMode(gin.TestMode)
const model = "deepseek-v4.1-flash"
for _, chat := range []bool{false, true} {
for _, test := range []struct {
name string
preference string
want string
}{
{name: "omitted uses DeepSeek default", want: "high"},
{name: "enabled thinking uses DeepSeek default", preference: `,"thinking":{"type":"enabled","budget_tokens":1024}`, want: "high"},
{name: "adaptive thinking uses DeepSeek default", preference: `,"thinking":{"type":"adaptive"}`, want: "high"},
{name: "explicit low preserved", preference: `,"output_config":{"effort":"low"}`, want: "low"},
{name: "explicit medium preserved", preference: `,"output_config":{"effort":"medium"}`, want: "medium"},
{name: "explicit max preserved", preference: `,"output_config":{"effort":"max"}`, want: "max"},
} {
t.Run(fmt.Sprintf("chat=%t/%s", chat, test.name), func(t *testing.T) {
account := rawGPT56ResponsesAPIKeyAccount(model, model)
endpoint, effortPath := "/responses", "reasoning.effort"
response := openAICompatSSECompletedResponse("resp_effort", model)
if chat {
account.Extra = map[string]any{openai_compat.ExtraKeyResponsesMode: string(openai_compat.ResponsesSupportModeForceChatCompletions)}
endpoint, effortPath = "/chat/completions", "reasoning_effort"
payload := `{"id":"chat_effort","model":"` + model + `","choices":[{"index":0,"message":{"role":"assistant","content":"ok"},"finish_reason":"stop"}],"usage":{"prompt_tokens":5,"completion_tokens":2}}`
response = &http.Response{StatusCode: 200, Header: http.Header{"Content-Type": []string{"application/json"}}, Body: io.NopCloser(strings.NewReader(payload))}
}
upstream := &httpUpstreamRecorder{resp: response}
svc := &OpenAIGatewayService{cfg: rawChatCompletionsTestConfig(), httpUpstream: upstream}
body := fmt.Sprintf(`{"model":%q,"max_tokens":1024,"messages":[{"role":"user","content":"Hello"}]%s}`, model, test.preference)
var forwardErr error
router := gin.New()
router.POST("/v1/messages", func(c *gin.Context) {
ctx := WithOpenAIReasoningEffortPolicyForMessages(c.Request.Context(), []byte(body), "", nil, "")
_, forwardErr = svc.ForwardAsAnthropic(ctx, c, account, []byte(body), "", "")
})
recorder := httptest.NewRecorder()
router.ServeHTTP(recorder, httptest.NewRequest(http.MethodPost, "/v1/messages", strings.NewReader(body)))
require.NoError(t, forwardErr)
require.Equal(t, http.StatusOK, recorder.Code, recorder.Body.String())
require.True(t, strings.HasSuffix(upstream.lastReq.URL.Path, endpoint), upstream.lastReq.URL.String())
require.Equal(t, test.want, gjson.GetBytes(upstream.lastBody, effortPath).String())
})
}
}
}
func TestMessagesRawEffortValidation(t *testing.T) {
for _, test := range []struct {
body string