Skip to content
Black Forest Labs logo

flux-2-dev

Text-to-ImageBlack Forest LabsHosted

FLUX.2 [dev] is an image model from Black Forest Labs where you can generate highly realistic and detailed images, with multi-reference support.

Model Info
Terms and Licenselink
PartnerYes
Unit Pricing$0.00021 per input 512x512 tile, per step, $0.00041 per output 512x512 tile, per step

Usage

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');
// FormData doesn't expose its serialized body or boundary. Passing it to a
// Request (or Response) 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')!;
const resp = await env.AI.run("@cf/black-forest-labs/flux-2-dev", {
multipart: {
body: formStream,
contentType: formContentType
}
});
return Response.json(resp);
},
} satisfies ExportedHandler<Env>;

Parameters

API Schemas

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