fix openai image request handling

This commit is contained in:
meteor041
2026-04-23 09:53:57 +08:00
parent 6449da6c8d
commit 00778dca31
8 changed files with 484 additions and 20 deletions

View File

@@ -1935,6 +1935,12 @@ func (s *OpenAIGatewayService) Forward(ctx context.Context, c *gin.Context, acco
markPatchSet("instructions", "You are a helpful coding assistant.")
}
if normalizeOpenAIResponsesImageGenerationTools(reqBody) {
bodyModified = true
disablePatch()
logger.LegacyPrintf("service.openai_gateway", "[OpenAI] Normalized /responses image_generation tool payload")
}
// 对所有请求执行模型映射(包含 Codex CLI
billingModel := account.GetMappedModel(reqModel)
if billingModel != reqModel {
@@ -1944,6 +1950,26 @@ func (s *OpenAIGatewayService) Forward(ctx context.Context, c *gin.Context, acco
markPatchSet("model", billingModel)
}
upstreamModel := billingModel
if err := validateOpenAIResponsesImageModel(reqBody, upstreamModel); err != nil {
setOpsUpstreamError(c, http.StatusBadRequest, err.Error(), "")
c.JSON(http.StatusBadRequest, gin.H{
"error": gin.H{
"type": "invalid_request_error",
"message": err.Error(),
"param": "model",
},
})
return nil, err
}
if hasOpenAIImageGenerationTool(reqBody) {
logger.LegacyPrintf(
"service.openai_gateway",
"[OpenAI] /responses image_generation request inbound_model=%s mapped_model=%s account_type=%s",
reqModel,
upstreamModel,
account.Type,
)
}
// OpenAI OAuth 账号走 ChatGPT internal Codex endpoint需要将模型名规范化为
// 上游可识别的 Codex/GPT 系列。API Key 账号则应保留原始/映射后的模型名,