fix(relay): change image[] to image in multipart field name for images/edits - #5331
fix(relay): change image[] to image in multipart field name for images/edits#5331Cokefish9527 wants to merge 1 commit into
Conversation
…s/edits Azure DALL-E /images/edits API requires the multipart file field to be named 'image' (singular), not 'image[]' (PHP array notation). Using 'image[]' causes 'Invalid image file or mode' errors from Azure. This bug was introduced during v1.1.2 gray period (May 25-27, 2026) and carried forward to v1.1.3. Root cause: ConvertImageRequest() in relay/channel/openai/adaptor.go conditionally set fieldName='image[]' when multiple image files were collected from the user's multipart form. Azure's API does not recognize this field naming convention. Fix: Always use fieldName='image' regardless of image count. Investigation report: docs/investigation-gpt-image-2-error-rate.md
WalkthroughThis PR fixes a multipart form field naming bug in Azure DALL-E image edit requests and documents a comprehensive investigation of high error rates in the gpt-image-2 relay. The code change corrects the field name from conditionally using Changesgpt-image-2 Multipart Field Fix and Investigation
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
relay/channel/openai/adaptor.go (1)
284-284:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winUse
common.Unmarshalinstead ofjson.Unmarshal.This line directly calls
json.Unmarshalfromencoding/json, which violates the coding guideline. All JSON unmarshal operations must use the wrapper functioncommon.Unmarshal()fromcommon/json.go.♻️ Proposed fix
- if err := json.Unmarshal(request.THINKING, &thinking); err != nil { + if err := common.Unmarshal(request.THINKING, &thinking); err != nil {As per coding guidelines: All JSON marshal/unmarshal operations MUST use wrapper functions from
common/json.go:common.Marshal(),common.Unmarshal(),common.UnmarshalJsonStr(),common.DecodeJson(), orcommon.GetJsonType(). Do NOT directly import or callencoding/jsonin business code.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@relay/channel/openai/adaptor.go` at line 284, Replace the direct call to encoding/json's json.Unmarshal in the THINKING handling with the project's wrapper common.Unmarshal: call common.Unmarshal(request.THINKING, &thinking) and keep the existing error handling intact; also remove any now-unused encoding/json import if present and ensure the code uses the common/json.go wrapper consistently for JSON operations (reference the current use of json.Unmarshal and the variables request.THINKING and thinking).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/investigation-gpt-image-2-error-rate.md`:
- Around line 36-40: The fenced code block showing the error message lacks a
language identifier; update the markdown block (the triple-backtick block
containing "status_code=400 / Invalid image file...") to include a language
specifier such as "text" (e.g., ```text) so it renders and lints correctly.
---
Outside diff comments:
In `@relay/channel/openai/adaptor.go`:
- Line 284: Replace the direct call to encoding/json's json.Unmarshal in the
THINKING handling with the project's wrapper common.Unmarshal: call
common.Unmarshal(request.THINKING, &thinking) and keep the existing error
handling intact; also remove any now-unused encoding/json import if present and
ensure the code uses the common/json.go wrapper consistently for JSON operations
(reference the current use of json.Unmarshal and the variables request.THINKING
and thinking).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: f2fbca30-5283-4ba0-a32f-959638169a06
📒 Files selected for processing (2)
docs/investigation-gpt-image-2-error-rate.mdrelay/channel/openai/adaptor.go
| ``` | ||
| status_code=400 | ||
| Invalid image file or mode for image 1 (或 image 3), | ||
| please check your image file. | ||
| ``` |
There was a problem hiding this comment.
Add language specifier to fenced code block.
The fenced code block should specify a language identifier for proper rendering and linting compliance.
📝 Proposed fix
-```
+```text
status_code=400
Invalid image file or mode for image 1 (或 image 3),
please check your image file.🧰 Tools
🪛 markdownlint-cli2 (0.22.1)
[warning] 36-36: Fenced code blocks should have a language specified
(MD040, fenced-code-language)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@docs/investigation-gpt-image-2-error-rate.md` around lines 36 - 40, The
fenced code block showing the error message lacks a language identifier; update
the markdown block (the triple-backtick block containing "status_code=400 /
Invalid image file...") to include a language specifier such as "text" (e.g.,
```text) so it renders and lints correctly.
|
Closing: PR should target aiapi114 project, not upstream new-api. |
Summary
Fix
Invalid image file or modeerrors from Azure DALL-E /images/edits API by correcting the multipart form field name fromimage[]toimage.Root Cause
When the
ConvertImageRequest()method constructs multipart form data for the images/edits relay, it usedimage[](PHP array notation) as the field name when multiple image files were collected. Azure's DALL-E API only recognizes the literal field nameimage— theimage[]name causes the API to misinterpret the form structure and returnInvalid image file or modeerrors.Investigation
image(without brackets) worked correctlydocs/investigation-gpt-image-2-error-rate.mdFix
Remove the conditional
image[]branch — always useimageas the multipart file field name.Testing
image(notimage[])imageworked correctly on Azure channelsSummary by CodeRabbit
Bug Fixes
Documentation