Text to Image Endpoint
Overview
Real-Time Text-to-Image API Endpoint
Use Case: Rapid image generation with standard quality.
Open in Playground 🚀Generation Time: 2-3 seconds.
Description: This endpoint delivers fast image generation with normal quality, making it ideal for applications where speed is more critical than high resolution.

Request
--request POST 'https://modelslab.com/api/v6/realtime/text2img' \
Make a POST
request to https://modelslab.com/api/v6/realtime/text2img endpoint and pass the required parameters as a request body.
Watch the Text to Image API Demo video to see it in action Postman.
Body Attributes
Here's the updated documentation for the parameters:
Parameter | Description |
---|---|
key | Your API Key is used for request authorization. https://modelslab.com/dashboard/api-keys Open the given link to view your API KEY. |
prompt | The text prompt provides a description of what you want in the generated image. It tells the AI what to create based on the given instructions. |
negative_prompt | Negative prompts are descriptions of things we don't want in our image. Examples include NSFW content, extra limbs, distorted faces, poor quality, or anything else we want to avoid. |
width | Width define the size of the generated image Width: 1024x1024. |
height | Height define the size of the generated image Height: 1024x1024. |
samples | Number of sample images to be returned in response. The maximum value is 4. |
safety_checker | A NSFW image checker ensures that any inappropriate content detected will be replaced with a blank image to maintain a safe and appropriate browsing experience. default: true , options: true or false . |
seed | The seed is used to reproduce results. Providing the same seed will yield the same image each time. Use "null" for a random number seed. |
instant_response | Enable instant response before processing finishes, eliminating the need to wait for a minimum amount of time. default: false , options: true or false . |
base64 | Get response as base64 string, default: false , options: true or false |
webhook | Assign a URL to receive a POST API call after image generation completes for seamless integration and notification. |
track_id | The track ID is returned in the response to the webhook API call. This will be used to identify the webhook request. |
enhance_prompt | Enhance prompts for better results; options: true or false . |
Example
Body
Body
{
"key": "",
"prompt": "ultra realistic close up portrait ((beautiful pale cyberpunk female with heavy black eyeliner))",
"negative_prompt": "bad quality",
"width": "512",
"height": "512",
"safety_checker": false,
"seed": null,
"samples": 1,
"base64": false,
"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: '',
prompt:
'ultra realistic close up portrait ((beautiful pale cyberpunk female with heavy black eyeliner))',
negative_prompt: 'bad quality',
width: '512',
height: '512',
safety_checker: false,
seed: null,
samples: 1,
base64: false,
webhook: null,
track_id: null,
});
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
redirect: 'follow',
};
fetch('https://modelslab.com/api/v6/realtime/text2img', requestOptions)
.then((response) => response.text())
.then((result) => console.log(result))
.catch((error) => console.log('error', error));
<?php
$payload = [
"key" => "",
"prompt" => "ultra realistic close up portrait ((beautiful pale cyberpunk female with heavy black eyeliner))",
"negative_prompt" => "bad quality",
"width" => "512",
"height" => "512",
"safety_checker" => false,
"seed" => null,
"samples" => 1,
"base64" => false,
"webhook" => null,
"track_id" => null
];
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://modelslab.com/api/v6/realtime/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/realtime/text2img',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
key: '',
prompt:
'ultra realistic close up portrait ((beautiful pale cyberpunk female with heavy black eyeliner))',
negative_prompt: 'bad quality',
width: '512',
height: '512',
safety_checker: false,
seed: null,
samples: 1,
base64: false,
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/realtime/text2img"
payload = json.dumps({
"key" : "",
"prompt": "ultra realistic close up portrait ((beautiful pale cyberpunk female with heavy black eyeliner))",
"negative_prompt": "bad quality",
"width": "512",
"height": "512",
"safety_checker": False,
"seed": None,
"samples":1,
"base64":False,
"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 \"prompt\": \"Black african wearing a suit in a corporate meeting\",\n \"negative_prompt\": \"bad quality\",\n \"width\": \"512\",\n \"height\": \"512\",\n \"safety_checker\": false,\n \"seed\": 2345,\n \"sample\":1,\n \"webhook\": \"\",\n \"track_id\": 20\n}");
Request request = new Request.Builder()
.url("https://modelslab.com/api/v6/realtime/text2img")
.method("POST", body)
.addHeader("Content-Type", "application/json")
.build();
Response response = client.newCall(request).execute();
Response
- Success
- Processing
- Error
{
"status": "success",
"generationTime": 1.06,
"id": 91753437,
"output": [
"https://pub-3626123a908346a7a8be8d9295f44e26.r2.dev/generations/f20412ca-cb22-4e77-9b75-26ddbad5a4e5-0.png"
],
"proxy_links": [
"https://cdn2.stablediffusionapi.com/generations/f20412ca-cb22-4e77-9b75-26ddbad5a4e5-0.png"
],
"meta": {
"base64": "no",
"enhance_prompt": "no",
"file_prefix": "f20412ca-cb22-4e77-9b75-26ddbad5a4e5",
"guidance_scale": 1,
"height": 512,
"instant_response": "no",
"n_samples": 1,
"negative_prompt": "bad quality",
"outdir": "out",
"prompt": "ultra realistic close up portrait ((beautiful pale cyberpunk female with heavy black eyeliner))",
"safety_checker": "no",
"safety_checker_type": "black",
"seed": 3977575608,
"temp": "no",
"width": 512
}
}
{
"status": "processing",
"eta": 35,
"message": "Try to fetch request after seconds estimated",
"fetch_result": "https://modelslab.com/api/v6/realtime/fetch/1241861",
"id": 1241861,
"output": [],
"future_links": [
"https://pub-3626123a908346a7a8be8d9295f44e26.r2.dev/generations/f20412ca-cb22-4e77-9b75-26ddbad5a4e5-0.png"
],
"proxy_links": [
"https://cdn2.stablediffusionapi.com/generations/f20412ca-cb22-4e77-9b75-26ddbad5a4e5-0.png"
],
"meta": {
"base64": "no",
"enhance_prompt": "no",
"file_prefix": "f20412ca-cb22-4e77-9b75-26ddbad5a4e5",
"guidance_scale": 1,
"height": 512,
"instant_response": "no",
"n_samples": 1,
"negative_prompt": "bad quality",
"outdir": "out",
"prompt": "ultra realistic close up portrait ((beautiful pale cyberpunk female with heavy black eyeliner))",
"safety_checker": "no",
"safety_checker_type": "black",
"seed": 3977575608,
"temp": "no",
"width": 512
}
}
{
"status": "error",
"message": "The prompt field is required."
}