ControlNet Main Endpoint
Overview
You can now control Stable Diffusion with ControlNet. The ControlNet models are available in this API.
You can also use this endpoint to inpaint images with ControlNet. Just make sure to pass the link to the mask_image
in the request body and use the controlnet_model
parameter with "inpaint" value.
Read our detailed blog article about the ControlNet advantages, before you dive in.
Request
--request POST 'https://modelslab.com/api/v5/controlnet' \
Send a POST
request to https://modelslab.com/api/v5/controlnet endpoint.
Body Attributes
Parameter | Description | Values |
---|---|---|
key | Your API Key used for request authorization. | string |
model_id | The ID of the model to be used. It can be a public model or one you have trained. (Note: Controlnet does not apply when using the model with ID flux ) | id |
controlnet_model | ControlNet model ID. It can be from the models list or user-trained. | id |
controlnet_type | ControlNet model type. It can be from the models list. | controlnet type |
auto_hint | Automatically generate a hint image. | "yes"/"no" |
guess_mode | Set this to "yes" if you don't provide any prompt. The model will try to guess from init_image. | "yes"/"no" |
prompt | Text prompt with a description of required image modifications. Make it detailed for best results. | string |
negative_prompt | Items you don't want in the image. | string |
init_image | Link to the initial image to be used as a reference. | url |
control_image | Link to the ControlNet image. | url |
mask_image | Link to the mask image for inpainting. | url |
width | The width of the image. Maximum value is 1024 pixels. | integer |
height | The height of the image. Maximum value is 1024 pixels. | integer |
samples | Number of images to be returned in response. The maximum value is 4. | integer |
scheduler | Use it to set a scheduler. | scheduler |
tomesd | Enable tomesd to generate images quickly. Default is "yes". | "yes"/"no" |
use_karras_sigmas | Use Keras sigmas to generate images. Produces nice results. Default is "yes". | "yes"/"no" |
algorithm_type | Used in the DPMSolverMultistepScheduler scheduler. Default is "none". | "dpmsolver+++" |
vae | Use a custom VAE for generating images. Default is null. | null |
lora_strength | Specify the strength of the LoRa model. Range from 0.1 to 1. | string (comma-separated values) |
lora_model | Pass LoRa model ID. Multiple LoRa models are supported; pass comma-separated values. | string (comma-separated values) |
num_inference_steps | Number of denoising steps. Accepts values 21 or 31. | integer |
safety_checker | A checker for NSFW images. If detected, such images will be replaced by a blank image. Default is "yes". | "yes"/"no" |
embeddings_model | Use it to pass an embeddings model. | id |
enhance_prompt | Enhance prompts for better results. Default is "yes". | "yes"/"no" |
controlnet_conditioning_scale | Scale for ControlNet guidance. Accepts floating values from 0.1 to 5 (e.g., 0.5). | float |
strength | Prompt strength when using the initial image. Range from 0 to 1. | float |
seed | Used to reproduce results. Pass null for a random number. | integral value |
ip_adapter_id | IP adapter ID. Supported IDs are ip-adapter_sdxl , ip-adapter_sd15 , ip-adapter-plus-face_sd15 . | string |
ip_adapter_scale | Scale for the IP adapter. Should be between 0 and 1. | float |
ip_adapter_image | Valid image URL for the IP adapter. | url |
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. Used to identify the request. | id |
upscale | Set this parameter to "yes" to upscale the given image resolution two times (2x). | "yes"/"no" |
clip_skip | Clip Skip. Minimum 1, Maximum 8. | integer |
base64 | Get response as a base64 string. Pass init_image, mask_image, and control_image as base64 strings to get base64 response. | "yes"/"no" |
temp | Create a temporary image link valid for 24 hours. | "yes"/"no" |
You can also use multi ControlNet. Just make sure to pass comma saparated controlnet models to the controlnet_model
as "canny,depth" and init_image
in the request body.
Models
ControlNet API using Controlnet 1.1 as default: Suported controlnet_model:
- canny
- depth
- hed
- mlsd
- normal
- openpose
- scribble
- segmentation
- inpaint
- softedge
- lineart
- shuffle
- tile
- face_detector
- qrcode
Schedulers
This endpoint also supports schedulers. Use the "scheduler" parameter in the request body to pass a specific scheduler from the list below:
- DDPMScheduler
- DDIMScheduler
- PNDMScheduler
- LMSDiscreteScheduler
- EulerDiscreteScheduler
- EulerAncestralDiscreteScheduler
- DPMSolverMultistepScheduler
- HeunDiscreteScheduler
- KDPM2DiscreteScheduler
- DPMSolverSinglestepScheduler
- KDPM2AncestralDiscreteScheduler
- UniPCMultistepScheduler
- DDIMInverseScheduler
- DEISMultistepScheduler
- IPNDMScheduler
- KarrasVeScheduler
- ScoreSdeVeScheduler
- LCMScheduler
Example
Body
- Canny
- Depth
- Hed
- MLSD
- Normal
- Scribble
- In-Paint
- Soft Edge
- Line Art
{
"key": "",
"controlnet_type": "canny",
"controlnet_model": "canny",
"model_id": "midjourney",
"init_image": "https://huggingface.co/takuma104/controlnet_dev/resolve/main/gen_compare/control_images/converted/control_human_openpose.png",
"mask_image": null,
"control_image": null,
"auto_hint": "yes",
"width": "512",
"height": "512",
"prompt": " (a frog wearing blue jean), full-body, Ghibli style, Anime, vibrant colors, HDR, Enhance, ((plain black background)), masterpiece, highly detailed, 4k, HQ, separate colors, bright colors",
"negative_prompt": "human, unstructure, (black object, white object), colorful background, nsfw",
"guess_mode": null,
"use_karras_sigmas": "yes",
"algorithm_type": null,
"safety_checker_type": null,
"tomesd": "yes",
"vae": null,
"embeddings": null,
"lora_strength": null,
"upscale": null,
"instant_response": null,
"strength": 1,
"guidance_scale": 7.5,
"samples": "1",
"safety_checker": null,
"num_inference_steps": "31",
"controlnet_conditioning_scale": 0.4,
"track_id": null,
"scheduler": "EulerDiscreteScheduler",
"base64": null,
"clip_skip": "1",
"temp": null,
"seed": null,
"webhook": null
}
{
"key": "",
"controlnet_model": "depth",
"controlnet_type": "depth",
"model_id": "realistic-vision-51",
"auto_hint": "yes",
"guess_mode": "no",
"prompt": "baby, smiling",
"negative_prompt": null,
"init_image": "https://img.freepik.com/free-photo/adorable-baby-boy-smiling-camera-blurred-background_132075-10819.jpg",
"mask_image": null,
"width": "512",
"height": "512",
"samples": "1",
"scheduler": "UniPCMultistepScheduler",
"num_inference_steps": "30",
"safety_checker": "no",
"enhance_prompt": "yes",
"guidance_scale": 7.5,
"strength": 0.55,
"seed": null,
"webhook": null,
"track_id": null
}
{
"key": "",
"controlnet_model": "hed",
"controlnet_type" :"hed",
"model_id": "realistic-vision-51",
"auto_hint": "yes",
"guess_mode" : "no",
"prompt": "baby, smiling",
"negative_prompt": null,
"init_image": " https://images-ext-1.discordapp.net/external/XM1tvX0cyqZOqfpRdT2BnzhaZo-Z525hXaSAD46gHJY/https/i.pinimg.com/736x/b0/a6/49/b0a649108926efec22c2fd055208955a.jpg?format=webp&width=1072&height=716",
"mask_image": null,
"width": "512",
"height": "512",
"samples": "1",
"scheduler": "UniPCMultistepScheduler",
"num_inference_steps": "30",
"safety_checker": "no",
"enhance_prompt": "yes",
"guidance_scale": 7.5,
"strength": 0.55,
"seed": null,
"webhook": null,
"track_id": null
}
{
"key": "",
"controlnet_model": "mlsd",
"controlnet_type" :"mlsd",
"model_id": "realistic-vision-51",
"auto_hint": "yes",
"guess_mode" : "no",
"prompt": "ROOM INTERIOR, OLD SCHOOL, VINTAGE",
"negative_prompt": null,
"init_image": " https://images-ext-1.discordapp.net/external/f_MuFioFIYcAuhbGrCXkiDfRJq1nZd-L0z_DibDpMc0/https/i.pinimg.com/736x/8a/2b/1e/8a2b1e6ca4779d787ae3c98b7b1100b2.jpg?format=webp&width=1044&height=784",
"mask_image": null,
"width": "512",
"height": "512",
"samples": "1",
"scheduler": "UniPCMultistepScheduler",
"num_inference_steps": "30",
"safety_checker": "no",
"enhance_prompt": "yes",
"guidance_scale": 7.5,
"strength": 0.55,
"seed": null,
"webhook": null,
"track_id": null
}
{
"key": "",
"controlnet_model": "normal",
"controlnet_type" :"normal",
"model_id": "realistic-vision-51",
"auto_hint": "yes",
"guess_mode" : "no",
"prompt": "awoman, posing",
"negative_prompt": null,
"init_image": " https://images-ext-1.discordapp.net/external/ZOjUvfZxcvlnt84xav_fDdIzXPuuMXcW9fA46OaZSTs/https/i.pinimg.com/736x/9d/09/ff/9d09ff904e082395f71aa12f5c83ea77.jpg?format=webp&width=712&height=1064",
"mask_image": null,
"width": "512",
"height": "512",
"samples": "1",
"scheduler": "UniPCMultistepScheduler",
"num_inference_steps": "30",
"safety_checker": "no",
"enhance_prompt": "yes",
"guidance_scale": 7.5,
"strength": 0.55,
"seed": null,
"webhook": null,
"track_id": null
}
{
"key": "",
"controlnet_model": "scribble",
"controlnet_type" :"scribble",
"model_id": "realistic-vision-51",
"auto_hint": "yes",
"guess_mode" : "no",
"prompt": "a woman, posing",
"negative_prompt": null,
"init_image": " https://images-ext-1.discordapp.net/external/2p2KWmaWToQXVSKJnVDbmjaHJHr1-Cx4F84O8l7mhEE/https/i.pinimg.com/736x/30/0c/20/300c209d4a1396c89bf7ea32eefcce95.jpg?format=webp&width=798&height=1064",
"mask_image": null,
"width": "512",
"height": "512",
"samples": "1",
"scheduler": "UniPCMultistepScheduler",
"num_inference_steps": "30",
"safety_checker": "no",
"enhance_prompt": "yes",
"guidance_scale": 7.5,
"strength": 0.55,
"seed": null,
"webhook": null,
"track_id": null
}
{
"key": "",
"controlnet_model": "inpaint",
"controlnet_type" :"inpaint",
"model_id": "realistic-vision-51",
"auto_hint": "yes",
"guess_mode" : "no",
"prompt": "bearded man",
"negative_prompt": null,
"init_image": " https://images-ext-1.discordapp.net/external/oo7VfGo6xDAXQIRP_k3RB5c7l4oEv4grWgkeG4xdUvc/https/i.pinimg.com/736x/0e/04/e0/0e04e00081774f01efd980f1c99ba69a.jpg?format=webp&width=676&height=1016",
"mask_image": " https://images-ext-1.discordapp.net/external/fn7yNKSonZwSLzvprcJR5pCiacxwsaEIHQO54dK3Y7E/https/i.pinimg.com/736x/98/23/64/98236482e403a18695caaac6aac733ba.jpg?format=webp&width=688&height=1028",
"width": "512",
"height": "512",
"samples": "1",
"scheduler": "UniPCMultistepScheduler",
"num_inference_steps": "30",
"safety_checker": "no",
"enhance_prompt": "yes",
"guidance_scale": 7.5,
"strength": 0.55,
"seed": null,
"webhook": null,
"track_id": null
}
{
"key": "",
"controlnet_model": "softedge",
"controlnet_type" :"softedge",
"model_id": "realistic-vision-51",
"auto_hint": "yes",
"guess_mode" : "no",
"prompt": "man",
"negative_prompt": null,
"init_image": " https://images-ext-1.discordapp.net/external/XGH2QUbobf3UWY6ldA9hOp9lhV8FZvCpZfmbZAvceeY/https/i.pinimg.com/736x/49/cc/b4/49ccb461e72b11f5d5f297eb267365c9.jpg?format=webp&width=864&height=1064",
"mask_image": "",
"width": "512",
"height": "512",
"samples": "1",
"scheduler": "UniPCMultistepScheduler",
"num_inference_steps": "30",
"safety_checker": "no",
"enhance_prompt": "yes",
"guidance_scale": 7.5,
"strength": 0.55,
"seed": null,
"webhook": null,
"track_id": null
}
{
"key": "",
"controlnet_model": "lineart",
"controlnet_type" :"lineart",
"model_id": "realistic-vision-51",
"auto_hint": "yes",
"guess_mode" : "no",
"prompt": "beautiful girl",
"negative_prompt": null,
"init_image": "https://www.shutterstock.com/image-illustration/beautiful-anima-samurai-girl-katana-600nw-2111398124.jpg",
"mask_image": "",
"width": "512",
"height": "512",
"samples": "1",
"scheduler": "UniPCMultistepScheduler",
"num_inference_steps": "30",
"safety_checker": "no",
"enhance_prompt": "yes",
"guidance_scale": 7.5,
"strength": 0.55,
"seed": 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": "",
"controlnet_type": "canny",
"controlnet_model": "canny",
"model_id": "midjourney",
"init_image": "https://huggingface.co/takuma104/controlnet_dev/resolve/main/gen_compare/control_images/converted/control_human_openpose.png",
"mask_image": null,
"control_image": null,
"auto_hint":"yes",
"width": "512",
"height": "512",
"prompt": " (a frog wearing blue jean), full-body, Ghibli style, Anime, vibrant colors, HDR, Enhance, ((plain black background)), masterpiece, highly detailed, 4k, HQ, separate colors, bright colors",
"negative_prompt": "human, unstructure, (black object, white object), colorful background, nsfw",
"guess_mode": null,
"use_karras_sigmas": "yes",
"algorithm_type": null,
"safety_checker_type": null,
"tomesd": "yes",
"vae": null,
"embeddings": null,
"lora_strength": null,
"upscale": null,
"instant_response": null,
"strength": 1,
"guidance_scale": 7.5,
"samples": "1",
"safety_checker": null,
"num_inference_steps": "31",
"controlnet_conditioning_scale": 0.4,
"track_id": null,
"scheduler": "EulerDiscreteScheduler",
"base64": null,
"clip_skip": "1",
"temp": null,
"seed": null,
"webhook": null
});
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
redirect: 'follow'
};
fetch("https://modelslab.com/api/v5/controlnet", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
<?php
$payload = [
"key" => "",
"controlnet_model" => "canny",
"controlnet_type" => "canny",
"model_id" => "midjourney",
"auto_hint" => "yes",
"guess_mode" => "no",
"prompt" => "a model doing photoshoot, ultra high resolution, 4K image",
"negative_prompt" => null,
"init_image" => "https://huggingface.co/takuma104/controlnet_dev/resolve/main/gen_compare/control_images/converted/control_human_openpose.png",
"mask_image" => null,
"control_image" => null,
"auto_hint" => "yes",
"width" => "512",
"height" => "512",
"samples" => "1",
"scheduler" => "UniPCMultistepScheduler",
"num_inference_steps" => "31",
"safety_checker" => "no",
"enhance_prompt" => "yes",
"guidance_scale" => 7.5,
"strength" => 0.55,
"lora_model" => null,
"tomesd" => "yes",
"use_karras_sigmas" => "yes",
"algorithm_type" => null,
"safety_checker_type" => null,
"vae" => null,
"embeddings" => null,
"lora_strength" => null,
"embeddings_model" => null,
"seed" => null,
"webhook" => null,
"track_id" => null
];
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://modelslab.com/api/v5/controlnet',
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/v5/controlnet',
'headers': {
'Content-Type': 'application/json'
},
body: JSON.stringify({
"key": "",
"controlnet_type": "canny",
"controlnet_model": "canny",
"model_id": "midjourney",
"init_image": "https://huggingface.co/takuma104/controlnet_dev/resolve/main/gen_compare/control_images/converted/control_human_openpose.png",
"mask_image": null,
"control_image": null,
"auto_hint":"yes",
"width": "512",
"height": "512",
"prompt": " (a frog wearing blue jean), full-body, Ghibli style, Anime, vibrant colors, HDR, Enhance, ((plain black background)), masterpiece, highly detailed, 4k, HQ, separate colors, bright colors",
"negative_prompt": "human, unstructure, (black object, white object), colorful background, nsfw",
"guess_mode": null,
"use_karras_sigmas": "yes",
"algorithm_type": null,
"safety_checker_type": null,
"tomesd": "yes",
"vae": null,
"embeddings": null,
"lora_strength": null,
"upscale": null,
"instant_response": null,
"strength": 1,
"guidance_scale": 7.5,
"samples": "1",
"safety_checker": null,
"num_inference_steps": "31",
"controlnet_conditioning_scale": 0.4,
"track_id": null,
"scheduler": "EulerDiscreteScheduler",
"base64": null,
"clip_skip": "1",
"temp": null,
"seed": null,
"webhook": 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/v5/controlnet"
payload = json.dumps({
"key": "",
"controlnet_type": "canny",
"controlnet_model": "canny",
"model_id": "midjourney",
"init_image": "https://huggingface.co/takuma104/controlnet_dev/resolve/main/gen_compare/control_images/converted/control_human_openpose.png",
"mask_image": None,
"control_image": None,
"auto_hint":"yes",
"width": "512",
"height": "512",
"prompt": " (a frog wearing blue jean), full-body, Ghibli style, Anime, vibrant colors, HDR, Enhance, ((plain black background)), masterpiece, highly detailed, 4k, HQ, separate colors, bright colors",
"negative_prompt": "human, unstructure, (black object, white object), colorful background, nsfw",
"guess_mode": None,
"use_karras_sigmas": "yes",
"algorithm_type": None,
"safety_checker_type": None,
"tomesd": "yes",
"vae": None,
"embeddings": None,
"lora_strength": None,
"upscale": None,
"instant_response": None,
"strength": 1,
"guidance_scale": 7.5,
"samples": "1",
"safety_checker": None,
"num_inference_steps": "31",
"controlnet_conditioning_scale": 0.4,
"track_id": None,
"scheduler": "EulerDiscreteScheduler",
"base64": None,
"clip_skip": "1",
"temp": None,
"seed": None,
"webhook": 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 \"controlnet_type\": \"canny\",\n \"controlnet_model\": \"canny\",\n \"model_id\": \"midjourney\",\n \"init_image\": \"https://huggingface.co/takuma104/controlnet_dev/resolve/main/gen_compare/control_images/converted/control_human_openpose.png\",\n \"mask_image\": null,\n \"control_image\": null,\n \"auto_hint\":\"yes\",\n \"width\": \"512\",\n \"height\": \"512\",\n \"prompt\": \" (a frog wearing blue jean), full-body, Ghibli style, Anime, vibrant colors, HDR, Enhance, ((plain black background)), masterpiece, highly detailed, 4k, HQ, separate colors, bright colors\",\n \"negative_prompt\": \"human, unstructure, (black object, white object), colorful background, nsfw\",\n \"guess_mode\": null,\n \"use_karras_sigmas\": \"yes\",\n \"algorithm_type\": null,\n \"safety_checker_type\": null,\n \"tomesd\": \"yes\",\n \"vae\": null,\n \"embeddings\": null,\n \"lora_strength\": null,\n \"upscale\": null,\n \"instant_response\": null,\n \"strength\": 1,\n \"guidance_scale\": 7.5,\n \"samples\": \"1\",\n \"safety_checker\": null,\n \"num_inference_steps\": \"31
\",\n \"controlnet_conditioning_scale\": 0.4,\n \"track_id\": null,\n \"scheduler\": \"EulerDiscreteScheduler\",\n \"base64\": null,\n \"clip_skip\": \"1\",\n \"temp\": null,\n \"seed\": null,\n \"webhook\": null\n}");
Request request = new Request.Builder()
.url("https://modelslab.com/api/v5/controlnet")
.method("POST", body)
.addHeader("Content-Type", "application/json")
.build();
Response response = client.newCall(request).execute();
Response
{
"status": "processing",
"tip": "for faster speed, keep resolution upto 512x512",
"eta": 146.5279869184,
"messege": "Try to fetch request after given estimated time",
"fetch_result": "https://modelslab.com/api/v3/fetch/13902970",
"id": 13902970,
"output": "",
"meta": {
"prompt": "mdjrny-v4 style a model doing photoshoot, ultra high resolution, 4K image",
"model_id": "midjourney",
"controlnet_model": "canny",
"controlnet_type": "canny",
"negative_prompt": "",
"scheduler": "UniPCMultistepScheduler",
"safetychecker": "no",
"auto_hint": "yes",
"guess_mode": "no",
"strength": 0.55,
"W": 512,
"H": 512,
"guidance_scale": 3,
"seed": 4016593698,
"init_image": "https://huggingface.co/takuma104/controlnet_dev/resolve/main/gen_compare/control_images/converted/control_human_openpose.png",
"mask_image": null,
"steps": 30,
"full_url": "no",
"upscale": "no",
"n_samples": 1,
"embeddings": null,
"lora": null,
"outdir": "out",
"file_prefix": "c8bb8efe-b437-4e94-b508-a6b4705f366a"
}
}