mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #1026] [Bug]: OpenRouter image generation throws unhelpful errors when response is not the expected chat envelope #499
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#499
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @etherious1804 on GitHub (May 20, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/1026
Summary
generateOpenRouterinpackages/server/src/services/image/image-generation.tsassumes every successful response from OpenRouter's image-generation endpoint is a chat-completions JSON envelope with an extractable image URL. In practice there are at least two shapes that break the path today:Failure modes
Raw image bytes. Some OpenRouter image models (raw provider passthrough) return PNG / JPEG / GIF / WEBP bytes directly with an
image/*content-type instead of a JSON envelope. The currentawait resp.json()call then throwsSyntaxError: Unexpected token ...and the user sees a JSON parse crash instead of the image. There is no way to recover this in user space — the response is being thrown out before any image data is read.JSON envelope with no image (model refusal, text-only response, etc.). The current "no image" error message is just
No image data in OpenRouter response: <first 200 chars>with nofinish_reason, no shape hint, and no log line. There is no way to tell from this error whether the issue is a wrong API key, a model that doesn't support image output, a prompt the model refused, or a misconfiguredmodalitiessetting on the model itself.Gzipped responses. OpenRouter sometimes returns
Content-Encoding: gzipfrom upstream providers. The sharedimageFetchhelper does not setdecodeCompressedResponse: true, so the buffer fails the same JSON-parse path.Proposed fix
Buffer, sniff the content-type + magic bytes, and short-circuit to a base64 image return when the bytes look like an image.errorfield, surface it directly.logger.warn(model,finish_reason, first 800 chars of the message body) and includefinish_reason+ message-object keys in the thrown error.decodeCompressedResponse: trueon the sharedimageFetchhelper so gzipped responses are decoded transparently.Repro
PR coming.