Black Forest Labs

black-forest-labs/flux-2-klein-9b/text-to-image

Text to Image

Black Forest Labs FLUX.2 Klein 9B is the compact FLUX.2 model, built for fast, low-cost images with sharp realism and clean text. Use 4 to 8 steps for quick drafts and high-volume work, with six size presets, PNG, JPEG or WebP output and up to 4 images per call.

More settings (4)
ResultExampleSign in to try

$0.006 / megapixel · billed by each image's actual pixels

FLUX.2 Klein 9B Text to Image example
Example — generated from this input

A golden retriever puppy wearing tiny yellow rain boots splashes through a puddle on a cobblestone street just after rain, ears flying, droplets frozen in the air. Soft morning light, reflections in the wet stones, shallow depth of field, crisp photographic detail.

Pricing

Unit price $0.006 / megapixel

Billed by the actual pixels of each image; larger sizes and more images cost more. 1024×1024 is about 1 megapixel.

Typically about $0.0045 per image at default settings.

Each request temporarily reserves $0.0045; you are charged for actual usage, usually within a minute: any unused amount is released and any usage above it is charged to your balance, even if that takes it below zero; while your balance is below zero, new requests are paused until a top-up covers it.

Failed generations are not charged.

API

Submit generation requests with this model ID.

POST/v1/model-tasks
black-forest-labs/flux-2-klein-9b/text-to-image
Request body
{
  "model": "black-forest-labs/flux-2-klein-9b/text-to-image",
  "input": {
    "prompt": "A golden retriever puppy wearing tiny yellow rain boots splashes through a puddle on a cobblestone street just after rain, ears flying, droplets frozen in the air. Soft morning light, reflections in the wet stones, shallow depth of field, crisp photographic detail.",
    "image_size": "landscape_4_3",
    "num_images": 1,
    "num_inference_steps": 4,
    "output_format": "png"
  }
}

Input schema

ParameterTypeRequirementDefault
promptstringRequired—
image_sizeobject | stringOptionallandscape_4_3
num_imagesintegerOptional1
num_inference_stepsintegerOptional4
output_formatstringOptionalpng
seedintegerOptional—

Response

The API returns a result or a pollable asynchronous task. See the examples and Schema below for the response mode and result fields.

Asynchronous task
Submit response
HTTP 202
/v1/model-tasksapplication/json
{
  "id": "task_example",
  "model": "black-forest-labs/flux-2-klein-9b/text-to-image",
  "status": "queued"
}
Status response
HTTP 200
/v1/model-tasks/{id}application/json
{
  "id": "task_example",
  "model": "black-forest-labs/flux-2-klein-9b/text-to-image",
  "status": "completed",
  "output": {
    "images": [
      {
        "url": "https://api.musespan.com/v1/model-tasks/task_example/artifacts/0"
      }
    ]
  }
}
File download
HTTP 200
/v1/model-tasks/{id}/artifacts/{index}Generated image (e.g. image/png)

When the task completes, file URLs in output point to this endpoint, numbered from 0. Send the same API key (Authorization header) when downloading.

Error response
HTTP 400
/v1/model-tasksapplication/json
{
  "error": {
    "code": "invalid_input",
    "message": "The input does not match this model's input schema. Check the model's API documentation.",
    "type": "invalid_request_error"
  }
}

Code examples

Async submission returns a task ID. Poll until status is completed, then retrieve the generated content from the result. Get your API key in the console.

# Use a new directory for each new generation. Rerunning here continues this task.
set -eu
test -s model-task-id.txt || python3 -c "import uuid; print(uuid.uuid4())" > model-task-id.txt
REQUEST_ID=$(cat model-task-id.txt)
# Idempotent: resending the same bytes with the same ID never charges twice.
curl --fail-with-body --retry 3 --retry-connrefused --request POST 'https://api.musespan.com/v1/model-tasks' \
  --header "Authorization: Bearer $MUSESPAN_API_KEY" \
  --header "X-Request-Id: $REQUEST_ID" \
  --header "Content-Type: application/json" \
  --data '{"model":"black-forest-labs/flux-2-klein-9b/text-to-image","input":{"prompt":"A golden retriever puppy wearing tiny yellow rain boots splashes through a puddle on a cobblestone street just after rain, ears flying, droplets frozen in the air. Soft morning light, reflections in the wet stones, shallow depth of field, crisp photographic detail.","image_size":"landscape_4_3","num_images":1,"num_inference_steps":4,"output_format":"png"}}'
# Poll every 5 seconds for up to 25 minutes until status is completed or failed.
# Still queued (with queue_position) 5 minutes after submission: failed with queue_timeout, not charged.
# No result 15 minutes after acceptance (or no confirmation 15 minutes after submission): failed with generation_timeout, not charged.
# Any failure is final: generate again in a new directory (a new X-Request-Id).
# A 404 means the POST did not arrive: rerun this script to resend it with the same ID.
curl --fail-with-body 'https://api.musespan.com/v1/model-tasks/'"$REQUEST_ID"'' --header "Authorization: Bearer $MUSESPAN_API_KEY"