fix: remove non-standard thinking/reasoning_max_tokens from Claude-to… (#3667)

This commit is contained in:
woody
2026-04-01 09:40:14 +08:00
committed by GitHub
parent cd8ed99db5
commit 89587c1c9b
8 changed files with 363 additions and 38 deletions

View File

@@ -168,6 +168,8 @@ const (
finishReasonLength = "length"
finishReasonToolCall = "tool_calls"
ctxKeyClaudeBudgetTokens = "claudeBudgetTokens"
ctxKeyClaudeThinkingType = "claudeThinkingType"
ctxKeyIncrementalStreaming = "incrementalStreaming"
ctxKeyApiKey = "apiKey"
CtxKeyApiName = "apiName"
@@ -1155,6 +1157,21 @@ func (c *ProviderConfig) handleRequestBody(
// If main.go detected a Claude request that needs conversion, convert the body
needClaudeConversion, _ := ctx.GetContext("needClaudeResponseConversion").(bool)
if needClaudeConversion {
// Extract thinking config from original Claude body before conversion,
// so downstream providers (OpenRouter, ZhipuAI) can access it.
thinkingType := gjson.GetBytes(body, "thinking.type").String()
if thinkingType == "" {
// Claude request had no thinking field at all - treat as disabled
thinkingType = "disabled"
}
ctx.SetContext(ctxKeyClaudeThinkingType, thinkingType)
// Only extract budget_tokens when thinking is explicitly enabled
if thinkingType == "enabled" {
if budgetTokens := gjson.GetBytes(body, "thinking.budget_tokens").Int(); budgetTokens > 0 {
ctx.SetContext(ctxKeyClaudeBudgetTokens, int(budgetTokens))
}
}
// Convert Claude protocol to OpenAI protocol
converter := &ClaudeToOpenAIConverter{}
body, err = converter.ConvertClaudeRequestToOpenAI(body)