Skip to content

Conversation

@mattrothenberg
Copy link

Summary

  • Fix broken code examples for Flux 2 multipart API in docs
  • Add explanatory comment about why the Response constructor workaround is needed

Problem

The existing code examples for Flux 2 models (dev, klein-4b, klein-9b) don't work. They either:

  1. Reference undefined variables (formStream, formContentType)
  2. Pass FormData directly with a hardcoded "multipart/form-data" content-type

Both approaches fail because the AI API requires the multipart boundary parameter in the Content-Type header to parse the form fields.

Solution

FormData doesn't expose its serialized body or boundary. Passing it to a Response (or Request) constructor serializes it and generates the Content-Type header with the boundary, which is required for the server to parse the multipart fields.

const formResponse = new Response(form);
const formStream = formResponse.body;
const formContentType = formResponse.headers.get('content-type');

Files Changed

  • src/components/models/code/Flux-2.astro - shared code example component
  • src/content/changelog/workers-ai/2026-01-15-flux-2-klein-4b-workers-ai.mdx
  • src/content/changelog/workers-ai/2026-01-28-flux-2-klein-9b-workers-ai.mdx

Testing

Verified all 3 models work with the fixed code:

  • @cf/black-forest-labs/flux-2-dev
  • @cf/black-forest-labs/flux-2-klein-4b
  • @cf/black-forest-labs/flux-2-klein-9b

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants