Skip to content

fix(ai): resolve missing multipart boundary in toMarkdown transform#2779

Open
Ahmedhajjajofficial wants to merge 0 commit into
cloudflare:mainfrom
Ahmedhajjajofficial:main
Open

fix(ai): resolve missing multipart boundary in toMarkdown transform#2779
Ahmedhajjajofficial wants to merge 0 commit into
cloudflare:mainfrom
Ahmedhajjajofficial:main

Conversation

@Ahmedhajjajofficial

Copy link
Copy Markdown

Description

This PR resolves the 400 {"errors":[{"message":"Request body is not valid multipart/form-data"}]} error when calling the cloudflare.ai.toMarkdown.transform method.

Root Cause

In certain runtime environments (like Node.js), passing a standard FormData instance directly into the internal HTTP fetch wrapper causes a boundary mismatch. The internal request layer hardcodes the content-type: multipart/form-data header without appending the dynamically generated boundary string (e.g., boundary=----WebKitFormBoundary...), causing Cloudflare Gateway to reject the payload immediately.

Solution

Instead of transmitting the raw FormData object, we pipe it into a native Response constructor inside the transform method. This forces the underlying V8/Node engine to serialize the payload and accurately construct a spec-compliant content-type header that includes the official boundary token. We then extract this complete header and apply it explicitly to the final request payload.

Verification

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant