Please rotate your device

To continue exploring this website, please rotate your device to a vertical orientation

Flux.2 [dev]

black-forest-labs/FLUX.2-dev

High-quality 32B parameter image generation model from Black Forest Labs.

image generation

Generate an image using the OpenAI-compatible images API. The response contains a base64-encoded image.

Input

python
from openai import OpenAI
import base64
import os

client = OpenAI(
    base_url="https://model-{MODEL_ID}.api.baseten.co/production/sync/v1",
    api_key=os.environ["BASETEN_API_KEY"],
)

response = client.images.generate(
    model="flux2-dev",
    prompt="A cat holding a sign that says Hello World",
    n=1,
    size="1024x1024",
    response_format="b64_json",
    extra_body={
        "num_inference_steps": 50,
        "guidance_scale": 1.0,
    },
)

# Decode and save the image
img_data = base64.b64decode(response.data[0].b64_json)
with open("flux2_output.png", "wb") as f:
    f.write(img_data)

Output

json
{
  "created": 1234567890,
  "data": [
    {
      "b64_json": "iVBORw0KGgoAAAANSUhEUgAABAAAAAQA..."
    }
  ]
}