Flux-2 Klein-4b Serverless API

FLUX.2 [klein] delivers photorealistic image generation and editing with sub-second latency on consumer hardware.

~10.93s
~$0.033
 1import requests
 2import json
 3
 4url = "https://api.segmind.com/v1/flux-2-klein-4b"
 5headers = {
 6    "x-api-key": "YOUR_API_KEY",
 7    "Content-Type": "application/json"
 8}
 9
10data = {
11    "prompt": "A humanoid figure with a vintage television for a head, its green screen displaying 'FLUX.2 Klein on Segmind' in ASCII text. Wearing a yellow raincoat with wires and components trailing from the TV set",
12    "image_urls": [],
13    "negative_prompt": "low quality, blurry, less details",
14    "seed": 3425234,
15    "cfg": 5,
16    "sampler": "euler",
17    "steps": 20,
18    "aspect_ratio": "1:1",
19    "go_fast": true,
20    "image_format": "png",
21    "quality": 90
22}
23
24response = requests.post(url, headers=headers, json=data)
25
26if response.status_code == 200:
27    result = response.json()
28    print(json.dumps(result, indent=2))
29else:
30    print(f"Error: {response.status_code}")
31    print(response.text)

API Endpoint

POSThttps://api.segmind.com/v1/flux-2-klein-4b

Parameters

promptrequired
string

Prompt describing the image to generate

aspect_ratiooptional
string

Aspect ratio of the output image

Default: "1:1"
Allowed values (11 total):
"match_input_image""1:1""2:3""3:2""3:4""4:3""4:5""5:4""9:16""16:9"+1 more
cfgoptional
number

Classifier-free guidance scale

Default: 5Range: 1 - 20
go_fastoptional
boolean

Enable fast generation mode

Default: true
image_formatoptional
string

Output image format

Default: "png"
Allowed values :
"png""jpeg""webp"
image_urlsoptional
string[]

Add a reference image or leave blank for original ideas(text to image mode.

negative_promptoptional
string

Negative prompt to avoid certain elements

Default: "low quality, blurry, less details"
qualityoptional
integer

Output image quality

Default: 90Range: 10 - 100
sampleroptional
string

Sampling method

Default: "euler"
Allowed values :
"euler""res_2s"
seedoptional
integer

Random seed for reproducibility

Default: 3425234
stepsoptional
integer

Number of inference steps

Default: 20Range: 1 - 100

Response Type

Returns: Image

Common Error Codes

The API returns standard HTTP status codes. Detailed error messages are provided in the response body.

400

Bad Request

Invalid parameters or request format

401

Unauthorized

Missing or invalid API key

403

Forbidden

Insufficient permissions

404

Not Found

Model or endpoint not found

406

Insufficient Credits

Not enough credits to process request

429

Rate Limited

Too many requests

500

Server Error

Internal server error

502

Bad Gateway

Service temporarily unavailable

504

Timeout

Request timed out