Skip to content
This repository was archived by the owner on May 29, 2026. It is now read-only.

Fix generateImage edit mode content type error by using global.fetch for FormData#1914

Merged
pelikhan merged 4 commits into
devfrom
copilot/fix-101ee3b3-0e67-40f0-9736-fa6738e5bc2d
Sep 3, 2025
Merged

Fix generateImage edit mode content type error by using global.fetch for FormData#1914
pelikhan merged 4 commits into
devfrom
copilot/fix-101ee3b3-0e67-40f0-9736-fa6738e5bc2d

Conversation

Copilot AI commented Aug 29, 2025

Copy link
Copy Markdown

Fixes #1913 where generateImage in edit mode was throwing:

Unsupported content type: 'text/plain'. This API method only accepts 'multipart/form-data' requests, but you specified the header 'Content-Type: text/plain'.

Problem

The OpenAIImageGeneration function was using the createFetch wrapper (cross-fetch) for all requests, including FormData requests in edit mode. Cross-fetch doesn't properly handle FormData content types and defaults to text/plain instead of letting FormData set the proper multipart/form-data boundary.

Solution

Modified the image generation to conditionally use global.fetch for multipart requests (edit mode with FormData) and the createFetch wrapper for JSON requests (generate mode):

// TODO: switch back to cross-fetch in the future  
const res = isMultipart ? await global.fetch(url, freq as any) : await fetch(url, freq as any);

This follows the same pattern already used in other parts of the codebase (WhisperASR transcription, speech generation) where FormData requires proper handling.

Testing

  • Enhanced test/image-generation.test.ts with new test cases for both edit and generate modes
  • All existing image generation tests continue to pass (17/17)
  • Core packages build successfully with no breaking changes

The fix is minimal and surgical, maintaining backward compatibility while resolving the regression that broke image editing functionality.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • cdn.sheetjs.com
    • Triggering command: node /home/REDACTED/.local/share/pnpm/.tools/pnpm/10.12.3/bin/pnpm install (dns block)
  • esm.ubuntu.com
    • Triggering command: /usr/lib/apt/methods/https (dns block)
  • example.com
    • Triggering command: node (vitest 3) (dns block)
  • https://api.github.com/markdown
    • Triggering command: node (vitest 3) (http block)
  • https://api.github.com/repos/microsoft/genaiscript/branches
    • Triggering command: node (vitest 3) (http block)
  • https://api.github.com/repos/microsoft/genaiscript/contents/README.md
    • Triggering command: node (vitest 3) (http block)
  • https://api.github.com/repos/microsoft/genaiscript/contents/packages%2Fcore%2Fsrc
    • Triggering command: node (vitest 3) (http block)
  • https://api.github.com/repos/microsoft/genaiscript/git/blobs
    • Triggering command: node (vitest 3) (http block)
  • https://api.github.com/repos/microsoft/genaiscript/git/ref/heads%2Ftest-ignore
    • Triggering command: node (vitest 3) (http block)
  • https://api.github.com/repos/microsoft/genaiscript/issues
    • Triggering command: node (vitest 3) (http block)
  • https://api.github.com/repos/microsoft/genaiscript/labels
    • Triggering command: node (vitest 3) (http block)
  • https://api.github.com/repos/microsoft/genaiscript/languages
    • Triggering command: node (vitest 3) (http block)
  • https://api.github.com/repos/microsoft/genaiscript/pulls
    • Triggering command: node (vitest 3) (http block)
  • https://api.github.com/repos/microsoft/genaiscript/pulls/999999
    • Triggering command: node (vitest 2) (http block)
  • https://api.github.com/test
    • Triggering command: node (vitest 3) (http block)
  • microsoft.github.io
    • Triggering command: node (vitest 1) (dns block)
    • Triggering command: node (vitest 3) (dns block)
  • telemetry.astro.build

If you need me to access, download, or install something from one of these locations, you can either:


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…for FormData

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Investigate https://github.com/microsoft/genaiscript/issues/1913 and fix the issue. Fix generateImage edit mode content type error by using global.fetch for FormData Aug 29, 2025
Copilot AI requested a review from pelikhan August 29, 2025 20:16
@pelikhan pelikhan marked this pull request as ready for review August 30, 2025 00:27
@github-actions

Copy link
Copy Markdown
Contributor

Warning

LLM error (403): error

AI-generated content by docs may be incorrect.

@pelikhan pelikhan merged commit 09d5cf7 into dev Sep 3, 2025
9 of 10 checks passed
@pelikhan pelikhan deleted the copilot/fix-101ee3b3-0e67-40f0-9736-fa6738e5bc2d branch September 3, 2025 04:50
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants