FLUX Text-to-Image Models, Multipart Requests, Reference Images, and Realtime Speech
How to run FLUX.2 Klein and Dev on Workers AI, multipart prompts, multi-reference editing, and Deepgram speech models for voice agents.
This page summarizes Cloudflare Workers AI documentation on running Black Forest Labs FLUX image models at the edge, the multipart request shape those models require, and the Deepgram speech stack used beside them for voice agents. If you only need a quick text prompt to image, you still send multipart form data. If you need live conversation, several speech models use WebSockets only.
FLUX.2 on Workers AI: which model fits your latency and quality trade-off
Section titled “FLUX.2 on Workers AI: which model fits your latency and quality trade-off”Workers AI hosts three closely related text-to-image FLUX.2 variants under the @cf/black-forest-labs/ prefix. They share multi-reference editing (up to four inputs) but differ in speed, tunable steps, and intended workload.
| Model ID | Role | Inference steps | Typical use |
|---|---|---|---|
@cf/black-forest-labs/flux-2-klein-4b |
Fastest distilled Klein | Fixed at 4 (not adjustable) | Rapid prototyping and latency-critical previews |
@cf/black-forest-labs/flux-2-klein-9b |
Higher-quality Klein | Fixed at 4 | Speed and quality together for real-time apps |
@cf/black-forest-labs/flux-2-dev |
Full dev fidelity | Configurable (steps affects quality vs time) |
High-detail assets, JSON-style control, slower runs |
This distilled model offers faster generation and cost-effective pricing, while maintaining great output quality. With a fixed 4-step inference process, Klein 4B is ideal for rapid prototyping and real-time applications where speed matters.
— Cloudflare, Launching FLUX.2 [klein] 4B on Workers AI
FLUX.2 [dev] is an image model from Black Forest Labs where you can generate highly realistic and detailed images, with multi-reference support.
— Cloudflare,
flux-2-devmodel page
Note, this image model is one of the most powerful in the catalog and is expected to be slower than the other image models we currently support.
— Cloudflare, Launching FLUX.2 [dev] on Workers AI
For unit pricing on hosted FLUX models, see Workers AI platform pricing (for example klein-9b is priced per megapixel rather than per step). Third-party catalog entries such as black-forest-labs/flux-2-flex use JSON input and different billing; this page focuses on the @cf/ FLUX.2 models in the cluster.
Older FLUX.1 and SDK shortcuts
Section titled “Older FLUX.1 and SDK shortcuts”@cf/black-forest-labs/flux-1-schnell is an earlier 12B text-to-image model. The Pi AI helper accepts steps for that model, while width, height, seed, and guidance are dropped for flux-1-schnell specifically. FLUX.2 dev and Klein paths documented below use multipart instead.
Multipart env.AI.run() and REST: why a text-only prompt still uses form data
Section titled “Multipart env.AI.run() and REST: why a text-only prompt still uses form data”All three FLUX.2 models in this group take multipart form data inputs even if you only send a prompt. That is the most common integration mistake.
One catch to look out for is that this model takes multipart form data inputs, even if you just have a prompt.
— Cloudflare, Launching FLUX.2 [dev] on Workers AI
REST API: POST /ai/run/{model} with curl
Section titled “REST API: POST /ai/run/{model} with curl”Point at your account and token. Klein 4B example from the klein 4B changelog:
curl --request POST \ --url 'https://api.cloudflare.com/client/v4/accounts/{ACCOUNT}/ai/run/@cf/black-forest-labs/flux-2-klein-4b' \ --header 'Authorization: Bearer {TOKEN}' \ --header 'Content-Type: multipart/form-data' \ --form 'prompt=a sunset at the alps' \ --form width=1024 \ --form height=1024For @cf/black-forest-labs/flux-2-dev, add tunable steps (for example steps=25) in the same multipart request per the dev launch post.
Workers AI binding: FormData, boundary, and multipart option
Section titled “Workers AI binding: FormData, boundary, and multipart option”In a Worker, build FormData, then pass a serialized body and full Content-Type (with boundary) into env.AI.run(). Klein models document using a Response constructor for that serialization:
const form = new FormData();form.append("prompt", "a sunset with a dog");form.append("width", "1024");form.append("height", "1024");
const formResponse = new Response(form);const formStream = formResponse.body;const formContentType = formResponse.headers.get('content-type');
const resp = await env.AI.run("@cf/black-forest-labs/flux-2-klein-9b", { multipart: { body: formStream, contentType: formContentType, },});The same pattern appears across Klein 9B, Klein 4B, and dev announcements. Klein changelogs state that FormData does not expose its boundary unless you serialize through Request or Response; dev examples sometimes used a temporary Request('http://dummy', …) hack—prefer the Response(form) approach where documented for Klein.
Parameters, defaults, and multi-reference input_image_0 … input_image_3
Section titled “Parameters, defaults, and multi-reference input_image_0 … input_image_3”Required: prompt (string).
Optional (all three models): input_image_0 … input_image_3 (binary), guidance (float), width and height (integer, range 256–1920, defaults 1024 and 768), seed (integer).
dev only: steps (integer)—higher values may improve quality at the cost of generation time.
Reference images use the same multipart structure. Names must be exactly input_image_0 through input_image_3; each file must be smaller than 512×512. You may reference slots in the prompt by index or in natural language.
For the prompt, you can reference the images based on the index, like take the subject of image 1 and style it like image 0 or even use natural language like place the dog beside the woman.
— Cloudflare, Launching FLUX.2 [klein] 9B on Workers AI
Example curl with two references (Klein 9B changelog):
curl --request POST \ --url 'https://api.cloudflare.com/client/v4/accounts/{ACCOUNT}/ai/run/@cf/black-forest-labs/flux-2-klein-9b' \ --header 'Authorization: Bearer {TOKEN}' \ --header 'Content-Type: multipart/form-data' \ --form 'prompt=take the subject of image 1 and style it like image 0' \ --form input_image_0=@/path/to/style.png \ --form input_image_1=@/path/to/subject.png \ --form width=1024 \ --form height=1024JSON schemas for each model are linked from the same changelog sections (“JSON Schema for Model”).
Building an image playground and choosing non-FLUX image models
Section titled “Building an image playground and choosing non-FLUX image models”Cloudflare’s Build an AI Image Generator Playground (Part 1) walks through deploying a Workers AI Image Playground in minutes and points to a GitHub repo for local follow-along. That tutorial situates FLUX alongside “the best models in the industry” without self-managing inference.
Other Partner image models on Workers AI include @cf/leonardo/lucid-origin (graphic design and HD renders) and @cf/leonardo/phoenix-1.0 (prompt adherence and text in images), announced in Deepgram and Leonardo partner models. Filter the catalog by Partner on the models page. @cf/lykon/dreamshaper-8-lcm is a photorealism-tuned Stable Diffusion option explored in Explore Workers AI Models Using a Jupyter Notebook.
Realtime speech: Deepgram Flux, Nova-3, Aura, and voice-agent LLMs
Section titled “Realtime speech: Deepgram Flux, Nova-3, Aura, and voice-agent LLMs”A large share of cluster material covers realtime audio on Workers AI—not image generation, but often deployed in the same voice products.
@cf/deepgram/flux (WebSocket-only conversational ASR)
Section titled “@cf/deepgram/flux (WebSocket-only conversational ASR)”@cf/deepgram/flux is automatic speech recognition “built specifically for voice agents.” It is WebSocket-only because it needs live bidirectional streaming for speech activity.
The new Flux model is WebSocket only as it requires live bi-directional streaming in order to recognize speech activity.
— Cloudflare, New Deepgram Flux model available on Workers AI
Worker pattern from the same post:
const resp = await env.AI.run("@cf/deepgram/flux", { encoding: "linear16", sample_rate: "16000"}, { websocket: true});The AI SDK limitations page states that @cf/deepgram/flux only accepts WebSocket connections and throws before a non-WebSocket request is sent; for batch or non-streaming transcription, use @cf/deepgram/nova-3 or @cf/openai/whisper-large-v3-turbo per that note. Model pricing for Flux is listed on its model page (for example per audio minute over WebSocket). Promotional free use in October 2025 ended; see the Workers AI changelog for pricing updates.
Flux is meant to run with Nova-3 (STT) and Aura (TTS) for end-to-end agents:
The Flux model can be used in conjunction with Deepgram’s speech-to-text model @cf/deepgram/nova-3 and text-to-speech model @cf/deepgram/aura-1 to build end-to-end voice agents.
— Cloudflare, New Deepgram Flux model available on Workers AI
Realtime WebSockets API documents Workers AI Deepgram STT/TTS over WebSockets. Aura accepts JSON messages such as Speak and Flush in the partner models announcement. Turn detection for agents uses @cf/pipecat-ai/smart-turn-v2.
Nova-3 transcription in RealtimeKit and PhoneLLM for dialogue
Section titled “Nova-3 transcription in RealtimeKit and PhoneLLM for dialogue”RealtimeKit multilingual transcription routes meeting audio through AI Gateway to Nova-3 on Workers AI. Set ai_config.transcription.language when creating a meeting (for example "fr", regional codes like en-GB, or multi for detection). Ten base languages with regional variants are listed in that post.
For the LLM between STT and TTS, @cf/daily-co/phonellm-mini-alpha-2 targets voice agents that must answer quickly and call tools mid-call. Use env.AI.run() or REST /ai/run with temperature: 0 and chat_template_kwargs: { enable_thinking: false } as Pipecat recommends in that changelog.
Platform limits and common mistakes
Section titled “Platform limits and common mistakes”| Issue | What happens | What to do instead |
|---|---|---|
JSON body to FLUX.2 @cf/ models |
Request does not match documented API | Use multipart per model changelogs |
| Missing multipart boundary in Worker | Server cannot parse fields | Serialize FormData via Response/Request and pass contentType |
| Oversized reference images | Multi-reference fails or is rejected | Keep each input under 512×512 |
| Wrong reference field names | Images ignored | Use input_image_0 … input_image_3 exactly |
steps on Klein |
No effect (fixed pipeline) | Pick dev if you need tunable steps |
HTTP call to @cf/deepgram/flux |
Error before request (per AI SDK note) | websocket: true or pick Nova-3 |
| Dropped Workers AI stream | No resume | Reconnect; streams do not resume per AI SDK limitations |
chatTemplateKwargs and sessionAffinity apply to Workers AI models only in the AI SDK sense; zdr applies to model objects only—see the same limitations page when mixing SDK abstractions with raw env.AI.run().
How to check this on your site
Section titled “How to check this on your site”-
Open the Workers AI models catalog and confirm your target model page (for example flux-2-klein-9b or flux for speech).
-
Compare pricing and parameters on Workers AI platform pricing and the model’s own page.
-
Send a minimal multipart
curlrequest from the relevant changelog post and confirm a successful image response. -
In a deployed Worker, log
formContentTypeand verify it includes aboundary=before callingenv.AI.run()withmultipart. -
You can check automatically in Answerwell (our tool): https://answerwell.org/workspace
Report an error or ask a question
Section titled “Report an error or ask a question”If something on this page does not match your results or the linked Cloudflare docs, email yimasynthetic@gmail.com with the page URL and the exact sentence you think is wrong so it can be corrected.