Flux-2 Klein-4b Serverless API
Sub-second photorealistic image generation and editing.
~10.39s
~$0.032
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) 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
POST
https://api.segmind.com/v1/flux-2-klein-4bParameters
promptrequiredstringPrompt describing the image to generate
aspect_ratiooptionalstringAspect 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 morecfgoptionalnumberClassifier-free guidance scale
Default:
5Range: 1 - 20go_fastoptionalbooleanEnable fast generation mode
Default:
trueimage_formatoptionalstringOutput image format
Default:
"png"Allowed values :
"png""jpeg""webp"image_urlsoptionalstring[]Reference image URL. Leave blank for text-to-image generation.
negative_promptoptionalstringNegative prompt to avoid certain elements
Default:
"low quality, blurry, less details"qualityoptionalintegerOutput image quality
Default:
90Range: 10 - 100sampleroptionalstringSampling method
Default:
"euler"Allowed values :
"euler""res_2s"seedoptionalintegerRandom seed for reproducibility
Default:
3425234stepsoptionalintegerNumber of inference steps
Default:
20Range: 1 - 100Response 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