Skip to content
Cloudflare Docs
Black Forest Labs logo

flux-2-klein-4b

Text-to-ImageBlack Forest Labs
@cf/black-forest-labs/flux-2-klein-4b

FLUX.2 [klein] is an ultra-fast, distilled image model. It unifies image generation and editing in a single model, delivering state-of-the-art quality enabling interactive workflows, real-time previews, and latency-critical applications.

Model Info
Terms and Licenselink
PartnerYes
Unit Pricing$0.000059 per input 512x512 tile, $0.000287 per output 512x512 tile

Usage

Workers - TypeScript

TypeScript
export interface Env {
AI: Ai;
}
export default {
async fetch(request, env): Promise<Response> {
const form = new FormData();
form.append('prompt', 'a sunset with a dog');
form.append('width', '1024');
form.append('height', '1024');
const resp = await env.AI.run("@cf/black-forest-labs/flux-2-klein-4b", {
multipart: {
body: formStream,
contentType: formContentType
}
});
return Response.json(resp);
},
} satisfies ExportedHandler<Env>;

curl

Terminal window
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 steps=25 \
--form width=1024 \
--form height=1024

Parameters

* indicates a required field

Input

  • multipart object required

    • body object

    • contentType string

Output

  • image string

    Generated image as Base64 string.

API Schemas

The following schemas are based on JSON Schema

{
"type": "object",
"properties": {
"multipart": {
"type": "object",
"properties": {
"body": {
"type": "object"
},
"contentType": {
"type": "string"
}
}
}
},
"required": [
"multipart"
]
}