Text to Image Endpoint
Overview
The Text to Image API is used to create image from text based using flux model. This endpoint generates and returns an image from a text passed in the request body.
Open in Playground 🚀

Request
--request POST 'https://modelslab.com/api/v6/images/text2img' \
Make a POST
request to https://modelslab.com/api/v6/images/text2img endpoint and pass the required parameters as a request body.
Watch the how-to video to see it in action.
Body Attributes
Parameter | Description | Type |
---|---|---|
key | Your API Key used for request authorization. | key |
model_id | The ID of the model. Obtain the model ID from the provided source. | ID |
prompt | A text description of the things you want in the generated image. | string |
negative_prompt | Items you don't want in the image. | string |
width | The width of the image. Maximum value is 1024. | integer |
height | The height of the image. Maximum value is 1024. | integer |
samples | The number of images to be returned in response. The maximum value is 4. | integer |
num_inference_steps | The number of denoising steps. values range from 1 to 20, and any value above 20 will be capped at 20. | |
safety_checker | A checker for NSFW images. If detected, such images will be replaced by a blank image. Default is "yes". Options: "yes"/"no". | string |
safety_checker_type | Modify image if NSFW images are found. Default is "sensitive_content_text". Options: "blur", "sensitive_content_text", "pixelate", "black". | string |
seed | Used to reproduce results. The same seed will generate the same image again. Pass null for a random number. | integer |
guidance_scale | Scale for classifier-free guidance. Minimum value is 1, maximum value is 20. | integer |
injected_noise_alpha | Controls the amount of noise injected into the image generation process. This parameter affects the balance between maintaining the original structure and introducing randomness in the generated images. Default Value: 0.75. Range from 0.0 to 1.0 | float |
sigma_threshold | Determines the noise level threshold at which the image generation process changes its behavior. This parameter affects how the model handles different noise levels during sampling. Default Value: 0.45. Range from 0.0 to 1.0 | float |
true_cfg_scale | Modifies the effective classifier-free guidance scale. This parameter allows for fine-tuning of how strongly the model adheres to the provided prompts. Default Value: 1.0. Valid Range: 0.0 to 10.0 | float |
use_cfg_zero_star | Enables or disables the use of a zero CFG variant for improved stability. This alternative approach can help reduce certain artifacts in the generation process. Default Value: "yes", Valid Values: "yes" or "no | yes/no |
use_zero_init | Controls whether to initialize the diffusion process with zeros instead of random noise. This can affect the starting point of the generation process. Default Value: "no". Valid Values: "yes" or "no | yes/no |
zero_steps | Specifies the number of initial steps to use zero noise initialization if use_zero_init is enabled. Determines how long the model uses zero initialization before switching to standard noise handling. Default Value: 0. Valid Range: 0 to maximum sampling steps (typically 0-50) | integer |
base64 | Get response as a base64 string. Default is no . Options: yes/no . | string |
webhook | Set a URL to receive a POST API call once image generation is complete | URL |
track_id | This ID is returned in the response to the webhook API call and is used to identify the webhook request. | ID |
temp | Create a temporary image link valid for 24 hours. Options: "yes"/"no". | string |
Flux generations
Flux Model (Full HD Quality)
Use Case: High-quality Full HD image generation
Generation Time: 4-5 seconds
Description: The Flux model delivers Full HD images with enhanced visual quality, offering a balance between speed and resolution for high-quality outputs.
Body
Body
{
"key": "",
"model_id": "flux",
"prompt": "ultra realistic close up portrait ((beautiful pale cyberpunk female with heavy black eyeliner)), blue eyes, shaved side haircut, hyper detail, cinematic lighting, magic neon, dark red city, Canon EOS R3, nikon, f/1.4, ISO 200, 1/160s, 8K, RAW, unedited, symmetrical balance, in-frame, 8K",
"width": "512",
"height": "512",
"samples": "1",
"num_inference_steps": "31",
"safety_checker": "no",
"enhance_prompt": "yes",
"seed": null,
"guidance_scale": 7.5,
"tomesd": "yes",
"clip_skip": "2",
"vae": null,
"webhook": null,
"track_id": null
}
Request
- JS
- PHP
- NODE
- PYTHON
- JAVA
var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
var raw = JSON.stringify({
"key": "",
"model_id": "flux",
"prompt": "actual 8K portrait photo of gareth person, portrait, happy colors, bright eyes, clear eyes, warm smile, smooth soft skin, big dreamy eyes, beautiful intricate colored hair, symmetrical, anime wide eyes, soft lighting, detailed face, by makoto shinkai, stanley artgerm lau, wlop, rossdraws, concept art, digital painting, looking into camera",
"width": "512",
"height": "512",
"samples": "1",
"num_inference_steps": "30",
"safety_checker": "no",
"enhance_prompt": "yes",
"seed": null,
"guidance_scale": 7.5,
"self_attention": "no",
"vae": null,
"webhook": null,
"track_id": null
});
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
redirect: 'follow'
};
fetch("https://modelslab.com/api/v6/images/text2img", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
<?php
$payload = [
"key" => "",
"model_id" => "your_model_id",
"prompt" => "actual 8K portrait photo of gareth person, portrait, happy colors, bright eyes, clear eyes, warm smile, smooth soft skin, big dreamy eyes, beautiful intricate colored hair, symmetrical, anime wide eyes, soft lighting, detailed face, by makoto shinkai, stanley artgerm lau, wlop, rossdraws, concept art, digital painting, looking into camera",
"width" => "512",
"height" => "512",
"samples" => "1",
"num_inference_steps" => "30",
"safety_checker" => "no",
"enhance_prompt" => "yes",
"seed" => null,
"guidance_scale" => 7.5,
"vae" => null,
"scheduler" => "UniPCMultistepScheduler",
"webhook" => null,
"track_id" => null
];
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://modelslab.com/api/v6/images/text2img',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => json_encode($payload),
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
var request = require('request');
var options = {
'method': 'POST',
'url': 'https://modelslab.com/api/v6/images/text2img',
'headers': {
'Content-Type': 'application/json'
},
body: JSON.stringify({
"key": "",
"model_id": "flux",
"prompt": "actual 8K portrait photo of gareth person, portrait, happy colors, bright eyes, clear eyes, warm smile, smooth soft skin, big dreamy eyes, beautiful intricate colored hair, symmetrical, anime wide eyes, soft lighting, detailed face, by makoto shinkai, stanley artgerm lau, wlop, rossdraws, concept art, digital painting, looking into camera",
"width": "512",
"height": "512",
"samples": "1",
"num_inference_steps": "30",
"safety_checker": "no",
"enhance_prompt": "yes",
"seed": null,
"guidance_scale": 7.5,
"self_attention": "no",
"vae": null,
"webhook": null,
"track_id": null
})
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
import requests
import json
url = "https://modelslab.com/api/v6/images/text2img"
payload = json.dumps({
"key": "",
"model_id": "flux",
"prompt": "actual 8K portrait photo of gareth person, portrait, happy colors, bright eyes, clear eyes, warm smile, smooth soft skin, big dreamy eyes, beautiful intricate colored hair, symmetrical, anime wide eyes, soft lighting, detailed face, by makoto shinkai, stanley artgerm lau, wlop, rossdraws, concept art, digital painting, looking into camera",
"width": "512",
"height": "512",
"samples": "1",
"num_inference_steps": "30",
"safety_checker": "no",
"enhance_prompt": "yes",
"seed": None,
"guidance_scale": 7.5,
"vae": None,
"lora_strength": None,
"webhook": None,
"track_id": None
})
headers = {
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\n \"key\": \"\",\n \"model_id\": \"your_model_id\",\n \"prompt\": \"actual 8K portrait photo of gareth person, portrait, happy colors, bright eyes, clear eyes, warm smile, smooth soft skin, big dreamy eyes, beautiful intricate colored hair, symmetrical, anime wide eyes, soft lighting, detailed face, by makoto shinkai, stanley artgerm lau, wlop, rossdraws, concept art, digital painting, looking into camera\",\n \"negative_prompt\": \"painting, extra fingers, mutated hands, poorly drawn hands, poorly drawn face, deformed, ugly, blurry, bad anatomy, bad proportions, extra limbs, cloned face, skinny, glitchy, double torso, extra arms, extra hands, mangled fingers, missing lips, ugly face, distorted face, extra legs, anime\",\n \"width\": \"512\",\n \"height\": \"512\",\n \"samples\": \"1\",\n \"num_inference_steps\": \"30\",\n \"safety_checker\": \"no\",\n \"enhance_prompt\": \"yes\",\n \"seed\": null,\n \"guidance_scale\": 7.5,\n \"upscale\": \"no\",\n \"lora_model\" \n \"tomesd\": \"yes\",\n \"vae\": null,\n \"lora_strength\": null,\n \"scheduler\": \"UniPCMultistepScheduler\",\n \"webhook\": null,\n \"track_id\": null\n}");
Request request = new Request.Builder()
.url("https://modelslab.com/api/v6/images/text2img")
.method("POST", body)
.addHeader("Content-Type", "application/json")
.build();
Response response = client.newCall(request).execute();
Response
- Success
- Processing
- Error
{
"status": "success",
"generationTime": 1.9110066890716553,
"id": 12384052,
"output": [
"https://pub-8b49af329fae499aa563997f5d4068a4.r2.dev/generations/4118bb93-2c49-4d1d-9837-f43a0801e42e-0.png"
],
"meta": {
"base64": "no",
"clip_skip": null,
"enhance_prompt": "yes",
"file_prefix": "29396946-e6e7-429d-9eda-7b6095868653",
"guidance_scale": 7.5,
"height": 1024,
"id": "134693666",
"injected_noise_alpha": 0.85,
"instant_response": "no",
"model_id": "flux",
"n_samples": 1,
"negative_prompt": "ugly, low contrast, tiling, poorly drawn hands, poorly drawn feet, poorly drawn face, out of frame, extra limbs, disfigured, deformed, body out of frame, bad anatomy, watermark, signature, cut off, low contrast, underexposed, overexposed, bad art, beginner, amateur, distorted face, blurry, draft, grainy",
"num_inference_steps": 12,
"opacity": 0.8,
"padding_down": 10,
"padding_right": 10,
"prompt": "ultra realistic close up portrait ((beautiful pale cyberpunk female with heavy black eyeliner))",
"rescale": "yes",
"safety_checker": "no",
"safety_checker_type": "black",
"scale_down": 6,
"seed": 2611448049,
"sigma_threshold": 0.45,
"temp": "no",
"track_id": null,
"true_cfg_scale": 1,
"use_cfg_zero_star": true,
"use_zero_init": false,
"watermark": "no",
"webhook": null,
"width": 1024,
"zero_steps": 0
}
}
{
"status": "processing",
"eta": 35,
"messege": "Try to fetch request after seconds estimated",
"fetch_result": "https://modelslab.com/api/v6/images/fetch/1241861",
"id": 13441520,
"output": [],
"future_links": [
"https://pub-8b49af329fae499aa563997f5d4068a4.r2.dev/generations/4118bb93-2c49-4d1d-9837-f43a0801e42e-0.png"
],
"proxy_links": [
"https://cdn2.stablediffusionapi.com/generations/4118bb93-2c49-4d1d-9837-f43a0801e42e-0.png"
],
"meta": {
"base64": "no",
"clip_skip": null,
"enhance_prompt": "yes",
"file_prefix": "29396946-e6e7-429d-9eda-7b6095868653",
"guidance_scale": 7.5,
"height": 1024,
"id": "134693666",
"injected_noise_alpha": 0.85,
"instant_response": "no",
"model_id": "flux",
"n_samples": 1,
"negative_prompt": "ugly, low contrast, tiling, poorly drawn hands, poorly drawn feet, poorly drawn face, out of frame, extra limbs, disfigured, deformed, body out of frame, bad anatomy, watermark, signature, cut off, low contrast, underexposed, overexposed, bad art, beginner, amateur, distorted face, blurry, draft, grainy",
"num_inference_steps": 12,
"opacity": 0.8,
"padding_down": 10,
"padding_right": 10,
"prompt": "ultra realistic close up portrait ((beautiful pale cyberpunk female with heavy black eyeliner))",
"rescale": "yes",
"safety_checker": "no",
"safety_checker_type": "black",
"scale_down": 6,
"seed": 2611448049,
"sigma_threshold": 0.45,
"temp": "no",
"track_id": null,
"true_cfg_scale": 1,
"use_cfg_zero_star": true,
"use_zero_init": false,
"watermark": "no",
"webhook": null,
"width": 1024,
"zero_steps": 0
}
}
{
"status": "error",
"messege": "Error message"
}