Black Forest Labs logo
fal-ai/flux-2/klein/realtime

Realtime generation with FLUX.2 [klein] from Black Forest Labs.
Inference
Commercial use

About

Realtime image edit (base model, no LoRA).

1. Calling the API#

Install the client#

The client provides a convenient way to interact with the model API.

npm install --save @fal-ai/client

Setup your API Key#

Set FAL_KEY as an environment variable in your runtime.

export FAL_KEY="YOUR_API_KEY"

Real-time via WebSockets#

This model has a real-time mode via WebSockets, supported by fal.realtime.connect.

import { fal } from "@fal-ai/client";

const connection = fal.realtime.connect("fal-ai/flux-2/klein/realtime", {
  onResult: (result) => {
    console.log(result);
  },
  onError: (error) => {
    console.error(error);
  },
  // Fetch short-lived JWT token from your backend
  tokenProvider: async (app) => {
    const response = await fetch("/api/fal/realtime-token", {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify({ app }),
    });
    return response.text();
  },
  tokenExpirationSeconds: 10,
});

connection.send({
  image_url: ""
});

2. Authentication#

The API uses an API Key for authentication. It is recommended you set the FAL_KEY environment variable in your runtime when possible.

API Key#

In an environment where you cannot set environment variables, you can configure the API key manually on the client.
import { fal } from "@fal-ai/client";

fal.config({
  credentials: "YOUR_FAL_KEY"
});

4. Files#

Some attributes in the API accept file URLs as input. Whenever that's the case you can pass your own URL or a Base64 data URI.

Data URI (base64)#

You can pass a Base64 data URI as a file input. The API will handle the file decoding for you. Keep in mind that for large files, this alternative although convenient can impact the request performance.

Hosted files (URL)#

You can also pass your own URLs as long as they are publicly accessible. Be aware that some hosts might block cross-site requests, rate-limit, or consider the request as a bot.

Uploading files#

We provide a convenient file storage that allows you to upload files and use them in your requests. You can upload files using the client API and use the returned URL in your requests.

import { fal } from "@fal-ai/client";

const file = new File(["Hello, World!"], "hello.txt", { type: "text/plain" });
const url = await fal.storage.upload(file);

Read more about file handling in our file upload guide.

5. Schema#

Input#

image_size ImageSizeEnum

The size of the generated image. square=768x768, square_hd=1024x1024. Default value: "square"

Possible enum values: square, square_hd

output_feedback_strength float

Output feedback loop. 1.0 = pure noise (no feedback), 0.9 = 90% noise + 10% previous output latent. Default value: 1

schedule_mu float

Schedule mu for time shift. 2.3=default, lower=more even denoising, 0.3=nearly linear. Default value: 2.3

prompt string

The prompt to guide image editing. Default value: "Turn this into "Living oil painting, melting gold and sapphire""

seed integer

Random seed for reproducibility. Default value: 35

image_url string* required

Base64-encoded image data URI for editing. CDN URLs are not supported for realtime. For optimal performance, use 704x704 JPEG images with 50% quality. Other sizes will be resized automatically.

enable_interpolation boolean

Enable RIFE frame interpolation between consecutive frames (doubles output frames).

num_inference_steps integer

Default value: 3

{
  "image_size": "square",
  "output_feedback_strength": 1,
  "schedule_mu": 2.3,
  "prompt": "Turn this into a watercolor painting",
  "seed": 35,
  "image_url": "",
  "num_inference_steps": 3
}

Output#

images list<RawImage>* required

Generated images as raw bytes. When interpolation is enabled, returns [interpolated_frame, current_frame] in chronological order. Otherwise returns [current_frame].

seed integer* required

Seed used for generation.

{
  "images": [
    {
      "content_type": "image/jpeg",
      "content": ""
    }
  ]
}

Other types#

RawImage#

height integer* required
content_type string

Default value: "image/jpeg"

content string* required
width integer* required
Flux 2 [klein] Realtime Image to Image API Docs | fal