• featured
flux2-klein-4b Robot

FLUX Klein

The FLUX.2 [klein] model family are our fastest image models to date. FLUX.2 [klein] unifies generation and editing in a single compact architecture, delivering state-of-the-art quality with end-to-end inference in as low as under a second.

$0.003/IMAGE

Input

quick start
The Neon Monk
Desert Solitude
The Lunar Moth
Translucent Ocean
The Midnight Witness
World Tree Portal
The Golden Veil
The Floating Museum
Micro Medieval Battle
The Porcelain Android

Output

Klein API Reference

Overview

The Klein API provides a synchronous interface for generating high-quality images from text prompts and reference images. All generation workflows are accessed through a single endpoint. The API automatically selects the appropriate workflow based on the number of reference images provided:

  • 0 images → Text-to-image generation
  • 1 image → Image-to-image editing
  • 2–4 images → Multi-reference generation

Authentication

All requests to the API must include a Bearer token in the Authorization header.

Example header:
Authorization: Bearer YOUR_API_KEY

Endpoint

POST /v1/generate

Generates or edits an image based on a text prompt and optional reference images. Uses multipart/form-data content type.

Field Type Required Default Description
prompt string Yes - The text description of the image to generate.
model string No flux2-klein-4b Model identifier. Use flux2-klein-4b.
aspect_ratio string No landscape The desired aspect ratio for the output image. Valid values: square, landscape, portrait, photo, photo_v, standard, standard_v, wide.
images file[] No [] Uploaded image files to use as references. Takes priority over image_uris.
image_uris string No - A JSON array of URLs or base64 data URIs of the reference images.

Workflow Selection

The workflow is automatically determined by the total number of reference images (from images and image_uris combined):

Reference Images Workflow Description
0 Text-to-image Generates an image purely from the text prompt.
1 Image-to-image Edits a single reference image based on the text prompt.
2–4 Multi-reference Generates an image using multiple references and the text prompt.

cURL Examples

Text-to-image (no images):

bash Copy
curl -X POST https://us-01.bytecompute.ai/v1/generate \
  -H "Authorization: Bearer " \
  -F "prompt=A futuristic city with neon lights" \
  -F "model=flux2-klein-4b" \
  -F "aspect_ratio=square"

Image-to-image (1 image):

bash Copy
curl -X POST https://us-01.bytecompute.ai/v1/generate \
  -H "Authorization: Bearer " \
  -F "prompt=A cat wearing a space suit" \
  -F "model=flux2-klein-4b" \
  -F "images=@/path/to/your/image.png" \
  -F "aspect_ratio=portrait"

Multi-reference (2+ images):

bash Copy
curl -X POST https://us-01.bytecompute.ai/v1/generate \
  -H "Authorization: Bearer " \
  -F "prompt=A hybrid of these two animals" \
  -F "model=flux2-klein-4b" \
  -F "images=@/path/to/image1.png" \
  -F "images=@/path/to/image2.png" \
  -F "aspect_ratio=landscape"

Response

The response body contains the raw PNG bytes of the generated image with a Content-Type of image/png.

Response headers:

  • X-Generation-Id: Unique identifier for the generation.
  • X-Generation-Time: Time taken to generate the image in seconds.
  • X-Resolution: Resolution of the generated image.
  • X-Model: Model identifier used.
  • X-Workflow: Workflow that was selected (t2i, i2i, or multi-ref).
  • X-Reference-Count: The number of reference images used (only present when images are provided).

Error Responses

The API uses standard HTTP status codes to indicate the success or failure of a request. Errors are returned in a unified JSON format.

json Copy
{
  "detail": "Error message description"
}

Status codes:

  • 401 Unauthorized: Authentication failed due to a missing or invalid API key.
  • 422 Unprocessable Entity: The request parameters failed validation.
  • 504 Gateway Timeout: The generation process exceeded the allowed time limit.
  • 500 Internal Server Error: An unexpected error occurred on the server.

Limits

Limit Value
Maximum Reference Images 4

Available aspect ratios and their corresponding resolutions:

Aspect Ratio Resolution
square 1024 x 1024
landscape 1344 x 768
portrait 768 x 1344
photo 1248 x 832
photo_v 832 x 1248
standard 1184 x 896
standard_v 896 x 1184
wide 1568 x 672

Unlock the most affordable AI hosting

Run models at scale with our fully managed GPU infrastructure, delivering enterprise-grade uptime at the industry's best rates.

Contact Sales