# FLUX.2 \[klein]

### Overview

**FLUX.2 \[klein]** is a family of efficient image generation models from Black Forest Labs, designed for fast inference while maintaining high-quality output. The Klein models are available in both guidance-distilled variants (optimized for speed) and base variants (with configurable guidance), offering flexibility for different use cases.

* **High-quality generation**: Produces high-fidelity images with excellent prompt adherence and detail preservation.
* **Efficient inference**: Guidance-distilled variants (FLUX.2 \[klein] 4B and FLUX.2 \[klein] 9B) enable fast generation with minimal steps.
* **Flexible configuration**: Base variants (FLUX.2 \[klein] Base 4B and FLUX.2 \[klein] Base 9B) support customizable guidance scales and inference steps.
* **Image genration and editing**: Capable of text-to-image, image editing with multiple reference images.

Find out more about [FLUX.2 \[klein\]](https://bfl.ai/blog/flux2-klein-towards-interactive-visual-intelligence)

### Variants

FLUX.2 \[klein] comes in four variants.

**FLUX.2 \[klein] 9B**

The **flagship compact, lightning-fast** 9B-parameter model delivering high-quality text-to-image generation and image editing for real-time creative workflows.

The Verda inference endpoint is **<https://inference.datacrunch.io/flux2-klein-9b/generate>**. See examples below.

**FLUX.2 \[klein] 4B**

The **4-step distilled,** **ultra-fast** variant enabling real-time image generation and editing.

The Verda inference endpoint is **<https://inference.datacrunch.io/flux2-klein-4b/generate>**. The endpoint can be used with examples below by just replacing the endpoint URL.

**FLUX.2 \[klein] Base 4B**

The undistilled version of FLUX.2 \[klein] 4B enabling greater output diversity and flexibility.

The Verda inference endpoint is **<https://inference.datacrunch.io/flux2-klein-base-4b/generate>**. The endpoint can be used with examples below by just replacing the endpoint URL.

**FLUX.2 \[klein] Base 9B**

The full capacity, undistilled version enablin maximum output diversity, flexibility, and control.

The Verda inference endpoint is **<https://inference.datacrunch.io/flux2-klein-base-9b/generate>**. The endpoint can be used with examples below by just replacing the endpoint URL.<br>

### **Getting Started**

Before generating images, make sure your account is ready to use the Inference API. Follow the [Getting Started](https://docs.verda.com/inference/getting-started) guide to create an account and top up your balance.

#### Authorization

To access and use these API endpoints, authorization is required. Please visit our [Authorization page](https://docs.verda.com/inference/authorization) for detailed instructions on obtaining and using a bearer token for secure API access.

### API Details

#### Parameters

**`prompt` (string)**

The text description to generate an image from.\
This is the core input that drives the output.

***

**`width` (integer)**

The width of the output image in pixels.\
**Constraints**: Must be a multiple of 16.\
**Default:** `1024`<br>

***

**`height` (integer)**

The height of the output image in pixels.\
**Constraints**: Must be a multiple of 16.\
**Default:** `768`

***

**`num_steps` (integer)**

How many denoising steps to run during generation.\
More steps may improve quality, at the cost of speed.\
**Default:** Model-dependent

* Guidance-distilled models (FLUX.2\[klein] 4B): `4` (fixed, cannot be changed)
* Base models (FLUX.2\[klein] Base 4B & FLUX.2\[klein] Base 9B): `50` (configurable)

**Note:** For guidance-distilled models, this parameter is fixed and cannot be overridden. Attempting to set a different value will result in an error.

***

**`guidance` (float)**

CFG (Classifier-Free Guidance) controls how closely the image follows the prompt.\
Higher values = stronger prompt adherence, but may reduce creativity.\
**Default:** Model-dependent

* Guidance-distilled models (FLUX.2\[klein] 4B): `1.0` (fixed, cannot be changed)
* Base models (FLUX.2\[klein] Base 4B & FLUX.2\[klein] Base 9B): `4.0` (configurable)

**Note:** For guidance-distilled models, this parameter is fixed and cannot be overridden. Attempting to set a different value will result in an error.

***

**`seed` (integer. optional)**

A seed value for reproducibility.\
The same seed + prompt + model version = same image.\
Use a random value (omit the parameter) to randomize.\
**Default:** Random (if not specified)

***

**`input_images` (array of strings, optional)**

Input images for **image-to-image** generation. Can be provided as:

* URLs (http/https)
* Base64-encoded strings

**Default:** `null` (text-to-image mode)

**Constraints:**

* Maximum 4 images allowed

***

**`enable_safety_checker` (boolean)**

If enabled, content will be checked for safety violations.\
**Default:** `true`

***

**`output_format` (string)**

The file format of the generated image.\
**Possible values:** `"jpeg"`, `"png"`, `"webp"`\
**Default:** `"jpeg"`

***

**`output_quality` (integer)**

Applies to `"jpeg"` and `"webp"` formats.\
Defines compression quality.\
**Range:** `1–100`\
**Default:** `95` (for jpeg/webp)

***

**`enable_base64_output` (boolean)**

If `true`, the API will return the image as a base64-encoded string in a JSON response.\
If `false`, the API will return raw image bytes with metadata in response headers (`X-Seed`, `X-Has-Nsfw-Content`).\
**Default:** `false`

#### Response Format

**JSON Response (when `enable_base64_output=true`)**

```json
{
  "image": "<base64-encoded-image-string>",
  "seed": 12345,
  "has_nsfw_content": false
}
```

**Binary Response (when `enable_base64_output=false`)**

Returns raw image bytes with the following headers:

* `Content-Type`: `image/jpeg`, `image/png`, or `image/webp` (based on `output_format`)
* `X-Seed`: The seed value used for generation
* `X-Has-Nsfw-Content`: `true` or `false` indicating if unsafe content was detected

#### Error Responses

The API may return the following error responses:

* **400 Bad Request**: Invalid parameters (e.g., dimensions not multiple of 16, invalid parameter values for model variant)
* **500 Internal Server Error**: Generation failed
* **503 Service Unavailable**: Model not loaded

Error response format:

```json
{
  "detail": "Error message describing what went wrong"
}
```

### Examples

#### Text to image

Generate an image from a text prompt.

**Endpoint:** `POST /generate`

Example:

{% tabs %}
{% tab title="cURL" %}

```bash
curl --request POST "https://inference.datacrunch.io/flux2-klein-4b/generate" \
  --header "Content-Type: application/json" \
  --header "Authorization: Bearer <your_api_key>" \
  --data '{
    "prompt": "a scientist racoon eating icecream in a datacenter",
    "enable_base64_output": true
  }'
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

token = "<your_api_key>"  # Replace with your actual key
bearer_token = f"Bearer {token}"

url = "https://inference.datacrunch.io/flux2-klein-4b/generate"
headers = {
    "Content-Type": "application/json",
    "Authorization": bearer_token
}
data = {
        "prompt": "a scientist racoon eating icecream in a datacenter",
        "enable_base64_output": True
}

response = requests.post(url, headers=headers, json=data)
print(response.json())
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

const token = '<your_api_key>'; // Replace with your actual token
const url = 'https://inference.datacrunch.io/flux2-klein-4b/generate';
const headers = {
  'Content-Type': 'application/json',
  'Authorization': `Bearer ${token}`
};
const data = {
    prompt: 'a scientist racoon eating icecream in a datacenter',
    enable_base64_output: true
};

axios
  .post(url, data, { headers: headers })
  .then((response) => {
    console.log(response.data);
  })
  .catch((error) => {
    console.error('Error:', error);
  });
```

{% endtab %}
{% endtabs %}

#### Image to image

Generate an image conditioned on one or more input images.

**Endpoint:** `POST /generate`

**Using local image**

Encode the local image to base64 and send it in the JSON Payload

{% tabs %}
{% tab title="cURL" %}

```bash
# Encode the image
INPUT_BASE64=$(base64 -i palm.jpg)

# Write JSON payload to a file
cat > payload.json <<EOF
{
    "prompt": "Add a tresure chest on the beach",
    "input_images": ["${INPUT_BASE64}"],
    "enable_base64_output": true
}
EOF

# Send the request
curl --request POST "https://inference.datacrunch.io/flux2-klein-4b/generate" \
  --header "Content-Type: application/json" \
  --header "Authorization: Bearer <your_api_key>" \
  --data @payload.json
```

{% endtab %}

{% tab title="Python" %}

```python
import requests
import base64

# Load your image as base64 string
with open("palm.jpg", "rb") as image_file:
    input_base64 = base64.b64encode(image_file.read()).decode("utf-8")

token = "<your_api_key>"  # Replace with your actual key
bearer_token = f"Bearer {token}"

url = "https://inference.datacrunch.io/flux2-klein-4b/generate"
headers = {
    "Content-Type": "application/json",
    "Authorization": bearer_token
}
data = {
        "prompt": "Add a tresure chest on the beach",
        "input_images": [input_base64],
        "enable_base64_output": True
}

response = requests.post(url, headers=headers, json=data)
print(response.status_code)
print(response.json())
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');
const fs = require('fs');

// Read image and convert to base64
const imageBase64 = fs.readFileSync('palm.jpg', { encoding: 'base64' });

const token = '<your_api_key>'; // Replace with your actual token
const url = 'https://inference.datacrunch.io/flux2-klein-4b/generate';
const headers = {
  'Content-Type': 'application/json',
  'Authorization': `Bearer ${token}`
};

const data = {
    prompt: 'Add a tresure chest on the beach',
    input_images: [input_base64],
    enable_base64_output: true
};

axios
  .post(url, data, { headers })
  .then((response) => {
    console.log('Response:', response.data);
  })
  .catch((error) => {
    console.error('Error:', error.response?.data || error.message);
  });
```

{% endtab %}
{% endtabs %}

**Using image URLS**

Provide the image urls in the `input_images` parameter.

{% tabs %}
{% tab title="cURL" %}
{% code overflow="wrap" %}

```bash
curl --request \
 POST "https://inference.datacrunch.io/flux2-klein-4b/generate" \
  --header "Content-Type: application/json" \
 --header "Authorization: Bearer <your_api_key>" \
  --data \
 '{
    "prompt": "Colorize the the man in image 1, and put him inside the middle of image 2",
     "input_images": [
      "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/ip_adapter_einstein_base.png",
     "https://timeline.web.cern.ch/sites/default/files/barrel-toroid_0.jpg"
     ],
    "enable_base64_output": true
  }'
```

{% endcode %}
{% endtab %}

{% tab title="Python" %}

```python
import requests
import base64

# Load your image as base64 string
with open("palm.jpg", "rb") as image_file:
    input_base64 = base64.b64encode(image_file.read()).decode("utf-8")

token = "<your_api_key>"  # Replace with your actual key
bearer_token = f"Bearer {token}"

url = "https://inference.datacrunch.io/flux2-klein-4b/generate"
headers = {
    "Content-Type": "application/json",
    "Authorization": bearer_token
}
data = {
        "prompt": "Add a tresure chest on the beach",
        "input_images": [input_base64],
        "enable_base64_output": True
}

response = requests.post(url, headers=headers, json=data)
print(response.status_code)
print(response.json())
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const axios = require('axios');
const fs = require('fs');

const token = '<your_api_key>'; // Replace with your actual token
const url = 'https://inference.datacrunch.io/flux2-klein-4b/generate';
const headers = {
  'Content-Type': 'application/json',
  'Authorization': `Bearer ${token}`
};

const data = {
    prompt: 'Add a tresure chest on the beach',
    input_images: [
    "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/ip_adapter_einstein_base.png",
    "https://timeline.web.cern.ch/sites/default/files/barrel-toroid_0.jpg"
    ],
    enable_base64_output: true
};

axios
  .post(url, data, { headers })
  .then((response) => {
    console.log('Response:', response.data);
  })
  .catch((error) => {
    console.error('Error:', error.response?.data || error.message);
  });
```

{% endtab %}
{% endtabs %}
