From 8d962ba494ae0adcd745629b1e4bcec1dc839b0e Mon Sep 17 00:00:00 2001 From: lishuangqiang <142634204+lishuangqiang@users.noreply.github.com> Date: Mon, 16 Nov 2026 23:34:25 +0800 Subject: [PATCH] perf(openai): use the validated parse path for chat completions too Same shape as the responses handler: the body is validated at the top of ChatCompletions, the only later rewrite is applyOpenAIReasoningEffortPolicyForRequest (sjson), and the parse error was already being ignored. Nothing between the two points mutates the bytes: parseOpenAICompatibleStream, checkSecurityAudit and tokenInflightEstimate only read them. --- backend/internal/handler/gateway_handler_chat_completions.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/backend/internal/handler/gateway_handler_chat_completions.go b/backend/internal/handler/gateway_handler_chat_completions.go index 0b982a961b..ef54220177 100644 --- a/backend/internal/handler/gateway_handler_chat_completions.go +++ b/backend/internal/handler/gateway_handler_chat_completions.go @@ -174,8 +174,10 @@ func (h *GatewayHandler) ChatCompletions(c *gin.Context) { defer inflightRelease() // Parse request for session hash + // body 已在本函数开头用 gjson.ValidBytes 校验过,之后只经过 sjson 改写 + // (applyOpenAIReasoningEffortPolicyForRequest),合法性保持,因此跳过重复校验。 bodyRef := service.NewRequestBodyRef(body) - parsedReq, _ := service.ParseGatewayRequest(bodyRef, "chat_completions") + parsedReq, _ := service.ParseGatewayRequestValidated(bodyRef, "chat_completions") if parsedReq == nil { parsedReq = &service.ParsedRequest{Model: reqModel, Stream: reqStream, Body: bodyRef} }