mirror of
https://github.com/open-webui/open-webui.git
synced 2026-07-15 21:19:39 -05:00
[PR #24838] fix(images): accept non-standard Content-Type in image generation responses #115194
Reference in New Issue
Block a user
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?
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/24838
Author: @first-it-consulting
Created: 5/17/2026
Status: 🔄 Open
Base:
dev← Head:fix/image-gen-content-type-ndjson-v2📝 Commits (1)
dbb90edfix(images): pass content_type=None to r.json() to accept non-standard MIME types📊 Changes
1 file changed (+5 additions, -5 deletions)
View changed files
📝
backend/open_webui/routers/images.py(+5 -5)📄 Description
Pull Request Checklist
dev.fixChangelog Entry
Description
aiohttp'sClientResponse.json()validates theContent-Typeresponse header against"application/json"by default and raisesContentTypeErrorfor any other value. This silently breaks image generation for backends that return valid JSON with a non-standard MIME type.The immediate trigger: Ollama v0.21.x returns
Content-Type: application/x-ndjsonfrom its OpenAI-compatible/v1/images/generationsendpoint, even though the response body is a single, fully-formed JSON object. Every image generation request via Ollama therefore fails with:The same issue can affect any backend returning valid JSON with a non-standard MIME type (e.g.
text/plain,application/x-ndjson).Fixed
ContentTypeErrorwhen a backend returns valid JSON with a non-standardContent-Typeheader (e.g. Ollama returningapplication/x-ndjson). Fix covers theopenai,gemini, andautomatic1111engines in bothimage_generationsandimage_edits.Technical Details
aiohttp.ClientResponse.json()exposes acontent_typeparameter (default"application/json") for exactly this case. Passingcontent_type=Noneskips the header check while keeping all other parsing behaviour identical — this is the documented aiohttp pattern for lenient content-type handling.Diff: 5 lines changed (one per affected
r.json()call site).Reproduction steps (before fix):
openai, pointapi_base_urlat a local Ollama instance.x/flux2-klein:latest).ContentTypeError: Attempt to decode JSON with unexpected mimetype: application/x-ndjsonVerification (after fix):
Tested against Ollama v0.21.2 with model
x/flux2-klein:latest. The response body ({"created": ..., "data": [{"b64_json": "..."}]}) is parsed correctly and the generated image is returned to the client.Additional Information
Content-Type: application/x-ndjson)Contributor License Agreement
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.