fix(images): 规范 OpenAI 图像尺寸参数

This commit is contained in:
2026-07-24 09:28:18 +08:00
parent 8df87875de
commit 36d1b18e10
2 changed files with 83 additions and 4 deletions
+19
View File
@@ -65,6 +65,7 @@ func (c OpenAIClient) Run(ctx context.Context, request Request) (Response, error
}
}
body["model"] = upstreamModelName(request.Candidate)
normalizeOpenAIImageRequestBody(endpointKind, body)
stream := openAIEndpointSupportsStream(endpointKind) && (request.Stream || boolValue(body, "stream"))
ensureOpenAIStreamUsage(body, endpointKind, stream)
raw, contentType, err := openAIRequestPayload(endpointKind, body, request.Candidate)
@@ -171,6 +172,24 @@ func (c OpenAIClient) Run(ctx context.Context, request Request) (Response, error
}, nil
}
func normalizeOpenAIImageRequestBody(endpointKind string, body map[string]any) {
if endpointKind != "images.generations" && endpointKind != "images.edits" {
return
}
// OpenAI image endpoints express output geometry through size. The Gateway
// keeps the generic fields for capability validation and billing, but they
// are not valid OpenAI wire parameters.
for _, key := range []string{
"aspect_ratio",
"aspectRatio",
"resolution",
"width",
"height",
} {
delete(body, key)
}
}
func openAIRequestPayload(endpointKind string, body map[string]any, candidate store.RuntimeModelCandidate) ([]byte, string, error) {
if endpointKind != "images.edits" {
raw, err := json.Marshal(body)